Files
sx/examples/0615-comptime-reify-typefn-identity.sx
agra 8ae655687a green(reify): type-fn bodies comptime-evaluated; reify fully removed from the compiler
Second slice of the re-architecture — the compiler now has ZERO type-
construction code beyond declare/define.

- instantiateTypeFunction: a type-fn body returning a computed Type (a call
  to a non-generic, bodied, Type-returning fn) is comptime-evaluated with the
  type bindings active, then renamed to the mangled instantiation name for
  identity (renameNominalType). Replaces the old reify-call pattern-matching.
- DELETED: reifyType (lower/nominal.zig), findReturnReifyCall (lower/generic.zig),
  and the stale inline-position reify gate in resolveTypeCallWithBindings.
- evalComptimeType (was evalComptimeTypeNamed): pure eval, no rename; the
  type-fn caller renames explicitly. renameReifiedType → renameNominalType.
- The TYPE NAME now travels in the data: EnumInfo gains `name`, and define()
  names the slot from it (the compiler derives no name from a binding LHS).
  examples/0614/0615 carry `name = "..."`; RecvResult/TryResult set it too.
- field_type stays a reflection #builtin (reads a type); only construction
  moved out. All reify mentions stripped from compiler source.

examples 0614/0615/0617 run on the floor. Full suite green (673).
2026-06-16 21:03:16 +03:00

35 lines
1.2 KiB
Plaintext

// REIFY Phase 1: a type-fn that RETURNS `reify(...)` 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
// (Contract 1). If the reify 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 reify(.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;
}