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).
This commit is contained in:
@@ -1676,6 +1676,16 @@ pub fn tryLowerReflectionCall(self: *Lowering, name: []const u8, c: *const ast.C
|
||||
// classification covers all 7; it runs before dispatch.
|
||||
if (self.reflectionTypeArgGuard(name, c)) |sentinel| return sentinel;
|
||||
|
||||
if (std.mem.eql(u8, name, "type_info")) {
|
||||
// Comptime reflection-into-data (REIFY). Until the interpreter-side
|
||||
// reflection lands (Phase 2), bail loudly rather than fall through to
|
||||
// the no-body `#builtin` const_decl path (which would mis-lower as a
|
||||
// zero-arg call). A silent fall-through would hand the caller a
|
||||
// garbage TypeInfo value.
|
||||
if (self.diagnostics) |d|
|
||||
d.addFmt(.err, c.callee.span, "type_info is not yet implemented (REIFY Phase 2)", .{});
|
||||
return Ref.none;
|
||||
}
|
||||
if (std.mem.eql(u8, name, "size_of")) {
|
||||
// size_of(T) → const_int(sizeof(T))
|
||||
const ty = self.resolveTypeArg(c.args[0]);
|
||||
|
||||
@@ -651,6 +651,17 @@ pub fn scanDecls(self: *Lowering, decls: []const *const Node) void {
|
||||
.field_access => |fa| fa.field,
|
||||
else => "",
|
||||
};
|
||||
// `E :: reify(...)` — mint a nominal type from a `TypeInfo`
|
||||
// and register `E` as an alias to it. The interpreter-side
|
||||
// construction lands in Phase 0.2; until then bail LOUDLY
|
||||
// and poison `E` to `.unresolved` (so downstream `E.value`
|
||||
// gets a clean follow-on, not a silent default type).
|
||||
if (std.mem.eql(u8, callee_name, "reify")) {
|
||||
if (self.diagnostics) |d|
|
||||
d.addFmt(.err, cd.value.span, "reify is not yet implemented (REIFY Phase 0.2)", .{});
|
||||
self.putTypeAlias(self.current_source_file, cd.name, .unresolved);
|
||||
continue;
|
||||
}
|
||||
// A namespaced callee (`ns.Box(..)`) is an explicit qualified
|
||||
// reach, exempt from the bare-head visibility gate (E4).
|
||||
const head_qualified = call_data.callee.data == .field_access;
|
||||
|
||||
@@ -1219,6 +1219,22 @@ pub fn resolveTypeCallWithBindings(self: *Lowering, cl: *const ast.Call) TypeId
|
||||
.field_access => |fa| fa.field,
|
||||
else => return .unresolved,
|
||||
};
|
||||
// Comptime type-construction builtins (REIFY). `reify`/`field_type`
|
||||
// appear in type position (`E :: reify(...)`, `field_type(T, i)` as a
|
||||
// type arg). Until the interpreter-side construction lands (Phase 0.2 /
|
||||
// Phase 2), bail LOUDLY rather than fall through to the misleading
|
||||
// "unknown type 'reify'" diagnostic below — a silent default here would
|
||||
// poison every downstream use of the type.
|
||||
if (std.mem.eql(u8, callee_name, "reify")) {
|
||||
if (self.diagnostics) |d|
|
||||
d.addFmt(.err, cl.callee.span, "reify is not yet implemented (REIFY Phase 0.2)", .{});
|
||||
return .unresolved;
|
||||
}
|
||||
if (std.mem.eql(u8, callee_name, "field_type")) {
|
||||
if (self.diagnostics) |d|
|
||||
d.addFmt(.err, cl.callee.span, "field_type is not yet implemented (REIFY Phase 2)", .{});
|
||||
return .unresolved;
|
||||
}
|
||||
// Built-in: Vector(N, T)
|
||||
if (std.mem.eql(u8, callee_name, "Vector") and cl.args.len == 2) {
|
||||
const length = self.resolveVectorLane(cl.args[0]) orelse return .unresolved;
|
||||
|
||||
Reference in New Issue
Block a user