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:
2026-06-10 19:08:15 +03:00
parent 7392013301
commit 8f8708c5df
2 changed files with 110 additions and 10 deletions
+7 -4
View File
@@ -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 "";
}