P5.7 Step D: re-express metatype declare() as sx over declare_type

declare(name) is now an ordinary sx fn in modules/std/meta.sx that calls the
abi(.compiler) declare_type primitive — both mint/find the same forward nominal
slot. Removed the bespoke .declare arm from callBuiltinVm and the BuiltinId.declare
member; dropped the declare interception in tryLowerReflectionCall (the call now
routes to the sx fn). preregisterForwardTypes still scans for the literal
declare("Name") spelling so *Name self-references forward-register before the
body lowers (0618). define/type_info/field_type remain builtins.
This commit is contained in:
agra
2026-06-19 20:58:34 +03:00
parent 61f5700a36
commit 8850fcce70
4 changed files with 55 additions and 38 deletions

View File

@@ -1677,22 +1677,12 @@ pub fn tryLowerReflectionCall(self: *Lowering, name: []const u8, c: *const ast.C
// classification covers all 7; it runs before dispatch.
if (self.reflectionTypeArgGuard(name, c)) |sentinel| return sentinel;
if (std.mem.eql(u8, name, "declare")) {
// Comptime type-construction primitive: mint an empty nominal slot NAMED
// by its (compile-time string) argument. Comptime-only — emitted as a
// builtin_call the interp executes against its `mint` table; never
// reaches codegen (its sx callers are only ever comptime-evaluated).
if (c.args.len != 1) {
if (self.diagnostics) |d| d.addFmt(.err, c.callee.span, "declare(name) takes one string argument", .{});
return Ref.none;
}
// The named forward type is pre-registered by `evalComptimeType`'s
// `preregisterForwardTypes` before this body lowers (so a `*Name`
// self-reference resolves); the interp's `declare` returns that slot.
const name_ref = self.lowerExpr(c.args[0]);
const args_owned = self.alloc.dupe(Ref, &.{name_ref}) catch return Ref.none;
return self.builder.callBuiltin(.declare, args_owned, .type_value);
}
// `declare(name)` is now an ordinary sx function (`modules/std/meta.sx`)
// written over the `abi(.compiler)` primitive `declare_type` — no longer
// intercepted here. (`preregisterForwardTypes` still scans for the literal
// `declare("Name")` spelling so a `*Name` self-reference forward-registers
// before the body lowers; the sx `declare` calls `declare_type`, which
// returns that same forward slot.)
if (std.mem.eql(u8, name, "define")) {
// Comptime type-construction primitive: complete a declare()'d slot
// from a TypeInfo value. `define(handle, info)`.