Skip to content

Commit 933436d

Browse files
committed
stage2: remove destroyed functions from maps
This is likely the cause of the flaky test failures in master branch. Since we have some test coverage for incremental compilation, it's not OK to leave proper memory management of Fn objects as "TODO".
1 parent 74673b7 commit 933436d

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Module.zig

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,13 @@ string_literal_bytes: std.ArrayListUnmanaged(u8) = .{},
8484
/// The set of all the generic function instantiations. This is used so that when a generic
8585
/// function is called twice with the same comptime parameter arguments, both calls dispatch
8686
/// to the same function.
87-
/// TODO: remove functions from this set when they are destroyed.
8887
monomorphed_funcs: MonomorphedFuncsSet = .{},
8988
/// The set of all comptime function calls that have been cached so that future calls
9089
/// with the same parameters will get the same return value.
9190
memoized_calls: MemoizedCallSet = .{},
9291
/// Contains the values from `@setAlignStack`. A sparse table is used here
9392
/// instead of a field of `Fn` because usage of `@setAlignStack` is rare, while
9493
/// functions are many.
95-
/// TODO: remove functions from this set when they are destroyed.
9694
align_stack_fns: std.AutoHashMapUnmanaged(*const Fn, SetAlignStack) = .{},
9795

9896
/// We optimize memory usage for a compilation with no compile errors by storing the
@@ -560,6 +558,8 @@ pub const Decl = struct {
560558
gpa.destroy(extern_fn);
561559
}
562560
if (decl.getFunction()) |func| {
561+
_ = mod.align_stack_fns.remove(func);
562+
_ = mod.monomorphed_funcs.remove(func);
563563
func.deinit(gpa);
564564
gpa.destroy(func);
565565
}
@@ -4094,6 +4094,12 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
40944094
// The exports this Decl performs will be re-discovered, so we remove them here
40954095
// prior to re-analysis.
40964096
mod.deleteDeclExports(decl_index);
4097+
4098+
// Similarly, `@setAlignStack` invocations will be re-discovered.
4099+
if (decl.getFunction()) |func| {
4100+
_ = mod.align_stack_fns.remove(func);
4101+
}
4102+
40974103
// Dependencies will be re-discovered, so we remove them here prior to re-analysis.
40984104
for (decl.dependencies.keys()) |dep_index| {
40994105
const dep = mod.declPtr(dep_index);

0 commit comments

Comments
 (0)