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) = .{},...@@ -84,7 +84,6 @@ string_literal_bytes: std.ArrayListUnmanaged(u8) = .{},
84/// The set of all the generic function instantiations. This is used so that when a generic84/// The set of all the generic function instantiations. This is used so that when a generic
85/// function is called twice with the same comptime parameter arguments, both calls dispatch85/// function is called twice with the same comptime parameter arguments, both calls dispatch
86/// to the same function.86/// to the same function.
87/// TODO: remove functions from this set when they are destroyed.
88monomorphed_funcs: MonomorphedFuncsSet = .{},87monomorphed_funcs: MonomorphedFuncsSet = .{},
89/// The set of all comptime function calls that have been cached so that future calls88/// The set of all comptime function calls that have been cached so that future calls
90/// with the same parameters will get the same return value.89/// with the same parameters will get the same return value.
...@@ -92,7 +91,6 @@ memoized_calls: MemoizedCallSet = .{},...@@ -92,7 +91,6 @@ memoized_calls: MemoizedCallSet = .{},
92/// Contains the values from `@setAlignStack`. A sparse table is used here91/// Contains the values from `@setAlignStack`. A sparse table is used here
93/// instead of a field of `Fn` because usage of `@setAlignStack` is rare, while92/// instead of a field of `Fn` because usage of `@setAlignStack` is rare, while
94/// functions are many.93/// functions are many.
95/// TODO: remove functions from this set when they are destroyed.
96align_stack_fns: std.AutoHashMapUnmanaged(*const Fn, SetAlignStack) = .{},94align_stack_fns: std.AutoHashMapUnmanaged(*const Fn, SetAlignStack) = .{},
9795
98/// We optimize memory usage for a compilation with no compile errors by storing the96/// We optimize memory usage for a compilation with no compile errors by storing the
...@@ -560,6 +558,8 @@ pub const Decl = struct {...@@ -560,6 +558,8 @@ pub const Decl = struct {
560 gpa.destroy(extern_fn);558 gpa.destroy(extern_fn);
561 }559 }
562 if (decl.getFunction()) |func| {560 if (decl.getFunction()) |func| {
561 _ = mod.align_stack_fns.remove(func);
562 _ = mod.monomorphed_funcs.remove(func);
563 func.deinit(gpa);563 func.deinit(gpa);
564 gpa.destroy(func);564 gpa.destroy(func);
565 }565 }
...@@ -4094,6 +4094,12 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -4094,6 +4094,12 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
4094 // The exports this Decl performs will be re-discovered, so we remove them here4094 // The exports this Decl performs will be re-discovered, so we remove them here
4095 // prior to re-analysis.4095 // prior to re-analysis.
4096 mod.deleteDeclExports(decl_index);4096 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
4097 // Dependencies will be re-discovered, so we remove them here prior to re-analysis.4103 // Dependencies will be re-discovered, so we remove them here prior to re-analysis.
4098 for (decl.dependencies.keys()) |dep_index| {4104 for (decl.dependencies.keys()) |dep_index| {
4099 const dep = mod.declPtr(dep_index);4105 const dep = mod.declPtr(dep_index);