diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-15 00:17:25 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-15 00:17:25 -0700 |
| commit | a5c7742ba6fc793608b8bb7ba058e33eccd9cfec (patch) | |
| tree | 29bf43a0bb915e35244d457514885baca2a5916b /src/codegen/c.zig | |
| parent | 41f3799bf0cfc8241f458094781ba45967e2576e (diff) | |
| download | zig-a5c7742ba6fc793608b8bb7ba058e33eccd9cfec.tar.gz zig-a5c7742ba6fc793608b8bb7ba058e33eccd9cfec.zip | |
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.
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 58bf919b1f..3f3147ca80 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -215,7 +215,7 @@ pub const DeclGen = struct { val: Value, decl: *Decl, ) error{ OutOfMemory, AnalysisFail }!void { - markDeclAlive(decl); + decl.markAlive(); if (ty.isSlice()) { try writer.writeByte('('); @@ -253,19 +253,6 @@ pub const DeclGen = struct { try dg.renderDeclName(decl, writer); } - fn markDeclAlive(decl: *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); - } - } - fn renderInt128( writer: anytype, int_val: anytype, |
