authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-10 20:39:57-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-08-10 23:23:30-07:00
log933436dc52b9be0a3e5d81b014fba6df2124fe20
treec28b511d22a08abf01abdb652d0d19a8c111eb86
parent74673b7f69b27dc39a653f92eb58bba71e289f39

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 files changed, 8 insertions(+), 2 deletions(-)

src/Module.zig+8-2
......@@ -84,7 +84,6 @@ 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.
8887monomorphed_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.
......@@ -92,7 +91,6 @@ 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.
9694align_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);