comptime VM: port the WRITE side (declare_type/pointer_to/register_type) -> first HANDLED lowering-time type-fns

declare_type / pointer_to / register_type are now serviced natively in
Vm.callCompilerFn, mirroring the legacy compiler_lib handlers (mint via
@constCast(table) — the lowering-time mint target is &module.types). register_type
reads the []Member slice from flat memory: ref_types is threaded through invoke ->
callCompilerFn so the slice element type (Member = {name: string, ty: Type}) gives
the field offsets + stride; each {name, ty} is decoded and minted with the same
kind branching + dup/payload rejections + idempotent re-fill as legacy.

Key unblock: the synthesized comptime type-fn wrapper was built with return type
.any, so regToValue bailed at the VM<->legacy boundary; changed to .type_value
(the legacy path reads via asTypeId regardless). The compiler-API write type-fns
(0631 register-graph, 0635 multi-edge import) now run HANDLED end-to-end on the VM
at lowering time — parity-correct, on the zeroed lowering-time context (fixed
member arrays, no allocation). The metatype make_enum/define examples still fall
back cleanly through call_builtin(define).

697/0 both gates + EXIT=0.
This commit is contained in:
agra
2026-06-18 14:19:54 +03:00
parent 7b1212b41e
commit 66005af478
3 changed files with 161 additions and 12 deletions

View File

@@ -449,7 +449,11 @@ pub fn evalComptimeType(self: *Lowering, expr: *const Node) ?TypeId {
// lowering because a `*Name` can lower before its `declare` within the same
// body. The interp's `declare` returns this same slot; `define` completes it.
preregisterForwardTypes(self, expr);
const func_id = self.createComptimeFunction("__ctype", expr, .any);
// The wrapper returns a `Type` value → `.type_value` (the dedicated 8-byte
// handle). The legacy path reads the result via `asTypeId` regardless, but the
// VM path converts `func.ret` — `.type_value` → `.type_tag` (an `.any` return
// would box the result and bail at the VM↔legacy boundary).
const func_id = self.createComptimeFunction("__ctype", expr, .type_value);
return self.runComptimeTypeFunc(func_id, expr.span);
}
@@ -463,7 +467,8 @@ pub fn evalComptimeTypeBody(self: *Lowering, body: *const Node, ret_expr: *const
// the prelude, not the return) so forward types register before lowering.
preregisterForwardTypes(self, body);
const prelude = preludeBeforeReturn(body);
const func_id = self.createComptimeFunctionWithPrelude("__ctype", prelude, ret_expr, .any);
// Return type `.type_value` (a `Type` value) — see `evalComptimeType`.
const func_id = self.createComptimeFunctionWithPrelude("__ctype", prelude, ret_expr, .type_value);
return self.runComptimeTypeFunc(func_id, ret_expr.span);
}