From a5c7742ba6fc793608b8bb7ba058e33eccd9cfec Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 15 Jan 2022 00:17:25 -0700 Subject: stage2: fix Decl garbage collection not marking enough It is the job of codegen backends to mark Decls that are referenced as alive so that the frontend does not sweep them with the garbage. This commit unifies the code between the backends with an added method on Decl. The implementation is more complete than before, switching on the Decl val tag and recursing into sub-values. As a result, two more array tests are passing. --- src/codegen.zig | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index 1d20c4bc74..65b0318e9e 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -464,7 +464,7 @@ fn lowerDeclRef( } if (decl.analysis != .complete) return error.AnalysisFail; - markDeclAlive(decl); + decl.markAlive(); const vaddr = vaddr: { if (bin_file.cast(link.File.MachO)) |macho_file| { break :vaddr try macho_file.getDeclVAddrWithReloc(decl, code.items.len); @@ -484,16 +484,3 @@ fn lowerDeclRef( return Result{ .appended = {} }; } - -fn markDeclAlive(decl: *Module.Decl) void { - if (decl.alive) return; - decl.alive = true; - - // This is the first time we are marking this Decl alive. We must - // therefore recurse into its value and mark any Decl it references - // as also alive, so that any Decl referenced does not get garbage collected. - - if (decl.val.pointerDecl()) |pointee| { - return markDeclAlive(pointee); - } -} -- cgit v1.2.3