feat(selfhost): auto-drop for interface-based Drop implementations

- Extend Lcx_BuildAutoDropFree to detect TypeName_Drop methods

  registered by sema for extend Type for Drop impl blocks.

- Preserve existing @[Drop] attribute path and move semantics.

- Add design doc and implementation plan.

- Mark Destructors/Drop roadmap item done in selfhost.
This commit is contained in:
2026-06-14 17:44:35 +03:00
parent 2c8223f94e
commit e5e490605a
5 changed files with 406 additions and 12 deletions
+5 -3
View File
@@ -2742,12 +2742,14 @@ func Lcx_BuildAutoDropFree(ctx: *LowerCtx, typeName: String) -> String {
return String_Concat(String_Concat("Map_Drop_", kType), String_Concat("_", vType));
}
}
// User-defined types with @[Drop]: look for TypeName_Drop function
// User-defined types with @[Drop] OR an explicit TypeName_Drop method
let typeSym: Symbol = Scope_Lookup(ctx.scope, typeName);
if typeSym.kind == skType && typeSym.decl != null as *Decl && typeSym.decl.isDrop != 0 {
if typeSym.kind == skType && typeSym.decl != null as *Decl {
let dropName: String = String_Concat(typeName, "_Drop");
let dropSym: Symbol = Scope_Lookup(ctx.scope, dropName);
if dropSym.decl != null as *Decl {
let hasAttr: bool = typeSym.decl.isDrop != 0;
let hasMethod: bool = dropSym.decl != null as *Decl;
if hasAttr || hasMethod {
return dropName;
}
}