comptime VM: VM-native metatype CONSTRUCTION — declare/define + tagged-union enum_init (P3.4 step 7)
The metatype type-construction builtins now run natively on the flat-memory
VM, so the construction examples run HANDLED end-to-end (no call_builtin
fallback to the legacy interp).
- Tagged-union enum_init WITH payload: allocate zeroed, write the tag at
offset 0, copy the payload at tag_size ({ header, [N x i8] } layout).
- New .call_builtin exec arm -> callBuiltinVm (VM-native mirror of the legacy
execBuiltinInner): declare(name) mints an empty forward nominal slot (shared
declareNominal, also used by declare_type); define(handle, info) reads the
TypeInfo tagged-union VALUE from flat memory and mints via defineFromInfo,
a faithful port of legacy defineEnum/defineStruct/defineTuple (all-void enum
-> real .enum per issue 0142, dup-name rejection, updatePreservingKey vs
replaceKeyedInfo). Unmodeled builtins bail -> legacy fallback (dual-path).
- Refactored the []{name,ty} decode out of registerTypeVm into a shared
decodeMemberSlice (+ decodeTypeSlice for bare-Type tuple elements).
- Correctness guard: enum_init/define assume a tag-headed layout, wrong for a
backing_type tagged union (laid out as the backing struct) — both now bail
loudly on backing_type != null rather than silent-clobber.
Examples 0614/0620/0621/0624/0632 run fully HANDLED on the VM; 0622/0623 run
define HANDLED then fall back at the still-unported type_info. VM output
byte-matches legacy for all 7. 697/0 both gates + all unit tests (added:
tagged-union enum_init payload layout).
This commit is contained in:
@@ -26,21 +26,23 @@ with ONE welded mechanism. Branch: `reify` (off `master`). Update after every st
|
||||
> breaks cross-compilation — host vs target layout — and loses the sandbox. A
|
||||
> flat-memory VM keeps both while getting native bytes + speed.)
|
||||
>
|
||||
> **Next action (2026-06-18) — THE WALL IS BROKEN; paused at a clean 3-commit boundary.** The
|
||||
> dedicated **`Type` builtin TypeId** (8B, distinct from the 16-byte `.any`) now exists and is
|
||||
> wired end-to-end: foundation (`6844fb9`), resolver flip + full `.any`-ref migration (`94f60c5`),
|
||||
> and the VM models `.type_value` natively (`554871b`). **697/0 BOTH gates + 494 unit tests.**
|
||||
> `first_user` is now **100** (slots 20–99 reserved builtin headroom so future builtins don't
|
||||
> renumber user TypeIds / churn snapshots). The PAYOFF is now LANDED (`66005af`): the
|
||||
> **WRITE side** (declare_type / register_type / pointer_to) is VM-native in `Vm.callCompilerFn`
|
||||
> — the compiler-API type-fns (`0631`/`0635`) run **HANDLED end-to-end on the VM at LOWERING
|
||||
> time** (parity-correct), the first lowering-time comptime to do so; they run on the zeroed
|
||||
> lowering-time context (no allocation). **697/0 both gates + EXIT=0.** What's LEFT toward the
|
||||
> end-state ONE evaluator: (1) re-express the metatype `define`/`make_enum` over the compiler-API
|
||||
> + delete the bespoke interp arms (the `make_enum` examples still fall back cleanly through
|
||||
> `call_builtin(define)`); (2) a REAL lowering-time Context (CAllocator thunk func-refs) for
|
||||
> List-growing type-fns — deferred (no HANDLED type-fn allocates); (3) eventually flip the VM to
|
||||
> default + delete `interp.zig`.
|
||||
> **Next action (2026-06-18) — VM-native metatype CONSTRUCTION landed (step 7, uncommitted).** The
|
||||
> metatype `declare`/`define` builtins + tagged-union `enum_init`-with-payload now run NATIVELY on
|
||||
> the VM (new `.call_builtin` exec arm → `callBuiltinVm`/`defineFromInfo`, reading the `TypeInfo`
|
||||
> value from FLAT MEMORY; faithful port of legacy `defineEnum`/`Struct`/`Tuple`). So the metatype
|
||||
> CONSTRUCTION examples run **fully HANDLED** on the VM (no `call_builtin` fallback): `0614`/`0620`/
|
||||
> `0621`/`0624`/`0632`; `0622`/`0623` define-HANDLED then fall back at the still-unported `type_info`.
|
||||
> Both `enum_init`/`define` bail loudly on a `backing_type` tagged union (wrong layout) rather than
|
||||
> silent-clobber. **697/0 BOTH gates + all unit tests** (added: tagged-union `enum_init` payload).
|
||||
> NOT yet committed. **THE NEXT STEP: port `type_info`** (reflect a type → build the `TypeInfo`
|
||||
> value in flat memory, the inverse of `define` — reuses tagged-union `enum_init`) so `0619`/`0622`/
|
||||
> `0623` go fully HANDLED; then drive the SX_COMPTIME_FLAT_TRACE fallback list toward
|
||||
> genuinely-non-comptime cases. Earlier landed: dedicated `Type` builtin TypeId (`6844fb9`/`94f60c5`/
|
||||
> `554871b`); WRITE side declare_type/register_type/pointer_to VM-native (`66005af`); real
|
||||
> lowering-time Context for allocating type-fns (`eb68d9e`). What's LEFT toward the end-state ONE
|
||||
> evaluator: (1) finish porting the comptime corpus onto the VM (type_info next); (2) THEN flip the
|
||||
> VM to default + delete `interp.zig` (with user go-ahead); (3) re-express `define`/`make_enum` as
|
||||
> sx over the compiler-API once legacy is gone (allocation works only on the sole VM evaluator).
|
||||
>
|
||||
> Done so far in Phase 3:
|
||||
> - **READ side (7 readers, dual-path):** `find_type`/`type_kind`/`type_field_count`/
|
||||
@@ -346,6 +348,32 @@ when reached (sentinels or accessor fns; see the design doc Risks).
|
||||
`List` growth; orthogonal, see `current/CHECKPOINT-METATYPE.md`.)
|
||||
|
||||
## Log
|
||||
- **Phase 3 P3.4 step 7 (VM plan) — VM-native metatype CONSTRUCTION: `declare`/`define` + tagged-union `enum_init` (2026-06-18).**
|
||||
Ported the metatype type-CONSTRUCTION builtins into the VM so the construction examples run
|
||||
HANDLED end-to-end (no `call_builtin` fallback). Three pieces: (1) **tagged-union `enum_init`
|
||||
with payload** — the arm previously bailed; now allocates the value (zeroed), writes the tag at
|
||||
offset 0 (`{ header(tag)@0, [N x i8] payload@tag_size }`, the LLVM `backend/llvm/types.zig`
|
||||
layout) and copies the payload at `tag_size`. (2) A **`.call_builtin` exec arm** → new
|
||||
`callBuiltinVm`, the VM-native mirror of the legacy `execBuiltinInner`: `declare(name)` mints an
|
||||
empty forward nominal slot (shared `declareNominal` helper, also used by `declare_type`);
|
||||
`define(handle, info)` reads the `TypeInfo` tagged-union VALUE from FLAT MEMORY (tag@0, active
|
||||
payload `EnumInfo`/`StructInfo`/`TupleInfo` struct at `tag_size`, its single slice field) and
|
||||
mints via `defineFromInfo`, a faithful port of legacy `defineEnum`/`defineStruct`/`defineTuple`
|
||||
(all-void enum → real `.@"enum"` per issue 0142, dup-name rejection, `updatePreservingKey` vs
|
||||
`replaceKeyedInfo`). (3) Refactored the `[]{name,ty}` decode out of `registerTypeVm` into a
|
||||
shared `decodeMemberSlice` (+ `decodeTypeSlice` for bare-`Type` tuple elements), keyed to the
|
||||
module-level `NamedMember`. Unmodeled builtins (`type_info`/`type_name`/…) return null → bail
|
||||
with the builtin name → legacy fallback (dual-path parity). **Correctness guard (caught via
|
||||
review):** `enum_init`/`define` assume a tag-headed layout, which is WRONG for a `backing_type`
|
||||
tagged union (laid out as the backing struct) — both now bail loudly on `backing_type != null`
|
||||
rather than silent-clobber. **Result:** examples `0614`/`0620`/`0621`/`0624`/`0632` run **fully
|
||||
HANDLED** on the VM (define is the whole eval); `0622`/`0623` run define HANDLED then fall back
|
||||
cleanly at the still-unported `type_info` reflection. VM output byte-matches legacy for all 7.
|
||||
**697/0 BOTH gates + all unit tests (added: tagged-union `enum_init` payload layout).** On
|
||||
`reify`. **Next:** port `type_info` (REFLECT a type → build a `TypeInfo` value in flat memory,
|
||||
the inverse — reuses the tagged-union `enum_init` write) so `0619`/`0622`/`0623` go fully HANDLED;
|
||||
then the rest of the comptime corpus (drive the SX_COMPTIME_FLAT_TRACE fallback list toward the
|
||||
genuinely-non-comptime cases) before the VM-default flip + legacy deletion.
|
||||
- **Phase 3 P3.4 step 6 (VM plan) — REAL lowering-time Context: allocating + List-building type-fns now run HANDLED on the VM (2026-06-18).**
|
||||
The VM can now evaluate a comptime type-fn that ALLOCATES at lowering time (the 0141 family) —
|
||||
the legacy interp cannot. Four changes: (1) `runComptimeTypeFunc` (lower/comptime.zig) FORCES the
|
||||
|
||||
Reference in New Issue
Block a user