docs(metatype): tuple done; reflect/construct triad complete

This commit is contained in:
agra
2026-06-17 07:10:45 +03:00
parent 14cfb64874
commit 60293bf5dd

View File

@@ -4,6 +4,18 @@ Companion to [PLAN-METATYPE.md](PLAN-METATYPE.md). Update after every step (one
step at a time, per the cadence rule).
## Last completed step
**`type_info` / `define` widened to TUPLE types — reflect/construct triad
complete.** `TypeInfo` gained a `` `tuple(TupleInfo) `` variant (`TupleInfo{
elements: []Type }`, positional/unnamed). `reflectTypeInfo` builds `.tuple`
(tag 2) as bare `type_tag` elements; `defineTuple` decodes `[]Type` and completes
the declare slot as a structural `.tuple` via `replaceKeyedInfo` (tuples are
structural, so the declared name is vestigial, but the slot is completed in place
so `define` returns the handle like enum/struct). `call.zig`'s `type_info` guard
admits `.tuple`. `examples/0623` (programmatic `Pair` + source-tuple round-trip).
Suite green (684). All three TypeInfo shapes now reflect + construct + round-trip
(`0619` enum, `0622` struct, `0623` tuple).
## Earlier — struct widening
**`type_info` / `define` widened to STRUCT types.** `TypeInfo` gained a
`` `struct(StructInfo) `` variant (`StructField{ name, type }`); the metatype
system now reflects AND constructs structs, not only enums.
@@ -87,10 +99,12 @@ traversal)**; `field_type` reflection `0616`. Full suite green (674 examples).
(reflection). No constructor-name knowledge anywhere in the compiler — every
named constructor is sx. `declare(name)` carries the type name (compile-time
string) for forward-type registration.
- `type_info($T)` reflects an `enum`/`tagged_union`/`struct` INTO a `TypeInfo`
value (`call.zig` emits `callBuiltin(.type_info)`; `interp.zig:reflectTypeInfo`
builds the Value). `define` decodes `.enum` → tagged_union and `.struct` →
struct. Tuple widening pending. `examples/0619` (enum) / `0622` (struct) round-trip.
- `type_info($T)` reflects an `enum`/`tagged_union`/`struct`/`tuple` INTO a
`TypeInfo` value (`call.zig` emits `callBuiltin(.type_info)`;
`interp.zig:reflectTypeInfo` builds the Value). `define` decodes `.enum` →
tagged_union, `.struct` → struct, `.tuple` → tuple (the last via
`replaceKeyedInfo`). `examples/0619` (enum) / `0622` (struct) / `0623` (tuple)
round-trip. All three TypeInfo shapes ship.
## Decision (kept)
**Meta lives in `modules/std/meta.sx`, not the prelude.** Declaring its data types
@@ -98,11 +112,19 @@ in the always-loaded prelude interns them into every module's type table and
shifts every `.ir` snapshot. On-demand import keeps the prelude clean.
## Next step
Pick any (independent):
- **Widen `type_info` / `TypeInfo` to `` `tuple ``** — the last shape. `` `enum ``
and `` `struct `` now ship (`examples/0619`/`0622`). A tuple has positional
(unnamed) element types; needs a `TupleInfo { elements: []Type }` in `meta.sx`,
a `reflectTypeInfo` arm for `.tuple`, and a `defineTuple` (mints a `.tuple` type).
The reflect/construct triad is COMPLETE — `` `enum `` (`0619`), `` `struct ``
(`0622`), `` `tuple `` (`0623`) all reflect AND construct + round-trip. Remaining
METATYPE work is the deferred enhancements (see below), all clean diagnostics
rather than crashes:
- **Comptime `List` growth** — `List(EnumVariant).append` at comptime bails
("struct_get: base has no fields"); the allocator/List protocol path isn't fully
interp-evaluable. Probe `.sx-tmp/probe_makeenum.sx`.
- **Generic type-fn body locals** — a generic `($T) -> Type` comptime-evals only
its return EXPRESSION (`generic.zig:1760`); a local before the return is
unresolved. Workaround: non-generic builder (`examples/0620`). Probe
`.sx-tmp/probe_me5.sx`.
Neither blocks anything; the metatype surface (declare/define/type_info/field_type
+ make_enum) is feature-complete for the locked design.
- ~~**Validation + loud diagnostics**~~ — COMPLETE. duplicate variant names
(`examples/1180`); `declare()` never `define()`d (`examples/1181`, was a
`verifySizes` panic); by-value self-reference for both source (`1178`) and
@@ -145,6 +167,12 @@ capabilities would let the variant list be built more freely; both error cleanly
`examples/1178` locks it).
## Log
- **Tuple widening done — reflect/construct triad complete.** `TypeInfo` gained
`` `tuple(TupleInfo) `` (positional `[]Type`); `reflectTypeInfo` reflects a
`.tuple` (bare type_tags, tag 2), `defineType` dispatches tag 2 → `defineTuple`
(completes the slot as a structural tuple via `replaceKeyedInfo`), and the
lower-time `type_info` guard admits `.tuple`. `examples/0623`. Suite green (684).
enum/struct/tuple all reflect + construct + round-trip.
- **Struct widening done.** `TypeInfo` gained `` `struct(StructInfo) ``; `define`
dispatches on the tag (`defineType` → `defineEnum`/`defineStruct`), `reflectTypeInfo`
reflects a `@"struct"`, and the lower-time `type_info` guard admits structs.