docs(metatype): type_info($T) enum reflection done; update plan/checkpoint
This commit is contained in:
@@ -4,6 +4,31 @@ Companion to [PLAN-METATYPE.md](PLAN-METATYPE.md). Update after every step (one
|
|||||||
step at a time, per the cadence rule).
|
step at a time, per the cadence rule).
|
||||||
|
|
||||||
## Last completed step
|
## Last completed step
|
||||||
|
**`type_info($T)` reflection — enum round-trip.** Reflect a type INTO a `TypeInfo`
|
||||||
|
value (the inverse of `define`'s decode), so `define(declare(n), type_info(T))`
|
||||||
|
mints a byte-identical copy with NO literal variant list.
|
||||||
|
|
||||||
|
- `inst.zig`: new `BuiltinId.type_info` (comptime-only, alongside `declare`/`define`).
|
||||||
|
- `lower/call.zig:tryLowerReflectionCall`: the old "not yet implemented" bail is
|
||||||
|
gone. Resolve `$T` at lower time, reject a non-`enum`/non-`tagged_union` arg
|
||||||
|
loudly (good span: `"type_info: 'X' is not an enum …"`), else emit
|
||||||
|
`callBuiltin(.type_info, [const_type], TypeInfo)`.
|
||||||
|
- `interp.zig:reflectTypeInfo`: builds the exact nested-aggregate Value
|
||||||
|
`defineEnum` decodes — variant `{name, payload}`, slice `{data, len}`, EnumInfo
|
||||||
|
`{variants}`, TypeInfo `{tag0, EnumInfo}`. A `tagged_union` reflects each
|
||||||
|
`field.ty` (tagless variants already carry `void`); a payloadless `` `enum ``
|
||||||
|
reflects `void` per variant. Round-trips both source enums AND constructed
|
||||||
|
(declare/define) enums.
|
||||||
|
- emit unchanged — `type_info` is always comptime-evaluated; the existing
|
||||||
|
comptime-only `else` arm in `emitCallBuiltin` (shared with declare/define)
|
||||||
|
never fires.
|
||||||
|
- Scope: **enum-only** (the symmetric inverse of `define`'s current capability).
|
||||||
|
Struct/tuple `TypeInfo` widening is a separate later step.
|
||||||
|
|
||||||
|
`examples/0619` locks it (source enum `circle:f64 / rect:i64 / empty` reflected →
|
||||||
|
reconstructed → constructs + matches). Full suite green (676 examples + units).
|
||||||
|
|
||||||
|
## Prior step
|
||||||
**Self-reference — recursive enums via `declare("Name")` + `*Name`.** The
|
**Self-reference — recursive enums via `declare("Name")` + `*Name`.** The
|
||||||
`declare`/`define` floor now supports self-referential types.
|
`declare`/`define` floor now supports self-referential types.
|
||||||
|
|
||||||
@@ -39,7 +64,9 @@ traversal)**; `field_type` reflection `0616`. Full suite green (674 examples).
|
|||||||
(reflection). No constructor-name knowledge anywhere in the compiler — every
|
(reflection). No constructor-name knowledge anywhere in the compiler — every
|
||||||
named constructor is sx. `declare(name)` carries the type name (compile-time
|
named constructor is sx. `declare(name)` carries the type name (compile-time
|
||||||
string) for forward-type registration.
|
string) for forward-type registration.
|
||||||
- `type_info` still bails loudly (`call.zig:tryLowerReflectionCall`) — pending.
|
- `type_info($T)` reflects an `enum`/`tagged_union` INTO a `TypeInfo` value
|
||||||
|
(`call.zig` emits `callBuiltin(.type_info)`; `interp.zig:reflectTypeInfo` builds
|
||||||
|
the Value). Enum-only; struct/tuple widening pending. `examples/0619` round-trip.
|
||||||
|
|
||||||
## Decision (kept)
|
## Decision (kept)
|
||||||
**Meta lives in `modules/std/meta.sx`, not the prelude.** Declaring its data types
|
**Meta lives in `modules/std/meta.sx`, not the prelude.** Declaring its data types
|
||||||
@@ -51,10 +78,10 @@ Pick any (independent):
|
|||||||
- **`make_enum(variants: []EnumVariant)`** sx helper over a COMPUTED (non-literal)
|
- **`make_enum(variants: []EnumVariant)`** sx helper over a COMPUTED (non-literal)
|
||||||
variant list — exercises the interpreter decoding a value-arg slice in `define`
|
variant list — exercises the interpreter decoding a value-arg slice in `define`
|
||||||
(vs. the literal `.[ … ]` the current examples use).
|
(vs. the literal `.[ … ]` the current examples use).
|
||||||
- **`type_info($T) -> TypeInfo`** — reflect a type INTO a value (inverse of
|
- **Widen `type_info` / `TypeInfo` past `` `enum ``** — struct/tuple variants:
|
||||||
`define`'s decode); widen `TypeInfo` past `` `enum `` + construct a
|
add `` .`struct ``/`` .`tuple `` to the `TypeInfo` enum in `meta.sx`, teach
|
||||||
`[]EnumVariant` value in the interp. Bails loudly today in
|
`reflectTypeInfo` to build them, and teach `defineEnum` (→ a `defineType`) to
|
||||||
`call.zig:tryLowerReflectionCall`. Its own focused effort.
|
decode them. Round-trips a struct through `define` once it lands.
|
||||||
- **Validation + loud diagnostics** (remaining) — duplicate variant names, a
|
- **Validation + loud diagnostics** (remaining) — duplicate variant names, a
|
||||||
`declare()` never `define()`d (hard error), use-before-define. (By-value
|
`declare()` never `define()`d (hard error), use-before-define. (By-value
|
||||||
self-reference already rejected — issue 0139.)
|
self-reference already rejected — issue 0139.)
|
||||||
@@ -65,6 +92,13 @@ Pass 1g emits a loud "infinitely sized" diagnostic + breaks the cycle; covers
|
|||||||
source + comptime types; `examples/1178` locks it.)
|
source + comptime types; `examples/1178` locks it.)
|
||||||
|
|
||||||
## Log
|
## Log
|
||||||
|
- **`type_info($T)` reflection done (enum round-trip).** New `BuiltinId.type_info`;
|
||||||
|
`lower/call.zig` resolves `$T`, rejects non-enum loudly, emits the builtin;
|
||||||
|
`interp.zig:reflectTypeInfo` constructs the exact nested-aggregate Value
|
||||||
|
`defineEnum` decodes (variant `{name,payload}` / slice `{data,len}` / EnumInfo /
|
||||||
|
TypeInfo `.enum`). `tagged_union` reflects `field.ty`; payloadless `` `enum ``
|
||||||
|
reflects `void`. Round-trips source AND constructed enums. Enum-only;
|
||||||
|
struct/tuple widening deferred. `examples/0619` locks it. Suite green (676).
|
||||||
- **By-value self-reference rejected (issue 0139, F5 partial).** New
|
- **By-value self-reference rejected (issue 0139, F5 partial).** New
|
||||||
`checkInfiniteSize` pass (Pass 1g) detects by-VALUE containment cycles (source +
|
`checkInfiniteSize` pass (Pass 1g) detects by-VALUE containment cycles (source +
|
||||||
comptime types, direct + mutual), emits a loud "infinitely sized" diagnostic,
|
comptime types, direct + mutual), emits a loud "infinitely sized" diagnostic,
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ Comptime type metaprogramming with the smallest possible compiler surface:
|
|||||||
- **`define(handle, info) -> Type`** — fill a declared handle's body from a
|
- **`define(handle, info) -> Type`** — fill a declared handle's body from a
|
||||||
`TypeInfo` *value*, and return the handle (so the one-shot form chains).
|
`TypeInfo` *value*, and return the handle (so the one-shot form chains).
|
||||||
- **`type_info($T) -> TypeInfo`** — reflect a type INTO data (the inverse of
|
- **`type_info($T) -> TypeInfo`** — reflect a type INTO data (the inverse of
|
||||||
`define`'s decode). *Pending.*
|
`define`'s decode). *Done for enums* (`interp.zig:reflectTypeInfo`,
|
||||||
|
`examples/0619`); struct/tuple widening pending.
|
||||||
- **`field_type($T, i) -> Type`** — the i-th field / variant-payload / element
|
- **`field_type($T, i) -> Type`** — the i-th field / variant-payload / element
|
||||||
type of `$T`. *Done.*
|
type of `$T`. *Done.*
|
||||||
|
|
||||||
@@ -109,10 +110,12 @@ while red. Examples: `06xx` (comptime), `11xx` (diagnostics).
|
|||||||
- [ ] **`make_enum(variants: []EnumVariant)`** sx helper over a COMPUTED
|
- [ ] **`make_enum(variants: []EnumVariant)`** sx helper over a COMPUTED
|
||||||
(non-literal) variant list — exercises the interpreter decoding a value-arg
|
(non-literal) variant list — exercises the interpreter decoding a value-arg
|
||||||
slice in `define`.
|
slice in `define`.
|
||||||
- [ ] **`type_info($T) -> TypeInfo`** — reflect a type INTO a value (inverse of
|
- [x] **`type_info($T) -> TypeInfo`** (enum-only) — reflect an `enum`/`tagged_union`
|
||||||
`define`'s decode): widen `TypeInfo` past `` `enum `` (struct/tuple) AND
|
INTO a value (inverse of `define`'s decode): `interp.zig:reflectTypeInfo`
|
||||||
construct a `[]EnumVariant`-style value in the interpreter. Bails loudly today
|
constructs the `.enum(EnumInfo{ variants })` Value `defineEnum` decodes, so
|
||||||
in `call.zig:tryLowerReflectionCall`. Round-trips through `define` once it lands.
|
`define(declare(n), type_info(T))` round-trips. `examples/0619`. Non-enum args
|
||||||
|
rejected loudly at lower time. **Still pending:** widen `TypeInfo` past
|
||||||
|
`` `enum `` (struct/tuple variants) + the matching `define` decode arms.
|
||||||
- [~] **Validation + loud diagnostics** — by-VALUE self-reference DONE
|
- [~] **Validation + loud diagnostics** — by-VALUE self-reference DONE
|
||||||
(`checkInfiniteSize` Pass 1g: loud "infinitely sized" diagnostic + cycle
|
(`checkInfiniteSize` Pass 1g: loud "infinitely sized" diagnostic + cycle
|
||||||
break, covers source + comptime types; `examples/1178`, issue 0139 resolved).
|
break, covers source + comptime types; `examples/1178`, issue 0139 resolved).
|
||||||
|
|||||||
Reference in New Issue
Block a user