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).
This commit is contained in:
agra
2026-06-16 21:03:16 +03:00
parent 442a70b8c9
commit 8ae655687a
11 changed files with 112 additions and 194 deletions

View File

@@ -384,15 +384,16 @@ pub fn lowerInsertExprValue(self: *Lowering, expr: *const Node) Ref {
return last_val;
}
/// Evaluate a Type-returning expression at compile time → its `TypeId`.
/// The driver of the REIFY floor: `expr` (e.g. `reify(.enum(...))`, a type-fn
/// call) is wrapped in a throwaway comptime fn and run through the interpreter
/// with the type-MINT table enabled, so `declare`/`define` builtins reached
/// inside it mutate the real type table. The result value is a `.type_tag`.
/// When `name` is given, the minted (anonymous) type is renamed to it so
/// `type_name` / diagnostics read the binding's name. Returns null (caller
/// poisons) if evaluation didn't yield a Type.
pub fn evalComptimeTypeNamed(self: *Lowering, expr: *const Node, name: ?[]const u8) ?TypeId {
/// Evaluate a `Type`-returning expression at compile time → its `TypeId`.
/// `expr` (a call to any bodied `-> Type` fn) is wrapped in a throwaway comptime
/// fn and run through the interpreter with the type-mint table enabled, so the
/// `declare`/`define` builtins reached inside it mutate the real type table. The
/// result value is a `.type_tag`. A type minted via `define` is already named
/// (the name travels in its `TypeInfo`); a caller needing a different identity
/// name (the type-fn mangled-name path) renames afterwards via
/// `renameNominalType`. Returns null (caller poisons) if evaluation didn't yield
/// a Type.
pub fn evalComptimeType(self: *Lowering, expr: *const Node) ?TypeId {
const func_id = self.createComptimeFunction("__ctype", expr, .any);
var interp = interp_mod.Interpreter.init(self.module, self.alloc);
@@ -401,15 +402,14 @@ pub fn evalComptimeTypeNamed(self: *Lowering, expr: *const Node, name: ?[]const
interp.setMintTable(&self.module.types);
const result = interp.call(func_id, &.{}) catch return null;
const tid = result.asTypeId() orelse return null;
if (name) |nm| self.renameReifiedType(tid, nm);
return tid;
return result.asTypeId();
}
/// Rename a freshly-minted (anonymous `__reified_N`) nominal type to its
/// binding's name, re-keying `intern_map` so `findByName(name)` resolves it.
/// A no-op for a non-nominal / already-named-as-requested type.
pub fn renameReifiedType(self: *Lowering, tid: TypeId, name: []const u8) void {
/// Rename a nominal type to a new name, re-keying `intern_map` so
/// `findByName(name)` resolves it. Used by the type-fn instantiation path to
/// give a comptime-minted type its mangled instantiation name (identity /
/// Contract 1). A no-op for a non-nominal / already-named-as-requested type.
pub fn renameNominalType(self: *Lowering, tid: TypeId, name: []const u8) void {
const tbl = &self.module.types;
const new_name_id = tbl.internString(name);
var info = tbl.get(tid);