comptime VM: Phase 3 — find_type + type_field_count reflection readers
First read-only compiler-API reflection readers, bound the same way as the intern/text_of seed (compiler_lib.bound_fns + Vm.callCompilerFn, native on flat memory, no marshaling). A type handle is a plain u32 TypeId (like StringId), so both stay clean scalar host-calls: find_type(name: StringId) -> TypeId (TypeTable.findByName; unresolved/0 if absent) type_field_count(t: TypeId) -> i64 (new TypeTable.memberCount; loud-bail, no silent 0) memberCount is the single source both the legacy handler and the VM read, so the two paths can't drift. find_type returns a non-optional TypeId using the unresolved(0) sentinel for not-found rather than ?Type — a Type value is .any-typed (which the flat-memory VM does not represent) and an optional can't cross the legacy<->VM eval boundary; unresolved is the project-blessed "no type" marker. Example 0628 chains intern -> find_type -> type_field_count (+ a not-found lookup), folded at #run, VM-HANDLED natively. VM unit test added. Parity 689/689 (gate OFF and -Dcomptime-flat).
This commit is contained in:
@@ -253,6 +253,36 @@ host through it:
|
||||
compiler functions (`find_type`, `register_struct`, the reflection readers) are added the
|
||||
same way — flat-memory pointer in, handle/pointer out, no marshaling.
|
||||
|
||||
**Phase 3 progress (2026-06-18):**
|
||||
- **(P3.1) First read-only reflection readers — `find_type` + `type_field_count` (DONE).**
|
||||
Two more `compiler`-library fns bound the same way as the `intern`/`text_of` seed
|
||||
(added to `compiler_lib.bound_fns` AND `Vm.callCompilerFn`, native on flat memory, no
|
||||
marshaling). A **type handle is a plain `u32` `TypeId`** (exactly like `StringId`), so
|
||||
both calls keep the seed's clean scalar shape — handle in, scalar out:
|
||||
`find_type(name: StringId) -> TypeId` (`TypeTable.findByName`) and
|
||||
`type_field_count(t: TypeId) -> i64` (a new `TypeTable.memberCount` query — struct/union/
|
||||
tagged-union fields, enum variants, array/vector length — that BOTH the legacy handler
|
||||
and the VM call, so the two paths can't drift). Example `0628` chains
|
||||
`intern → find_type → type_field_count` and a not-found lookup, both folded at `#run`,
|
||||
both VM-HANDLED natively (no fallback). Parity **689/689** (gate ON and OFF); VM unit test
|
||||
added.
|
||||
- **Decision (resolves the plan's `find_type → ?Type` sketch):** `find_type` returns a
|
||||
NON-optional `TypeId`, using the codebase's dedicated `unresolved` (0) sentinel for
|
||||
not-found — NOT an `?Type`. Rationale: a `Type` value resolves to `.any`
|
||||
(`type_resolver.zig`), which the flat-memory VM does not represent; and an optional
|
||||
return can't cross the legacy↔VM eval boundary (`regToValue` bridges only
|
||||
word/string/struct/tuple). `unresolved` is the project-blessed unmistakable "no type"
|
||||
marker (see CLAUDE.md REJECTED PATTERNS — a dedicated sentinel is the required shape),
|
||||
so the caller checks the handle against 0. This keeps the reader a clean scalar mirror
|
||||
of `intern`/`text_of` and defers `.any`/optional plumbing to when it's actually needed.
|
||||
- **Next (P3.2):** more read-only readers on the same `TypeId`-handle shape (`type_name(t)
|
||||
-> StringId`, `field_name(t, i) -> StringId`, `field_type(t, i) -> TypeId`, kind queries),
|
||||
then `register_struct` (the first MUTATING fn — mints a `TypeId`; resolve the mutable-table
|
||||
/ host-ABI-vs-target-ABI boundary deliberately, per the open questions). Re-expressing
|
||||
`declare`/`define`/`type_info` as sx (the metatype, which runs at LOWERING time) still
|
||||
needs the VM hardened against malformed lowering-time IR first — keep that on the legacy
|
||||
path until then (see the resume note in CHECKPOINT-COMPILER-API.md).
|
||||
|
||||
### Phase 3 — Compiler-API on flat memory (resume the stream — no weld)
|
||||
With native-byte comptime values, re-home the compiler-API:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user