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).
2.9 KiB
CHECKPOINT-REIFY — comptime type_info / reify (async-first foundation, step 3)
Companion to PLAN-REIFY.md. Update after every step (one step at a time, per the cadence rule).
Last completed step
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.sxdeclares the surface; the variant uses the backtick raw escape`enum(reads as the keyword, not a mangledenum_).- Loud bails wired (unimplemented → diagnostic, never a silent type):
reify(...)in a::type-alias position →decl.zig(the.callconst-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_typein any other type position →generic.zig:resolveTypeCallWithBindings(defense-in-depth).type_info(...)in expression position →call.zig:tryLowerReflectionCall.
- No interpreter-side construction yet —
reifymints 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/.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#builtindecls), loud bails at all three reach points,src/parser.test.zigparse-lock. Two user-directed refinements folded in: variant uses`enumraw escape; surface moved out of the prelude into its own module to avoid type-table /.ir-snapshot churn.zig build testgreen. - Stream carved. Selected as the first async-first foundation:
reifygates both channel result types (RecvResult($T)) andrace's synthesized union, is fully validated (3 reviewers), and is a self-contained compiler/type-system feature testable in isolation (06xxcomptime). Generic-enum syntax dropped in its favor.