Per the directive to strip reify entirely: the sx `reify(info)` one-shot is
removed. `define(handle, info)` now RETURNS the (completed) handle, so the
one-shot constructor chains as a single expression:
T :: define(declare(), .enum(.{ name = "T", variants = ... }));
- meta.sx: drop reify; RecvResult/TryResult use `define(declare(), …)`.
- interp .define returns the handle type_tag (was void); call.zig lowers it
with `Type` result and sets the info arg's target type to TypeInfo so the
intercepted call still infers the `.enum(…)` literal.
- returnExprMintsType: a type-fn body that returns `define(…)` (or a bodied
non-generic Type-returning sx helper) is comptime-evaluated.
- examples 0614 (direct) + 0615 (type-fn) use `define(declare(), …)`.
Full suite green (673). Files/docs still carry the old reify naming — the
rename sweep is the next commit.
35 lines
1.2 KiB
Plaintext
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 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;
|
|
}
|