lock(reify): meta.sx surface + bodyless #builtin decls + loud bails

REIFY Phase 0.0. Add the comptime type-metaprogramming surface as the
on-demand module modules/std/meta.sx (NOT the prelude — declaring its
data types in always-loaded core.sx interns them into every module's
type table and shifts every .ir snapshot):

  - EnumVariant / EnumInfo / TypeInfo data types. TypeInfo's variant uses
    the backtick raw escape `enum so it reads as the keyword.
  - reify / type_info / field_type as bodyless #builtin decls.

Each builtin bails LOUDLY when reached unimplemented (no silent default):
  - reify(...) in a :: type-alias position -> decl.zig .call branch
    (also the Phase 0.2 construction hook); poisons the alias .unresolved.
  - reify / field_type in any other type position ->
    generic.zig resolveTypeCallWithBindings.
  - type_info(...) in expression position -> call.zig tryLowerReflectionCall.

Unit test src/parser.test.zig (registered in root.zig) locks that the
decls parse. zig build test green (447 unit, 669 examples).
This commit is contained in:
agra
2026-06-16 17:44:19 +03:00
parent ded106333b
commit 81669c72b7
8 changed files with 196 additions and 13 deletions

View File

@@ -4,28 +4,51 @@ Companion to [PLAN-REIFY.md](PLAN-REIFY.md). Update after every step (one step a
time, per the cadence rule).
## Last completed step
**None — stream just carved.** Design validated (3 codebase reviewers; all five reify
contracts confirmed feasible). No code written yet.
**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
- The plan + the five locked contracts exist in `PLAN-REIFY.md`; design-of-record is
`design/execution-evolution-roadmap.md` §7 step 3 + §8.1.
- **Nothing built.** `reify`/`type_info`/`field_type` do not exist in the compiler.
- Confirmed against the source (anchors in the plan): type minting via
`intern`/`internNominal` is programmatic and AST-free; type-fns memoize by mangled
name; enum codegen is fully type-table-driven (zero AST coupling); recursive
forward-declaration (reserve→complete) already exists for source types.
- `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.0 (lock):** add `TypeInfo`/`EnumInfo`/`EnumVariant` data types + bodyless
`#builtin` decls for `reify`/`type_info`/`field_type` to `library/modules/std/core.sx`
(parsed, unimplemented → loud bail), with a unit test that the decls parse. Then 0.1
(xfail: `examples/06xx-comptime-reify-enum.sx`) → 0.2 (green: implement `reify(.enum_)`).
**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