The compiler concept is declare/define (comptime type construction); the old "reify" framing is gone from the entire repo. - Rename: PLAN-REIFY → PLAN-METATYPE, CHECKPOINT-REIFY → CHECKPOINT-METATYPE, PLAN-POST-REIFY → PLAN-POST-METATYPE (both rewritten around declare/define); examples 0614/0615/0617 → comptime-metatype-* (+ their expected/ triplets), headers rewritten. - Scrub reify from design/execution-evolution-roadmap.md (§7 step 3 contracts, §8.1, §9 decisions, §10 gates) → declare/define / comptime type construction. - core.sx prelude pointer + parser.test.zig surface lock updated to the declare/define builtins (define(handle, info) -> Type; EnumInfo.name). No behavior change; renamed examples match their renamed snapshots. Full suite green (673), all unit tests pass. Zero `reify` tokens remain in src/docs/sx/examples.
35 lines
1.2 KiB
Plaintext
35 lines
1.2 KiB
Plaintext
// Comptime type construction — identity: a type-fn that builds a type with
|
|
// `define(declare(), ...)` must memoize by the instantiation's mangled name, so
|
|
// `Box(i64)` resolved at two INDEPENDENT sites (here: a return type and a
|
|
// parameter type) is ONE `TypeId`. A value built at one site is therefore
|
|
// assignable / matchable at the other — nominal identity. If the minted result
|
|
// were not registered under the mangled instantiation name, the two sites would
|
|
// mint distinct types and `consume(build())` would be a type error.
|
|
#import "modules/std.sx";
|
|
#import "modules/std/meta.sx";
|
|
|
|
Box :: ($T: Type) -> Type {
|
|
return define(declare(), .enum(.{ name = "Box", variants = .[
|
|
EnumVariant.{ name = "some", payload = T },
|
|
EnumVariant.{ name = "none", payload = void },
|
|
] }));
|
|
}
|
|
|
|
build :: () -> Box(i64) { // site A resolves Box(i64)
|
|
return Box(i64).some(7);
|
|
}
|
|
|
|
consume :: (b: Box(i64)) { // site B resolves Box(i64) independently
|
|
if b == {
|
|
case .some: (n) { print("some {}\n", n); }
|
|
case .none: { print("none\n"); }
|
|
}
|
|
}
|
|
|
|
main :: () -> i32 {
|
|
consume(build()); // typechecks ONLY if site A == site B
|
|
b : Box(i64) = .none;
|
|
consume(b);
|
|
return 0;
|
|
}
|