diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2023-11-12 15:45:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-12 23:21:21 -0500 |
| commit | 91b897ef581aec65dd7a080754ab09d2e176ed8f (patch) | |
| tree | 6c6a7a2a3776d579619c6ed1cda49f5392f63640 /src/codegen | |
| parent | 53500a57684665e08a2e18e7a736aacfa6548062 (diff) | |
| download | zig-91b897ef581aec65dd7a080754ab09d2e176ed8f.tar.gz zig-91b897ef581aec65dd7a080754ab09d2e176ed8f.zip | |
rework memory management of Module.Namespace hash maps
The motivating problem here was a memory leak in the hash maps of
Module.Namespace.
The commit deletes more of the legacy incremental compilation
implementation. It had things like use of orderedRemove and trying to do
too much OOP-style creation and deletion of objects.
Instead, this commit iterates over all the namespaces on Module deinit
and calls deinit on the hash map fields. This logic is much simpler to
reason about.
Similarly, change global inline assembly to an array hash map since
iterating over the values is a primary use of it, and clean up the
remaining values on Module deinit, solving another memory leak.
After this there are no more memory leaks remaining when using the
x86 backend in a libc-less compiler.
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/c.zig | 5 | ||||
| -rw-r--r-- | src/codegen/llvm.zig | 5 |
2 files changed, 6 insertions, 4 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index f85f4b522b..7d850dec14 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -2506,8 +2506,9 @@ pub fn genTypeDecl( } pub fn genGlobalAsm(mod: *Module, writer: anytype) !void { - var it = mod.global_assembly.valueIterator(); - while (it.next()) |asm_source| try writer.print("__asm({s});\n", .{fmtStringLiteral(asm_source.*, null)}); + for (mod.global_assembly.values()) |asm_source| { + try writer.print("__asm({s});\n", .{fmtStringLiteral(asm_source, null)}); + } } pub fn genErrDecls(o: *Object) !void { diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 29e989ff56..672ae80a85 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -1121,8 +1121,9 @@ pub const Object = struct { const mod = object.module; const writer = object.builder.setModuleAsm(); - var it = mod.global_assembly.valueIterator(); - while (it.next()) |assembly| try writer.print("{s}\n", .{assembly.*}); + for (mod.global_assembly.values()) |assembly| { + try writer.print("{s}\n", .{assembly}); + } try object.builder.finishModuleAsm(); } |
