REIFY Phase 0.1. Add the end-to-end Phase-0 example: reify a flat enum (value: i64, closed) from a TypeInfo literal, construct E.value(3) / E.closed, and match both arms. Seed an empty expected/*.exit marker. RED by design (reify still bails -> "unparseable expected exit"); the next commit (0.2) implements reify and turns it green. Satisfies the no-commit-both-adds-a-test-and-passes cadence.
64 lines
3.5 KiB
Markdown
64 lines
3.5 KiB
Markdown
# CHECKPOINT-REIFY — comptime `type_info` / `reify` (async-first foundation, step 3)
|
|
|
|
Companion to [PLAN-REIFY.md](PLAN-REIFY.md). Update after every step (one step at a
|
|
time, per the cadence rule).
|
|
|
|
## Last completed step
|
|
**Phase 0.1 (xfail).** Added `examples/0614-comptime-reify-enum.sx` — reify a
|
|
flat enum (`value: i64`, `closed`) from a `TypeInfo` literal, construct
|
|
`E.value(3)` / `E.closed`, match both. Seeded an EMPTY
|
|
`expected/0614-….exit` marker → corpus is RED ("unparseable expected exit",
|
|
reify still bails). This is the deliberate xfail; **Phase 0.2 turns it green**
|
|
(per the no-commit-both-adds-and-passes cadence). `zig build test` is RED on
|
|
this commit by design (1 example fails); the very next commit makes it pass.
|
|
|
|
### (prior) Phase 0.0 (lock). Added the comptime type-metaprogramming surface as the
|
|
on-demand module `library/modules/std/meta.sx` (NOT the prelude — see decision
|
|
below): `EnumVariant`/`EnumInfo`/`TypeInfo` data types + bodyless `#builtin`
|
|
decls `reify` / `type_info` / `field_type`. Each builtin bails LOUDLY when
|
|
reached unimplemented (no silent default). Unit test `src/parser.test.zig`
|
|
(registered in `src/root.zig`) locks that the decls parse. `zig build test`
|
|
green (447/447 unit, 669/669 examples).
|
|
|
|
## Current state
|
|
- `modules/std/meta.sx` declares the surface; the variant uses the backtick raw
|
|
escape `` `enum `` (reads as the keyword, not a mangled `enum_`).
|
|
- **Loud bails wired (unimplemented → diagnostic, never a silent type):**
|
|
- `reify(...)` in a `::` type-alias position → `decl.zig` (the `.call`
|
|
const-decl branch) emits "reify is not yet implemented (REIFY Phase 0.2)"
|
|
and poisons the alias to `.unresolved`. This is also where Phase 0.2 will
|
|
hook the real construction.
|
|
- `reify` / `field_type` in any other type position →
|
|
`generic.zig:resolveTypeCallWithBindings` (defense-in-depth).
|
|
- `type_info(...)` in expression position →
|
|
`call.zig:tryLowerReflectionCall`.
|
|
- No interpreter-side construction yet — `reify` mints nothing.
|
|
|
|
## Decision (0.0)
|
|
**Meta lives in `modules/std/meta.sx`, not the prelude (`core.sx`).** Declaring
|
|
the data types in the always-loaded prelude interns them into every module's
|
|
type table and shifts every `.ir` snapshot (broke 37 examples in a trial). An
|
|
on-demand import keeps the prelude clean; reify users `#import
|
|
"modules/std/meta.sx"`. (User-directed.)
|
|
|
|
## Next step
|
|
**Phase 0.1 (xfail):** add `examples/06xx-comptime-reify-enum.sx` — `reify(.`enum(
|
|
.{ variants = .[ .{name="value",payload=i64}, .{name="closed",payload=void} ] }))`,
|
|
construct `.value(3)`, match it. RED (reify unimplemented → the loud bail above).
|
|
Seed `examples/expected/<name>.exit`. Then 0.2 (green: implement `reify(.`enum)`
|
|
in the interpreter / `decl.zig` reify hook).
|
|
|
|
## Known issues
|
|
None yet.
|
|
|
|
## Log
|
|
- **0.0 (lock).** Meta surface in `modules/std/meta.sx` (data types + 3 bodyless
|
|
`#builtin` decls), loud bails at all three reach points, `src/parser.test.zig`
|
|
parse-lock. Two user-directed refinements folded in: variant uses `` `enum ``
|
|
raw escape; surface moved out of the prelude into its own module to avoid
|
|
type-table / `.ir`-snapshot churn. `zig build test` green.
|
|
- **Stream carved.** Selected as the first async-first foundation: `reify` gates both
|
|
channel result types (`RecvResult($T)`) and `race`'s synthesized union, is fully
|
|
validated (3 reviewers), and is a self-contained compiler/type-system feature
|
|
testable in isolation (`06xx` comptime). Generic-enum syntax dropped in its favor.
|