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.
This commit is contained in:
@@ -783,6 +783,16 @@ pub const Decl = struct {
|
||||
return decl.ty.abiAlignment(target);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn markAlive(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.
|
||||
decl.val.markReferencedDeclsAlive();
|
||||
}
|
||||
};
|
||||
|
||||
/// This state is attached to every Decl when Module emit_h is non-null.
|
||||
|
||||
Reference in New Issue
Block a user