feat(drop): enforce @[Drop] attribute and add basic move semantics
- Auto-drop now only triggers for user-defined types explicitly marked with @[Drop] on the struct declaration. - Added move tracking in C backend to skip auto-drop for variables that have been moved (via let y = x, return x, or assignment). - Prevents double-free when ownership is transferred. - Selfhost bootstrap loop verified: C output is deterministic.
This commit is contained in:
+7
-4
@@ -2264,10 +2264,13 @@ func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
|
||||
}
|
||||
}
|
||||
// User-defined types with @[Drop]: look for TypeName_Drop function
|
||||
let dropName: String = String_Concat(typeName, "_Drop");
|
||||
let dropSym: Symbol = Scope_Lookup(ctx.scope, dropName);
|
||||
if dropSym.decl != null as *Decl {
|
||||
return dropName;
|
||||
let typeSym: Symbol = Scope_Lookup(ctx.scope, typeName);
|
||||
if typeSym.kind == skType && typeSym.decl != null as *Decl && typeSym.decl.isDrop != 0 {
|
||||
let dropName: String = String_Concat(typeName, "_Drop");
|
||||
let dropSym: Symbol = Scope_Lookup(ctx.scope, dropName);
|
||||
if dropSym.decl != null as *Decl {
|
||||
return dropName;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user