selfhost: add lib/Drop.bux with interface Drop; extend methods visible in scope

- lib/Drop.bux: interface Drop { func Drop(self: *Self); }
- sema.bux: define TypeName_MethodName in scope for impl block methods
  so auto-drop (Lcx_BuildAutoDropFree) can find Drop implementations
  via extend Type for Drop, not just @[Drop] or standalone functions
- Verified: extend Buffer for Drop auto-calls Buffer_Drop in @[Checked]
This commit is contained in:
2026-06-10 13:37:55 +03:00
parent 0a41ce85f4
commit 7d6cf7f511
2 changed files with 22 additions and 5 deletions
+4
View File
@@ -0,0 +1,4 @@
// Drop trait — automatic cleanup for heap-allocated or resource-holding types
interface Drop {
func Drop(self: *Self);
}
+18 -5
View File
@@ -1148,11 +1148,24 @@ func Sema_CollectGlobals(sema: *Sema) {
let implTypeName: String = decl.strValue; let implTypeName: String = decl.strValue;
var m: *Decl = decl.childDecl1; var m: *Decl = decl.childDecl1;
while m != null as *Decl { while m != null as *Decl {
if m.kind == dkFunc && sema.methodCount < 256 { if m.kind == dkFunc {
sema.methodEntries[sema.methodCount].typeName = implTypeName; if sema.methodCount < 256 {
sema.methodEntries[sema.methodCount].methodName = m.strValue; sema.methodEntries[sema.methodCount].typeName = implTypeName;
sema.methodEntries[sema.methodCount].decl = m; sema.methodEntries[sema.methodCount].methodName = m.strValue;
sema.methodCount = sema.methodCount + 1; sema.methodEntries[sema.methodCount].decl = m;
sema.methodCount = sema.methodCount + 1;
}
// Also define TypeName_MethodName in scope so auto-drop can find it
let methodSymName: String = String_Concat(implTypeName, "_");
let methodSymName2: String = String_Concat(methodSymName, m.strValue);
var methodSym: Symbol;
Sema_ZeroInitSymbol(&methodSym);
methodSym.kind = skFunc;
methodSym.name = methodSymName2;
methodSym.typeKind = tyFunc;
methodSym.isPublic = decl.isPublic;
methodSym.decl = m;
discard Scope_Define(sema.scope, methodSym);
} }
m = m.childDecl2; m = m.childDecl2;
} }