comptime VM: real lowering-time Context — allocating + List-building type-fns run on the VM (issue 0141)

The VM can now evaluate a comptime type-fn that allocates at lowering time (the
0141 family) — the legacy interp cannot. Four changes:

- runComptimeTypeFunc (lower/comptime.zig): force the CAllocator->Allocator thunks
  to exist (getOrCreateThunks, idempotent, guarded) BEFORE eval. A type-fn const
  runs at scanDecls (Pass 1), before Pass 1c builds the default-context global +
  thunks, so the comptime allocator was otherwise null.
- materializeDefaultContext: build a REAL context at lowering time when the global
  is absent — find the two thunks by name and lay their func-refs into the inline
  Allocator value at the head of Context, so context.allocator.alloc_bytes
  dispatches call_indirect -> thunk -> native VM malloc.
- aggType: deref a pointer base_type (the List write path emits struct_gep with
  base_type = *Struct; fieldOffset panicked on the pointer — now derefs, no panic).
- subslice: handle a [*]T many-pointer / *T base (a List's items field — the base
  IS the data pointer).

Verified end-to-end (manual probe): a compiler-API type-fn building its []Member in
a List(Member) runs HANDLED on the VM and mints (green=7) — the 0141 List-growth
pattern. Can't be a corpus test yet (gate-OFF/legacy can't allocate at lowering
time — the dual-path bind), so locked in via VM unit tests (many-pointer subslice;
struct_gep with a pointer base_type). 697/0 both gates + all unit tests.
This commit is contained in:
agra
2026-06-18 15:04:55 +03:00
parent 3c0e0852a8
commit eb68d9ed94
5 changed files with 165 additions and 17 deletions

View File

@@ -5,6 +5,21 @@
> (`examples/0620`/`0624`); only the `List`-grown form fails. Filed to record the
> two-layer root cause for a dedicated session. Surfaces a CLEAN diagnostic, not a
> crash.
>
> **UPDATE (2026-06-18): the flat-memory VM now HANDLES this pattern via the
> compiler-API.** A type-fn that builds its members in a `List` (`.append` then
> `register_type(handle, kind, vs.items[0..vs.len])`) runs end-to-end on the VM
> (`-Dcomptime-flat`) — both 0141 blockers are gone there: lowering-time allocation
> works (the CAllocator thunks are now force-created in `runComptimeTypeFunc` and
> the VM's `materializeDefaultContext` lays their func-refs into a real context),
> and pointer field access has no slot_ptr chain (flat memory; `aggType` derefs a
> pointer `base_type`, `subslice` handles `[*]T`). What still fails is the ORIGINAL
> repro below, which uses the metatype `define`/`make_enum` (`#builtin` →
> `call_builtin` → VM falls back to legacy → legacy's slot_ptr + null-allocator
> bugs). Resolving the repro on the VM needs the metatype re-expressed over the
> compiler-API (so the type-fn hits no `call_builtin`); shipping it on BOTH gates
> needs the VM-default flip + legacy deletion. See CHECKPOINT-COMPILER-API
> (2026-06-18 "step 6").
## Symptom