green: erase the sx reify sugar — declare/define are the only constructors
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.
This commit is contained in:
@@ -2062,7 +2062,8 @@ pub const Interpreter = struct {
|
||||
.nominal_id = cur.tagged_union.nominal_id,
|
||||
} };
|
||||
tbl.replaceKeyedInfo(handle, full);
|
||||
return .{ .value = .void_val };
|
||||
// Return the handle so the one-shot form chains: `T :: define(declare(), info)`.
|
||||
return .{ .value = .{ .type_tag = handle } };
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1695,9 +1695,18 @@ pub fn tryLowerReflectionCall(self: *Lowering, name: []const u8, c: *const ast.C
|
||||
return Ref.none;
|
||||
}
|
||||
const handle_ref = self.lowerExpr(c.args[0]);
|
||||
// Lower the info arg with `TypeInfo` as the target type so its `.enum(…)`
|
||||
// enum-literal infers correctly (we intercept the call, bypassing the
|
||||
// normal param-type-threading the regular call path does).
|
||||
const saved_tt = self.target_type;
|
||||
if (self.module.types.findByName(self.module.types.internString("TypeInfo"))) |ti|
|
||||
self.target_type = ti;
|
||||
const info_ref = self.lowerExpr(c.args[1]);
|
||||
self.target_type = saved_tt;
|
||||
const args_owned = self.alloc.dupe(Ref, &.{ handle_ref, info_ref }) catch return Ref.none;
|
||||
return self.builder.callBuiltin(.define, args_owned, .void);
|
||||
// define returns the (now-completed) handle as a `Type` value, so the
|
||||
// one-shot constructor form chains: `T :: define(declare(), info)`.
|
||||
return self.builder.callBuiltin(.define, args_owned, .any);
|
||||
}
|
||||
if (std.mem.eql(u8, name, "type_info")) {
|
||||
// Comptime reflection-into-data (reflect a type INTO a `TypeInfo`
|
||||
|
||||
@@ -1797,18 +1797,25 @@ pub fn findReturnTypeExpr(body: *const Node) ?*const Node {
|
||||
return body;
|
||||
}
|
||||
|
||||
/// True when a type-fn's return expression mints a type at comptime — a call to
|
||||
/// a NON-generic, bodied, `Type`-returning fn (a comptime type constructor).
|
||||
/// Such a body is comptime-evaluated (its `declare`/`define` mint the type)
|
||||
/// rather than statically resolved. Excludes generic / `#builtin` type
|
||||
/// constructors (`Vector(N,T)`, `Make($T)`), which the static path handles. No
|
||||
/// hardcoded constructor names — any qualifying Type-returning fn flows here.
|
||||
/// True when a type-fn's return expression mints a type at comptime and must be
|
||||
/// run through the interpreter rather than statically resolved. Two shapes:
|
||||
/// - a call to the `define` construction primitive — `return define(declare(),
|
||||
/// info)`, the one-shot constructor form; or
|
||||
/// - a call to a NON-generic, bodied, `Type`-returning sx fn (a constructor
|
||||
/// helper that itself ends in `define`).
|
||||
/// Excludes generic / static type constructors (`Vector(N,T)`, `Make($T)`,
|
||||
/// `return [K]T`, `return T`), which the static `resolveTypeWithBindings` path
|
||||
/// handles.
|
||||
pub fn returnExprMintsType(self: *Lowering, ret: *const Node) bool {
|
||||
if (ret.data != .call) return false;
|
||||
const callee = ret.data.call.callee;
|
||||
if (callee.data != .identifier) return false;
|
||||
const fd = self.program_index.fn_ast_map.get(callee.data.identifier.name) orelse return false;
|
||||
if (fd.type_params.len != 0) return false; // generic constructors stay static
|
||||
const name = callee.data.identifier.name;
|
||||
// The construction terminator builtin — a constructor's final act.
|
||||
if (std.mem.eql(u8, name, "define")) return true;
|
||||
// A bodied, non-generic, Type-returning sx helper.
|
||||
const fd = self.program_index.fn_ast_map.get(name) orelse return false;
|
||||
if (fd.type_params.len != 0) return false;
|
||||
if (fd.body.data == .block and fd.body.data.block.stmts.len == 0) return false; // bodyless #builtin
|
||||
const rt = fd.return_type orelse return false;
|
||||
return rt.data == .type_expr and std.mem.eql(u8, rt.data.type_expr.name, "Type");
|
||||
|
||||
Reference in New Issue
Block a user