fix(reflection): replace silent .s64 arg-type fallback with loud .unresolved (issue 0075)

The `type_name` / `type_eq` reflection builtins resolved their Type arg's IR
type via `getRefIRType(...) orelse TypeId.s64`, then gated `== .any`. A failed
must-succeed lookup silently became `.s64` (`!= .any`), classifying a boxed
`Any` arg as bare i64 and reading the wrong value with no diagnostic.

Add the sibling classifier `LLVMEmitter.reflectArgRepr`, which routes the
lookup through `argIRTypeOrFail` (the issue-0074 `.unresolved` resolver) and
returns `{ boxed, bare, unresolved }`. The three emit sites in ops.zig
(`type_name` + `type_eq` x2) now switch on it: `.boxed` extracts the Any value
field, `.bare` uses the value directly, `.unresolved` hits a hard `@panic`
tripwire — never silently treated as bare. Real args always resolve, so the
happy path is byte-identical (suite stays 361/0, zero snapshot churn).

Secondary `lower.zig` `null_literal`/`undef_literal => target_type orelse .void`
confirmed intentional (typeless-literal default deliberately handled by
emitConstNull/emitConstUndef as null-ptr / undef-i64) — left with an invariant
comment, not the `.unresolved` tripwire.

Regression test in emit_llvm.test.zig asserts the loud path: fail-before with
`orelse .s64` yields `.bare`; pass-after yields `.unresolved`.
This commit is contained in:
agra
2026-06-03 16:05:31 +03:00
parent 759e3caa5e
commit aca077d720
5 changed files with 106 additions and 13 deletions

View File

@@ -2249,6 +2249,22 @@ pub const LLVMEmitter = struct {
return self.getRefIRType(arg_ref) orelse .unresolved;
}
/// How a reflection builtin (`type_name` / `type_eq`) must read its `Type`
/// argument: boxed inside an `Any` aggregate (extract the value field) vs a
/// bare i64 `TypeId` index. The IR-type lookup is must-succeed, so it routes
/// through `argIRTypeOrFail`; a failed lookup surfaces as `.unresolved` —
/// never a silent `.s64` that would mis-classify a boxed arg as bare and read
/// the wrong value. The caller turns `.unresolved` into a hard tripwire.
pub const ReflectArgRepr = enum { boxed, bare, unresolved };
pub fn reflectArgRepr(self: *LLVMEmitter, arg_ref: Ref) ReflectArgRepr {
return switch (self.argIRTypeOrFail(arg_ref)) {
.unresolved => .unresolved,
.any => .boxed,
else => .bare,
};
}
/// Coerce both binary operands to match the instruction's result type.
/// E.g. if result is i64 but one operand is i32, sext it.