diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-01-06 00:52:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-01-06 00:52:10 -0700 |
| commit | 8c6175c1343a00278efc029a0be4091ff505dc3d (patch) | |
| tree | 63f9c87d0f37757f5c0c0b543fc94ea4fe68ae22 /src/codegen.zig | |
| parent | 713d2a9b3883942491b40738245232680877cc66 (diff) | |
| download | zig-8c6175c1343a00278efc029a0be4091ff505dc3d.tar.gz zig-8c6175c1343a00278efc029a0be4091ff505dc3d.zip | |
Sema: const inferred alloc infers comptime-ness
const locals now detect if the value ends up being comptime known. In
such case, it replaces the runtime AIR instructions with a decl_ref
const.
In the backends, some more sophisticated logic for marking decls as
alive was needed to prevent Decls incorrectly being garbage collected
that were indirectly referenced in such manner.
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 9de13ee657..e385158ba6 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -464,7 +464,7 @@ fn lowerDeclRef( } if (decl.analysis != .complete) return error.AnalysisFail; - decl.alive = true; + markDeclAlive(decl); // TODO handle the dependency of this symbol on the decl's vaddr. // If the decl changes vaddr, then this symbol needs to get regenerated. const vaddr = bin_file.getDeclVAddr(decl); @@ -478,3 +478,16 @@ 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); + } +} |
