green(reify): field_type($T, i) -> Type over the type table

REIFY Phase 2.1. fieldTypeOf (lower/generic.zig, re-exported on Lowering)
returns the i-th member type of T: struct field / tagged-union + union
variant payload (.void for a tagless variant) / tuple element / array +
vector element. Out-of-range and memberless types poison to .unresolved
with a loud diagnostic (never a silent default). Wired into
resolveTypeCallWithBindings (replacing the Phase-2 bail); since it folds
to a TypeId at lower time it composes inside type_eq / type_name / any
type-arg slot.

examples/0616 green: struct fields (name via field_name + type via
field_type), type_eq fold, tagged-union payloads incl. quit -> void.
Suite green (672 examples, 447 unit).

type_info($T) -> TypeInfo (reflect into a value, inverse of reify) is
NOT done — still bails loudly; it's the larger Phase 2.2 step (widen the
TypeInfo data model + comptime value construction). Plan/checkpoint updated.
This commit is contained in:
agra
2026-06-16 19:06:57 +03:00
parent bd139dc09c
commit ac8c689518
7 changed files with 107 additions and 17 deletions

View File

@@ -4,7 +4,21 @@ Companion to [PLAN-REIFY.md](PLAN-REIFY.md). Update after every step (one step a
time, per the cadence rule).
## Last completed step
**Phase 1 (type-fn → reify identity) — COMPLETE.** A type-fn body that returns
**Phase 2.1 (green) — `field_type` done.** `field_type($T, i) -> Type` is
implemented over the type table (`fieldTypeOf` in `lower/generic.zig`, re-exported
on `Lowering`): struct field / tagged-union + `union` variant payload (`.void` for
a tagless variant) / tuple element / array + vector element; OOB and memberless
types poison to `.unresolved` with a loud diagnostic (never a silent default).
It folds at lower time, so it composes inside `type_eq` / `type_name` / any type-arg
slot. `examples/0616` green (struct fields name+type, `type_eq` fold, tagged-union
payloads incl. `quit → void`). Full suite green (672 examples, 447 unit). Cadence:
2.0 xfail (empty marker, RED) → 2.1 green (this commit).
**`type_info` is NOT done** — it still bails loudly in
`call.zig:tryLowerReflectionCall`. It builds a full `TypeInfo` *value* (inverse of
reify) and is the larger Phase 2.2 step (see Next step).
### (prior) Phase 1 (type-fn → reify identity) — COMPLETE. A type-fn body that returns
`reify(...)` now mints the enum under the instantiation's name:
`instantiateTypeFunction` (`lower/generic.zig`) detects a reify-returning body
(`findReturnReifyCall`) and routes it to `reifyType(<mangled-or-alias name>,
@@ -65,16 +79,23 @@ on-demand import keeps the prelude clean; reify users `#import
"modules/std/meta.sx"`. (User-directed.)
## Next step
**Phase 2 (`type_info` + `field_type`).** Reflect a struct/tuple → read variant /
field names + **types** (`field_type($T, i) -> Type`, `type_info($T) -> TypeInfo`).
xfail → green by implementing both over the type table (reuse the
`field_count`/`field_name` reflection path; both currently bail loudly —
`type_info` in `call.zig:tryLowerReflectionCall`, `field_type` in
`generic.zig:resolveTypeCallWithBindings`). NOTE: `reifyType` still reads a LITERAL
`TypeInfo` off the AST (works for the inline-literal and type-fn-over-literal cases
Phases 01 use); a `type_info`-derived (computed, non-literal) `TypeInfo` fed back
into `reify` would need the reader generalized (or interp evaluation) — call that out
when Phase 2 enables round-tripping.
**Phase 2.2 (`type_info($T) -> TypeInfo`).** Reflect a type into a `TypeInfo`
*value* — the inverse of reify. Two sub-pieces, both non-trivial: (a) widen the
`meta.sx` `TypeInfo` data model beyond `` `enum `` (struct / tuple variants); (b)
build the value at comptime — a `[]EnumVariant`-style slice of structs holding
strings (`name`) + `Type` tags (`payload`), populated from the type table. This is
comptime value-CONSTRUCTION (allocating slice/struct/string/type-tag values in the
interpreter), materially larger than 2.1's fold-to-a-TypeId. Currently bails loudly
in `call.zig:tryLowerReflectionCall`. Best done as its own session for context room.
NOTE (round-tripping): `reifyType` still reads a LITERAL `TypeInfo` off the AST
(fine for the inline-literal + type-fn-over-literal cases of Phases 01). Once 2.2
produces a COMPUTED `TypeInfo`, feeding it back into `reify` needs the reader
generalized (or interp evaluation of the `TypeInfo` value) — handle that when 2.2
enables round-tripping.
Alternatively jump to **Phase 3** (`make_enum` + `RecvResult`/`TryResult` sx lib over
`reify`) — that only needs reify (have it) + type-fns (have them), not `type_info`.
SELF-REFERENCE = Phase 4, API DECIDED (user-directed): explicit **`declare()` →
`define(h, info)`** (the declaration-vs-definition split; NOT a `reify_rec((self)=>…)`
@@ -92,6 +113,11 @@ in PLAN-REIFY Phase 4.
None yet.
## Log
- **2.1 (green) — `field_type` done.** `fieldTypeOf` over the type table
(struct/tagged-union/union/tuple/array/vector; OOB+memberless = loud poison);
folds at lower time, composes in `type_eq`/`type_name`; `0616` green. `type_info`
still pending (Phase 2.2 — builds a TypeInfo value).
- **2.0 (xfail).** `0616` + empty `.exit` marker → RED (field_type bailed).
- **1.1 (green) — Phase 1 done.** Type-fn body `return reify(...)` routes through
`reifyType` under the instantiation name (`findReturnReifyCall` +
mangled-name registration); `Box(i64)` at two sites = one type (Contract 1);