Files
sx/current/CHECKPOINT-REIFY.md
agra 81669c72b7 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).
2026-06-16 17:44:19 +03:00

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.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.sxreify(.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 #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.