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:
+5
-3
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user