ffi M5.A.next.4A.bare.4.B: tryLowerReflectionCall splits static vs dynamic
Fix for the silent .s64 fall-through in `type_name(<dynamic-arg>)`.
`tryLowerReflectionCall` now splits on `isStaticTypeArg(node)`:
- Static (type_expr / identifier / pack_index_type_expr / pointer
/ array / slice / optional / many_pointer / function_type_expr
/ tuple_literal / call) → fold to const_string at lower time
(today's fast path).
- Dynamic (index_expr, field_access, runtime locals, anything
else) → emit `callBuiltin(.type_name, [arg_ref])`. The interp's
arm (commit 9600ba5) reads the runtime `.type_tag` Value and
returns the per-position name.
`isStaticTypeArg(node)` is a new helper mirroring the explicit
arms of `resolveTypeArg`. Lives alongside resolveTypeArg in
lower.zig; documented to track shape changes together.
emit_llvm: the comptime reflection builtins (`type_name`,
`type_eq`, `has_impl`) now emit a silent undef-i64 placeholder.
Same reasoning as 4A.bare.1.B's relaxation of const_type's
emit_llvm arm: the JIT compiles the containing fn module-wide
even if main never calls it, so emit-time noise here is just
dead-from-main's-perspective code. Real misuse — passing a non-
Type value to one of these — is caught by the interp arm's
`asTypeId orelse bailDetail`.
`examples/171-pack-dynamic-type-name.sx` flips from "s64s64"
(silent .s64 fold per element) to "s64string" (per-position
correct via interp arm). Test runs `walk(42, "hi")` at `#run`
time so the dynamic path executes in the interp.
211/211 example tests + zig build test green.
This commit is contained in:
@@ -2968,15 +2968,17 @@ pub const LLVMEmitter = struct {
|
||||
self.advanceRefCounter();
|
||||
},
|
||||
.type_name, .type_eq, .has_impl => {
|
||||
// Comptime-only reflection builtins. Reaching
|
||||
// LLVM emit means lowering DIDN'T fold the call
|
||||
// (static-arg fast path) AND lowering emitted a
|
||||
// real `builtin_call` — but the resulting IR
|
||||
// shouldn't survive past the comptime interp
|
||||
// that's supposed to consume it. Loud failure:
|
||||
// log + undef placeholder so the LLVM verifier
|
||||
// catches downstream use.
|
||||
std.debug.print("emit_llvm: comptime reflection builtin '{s}' reached runtime emit — Type values are interp-only.\n", .{@tagName(bi.builtin)});
|
||||
// Comptime-only reflection builtins. When the
|
||||
// lowering split between static-fold and
|
||||
// dynamic-builtin-call routes a call to one of
|
||||
// these, the call site is intended for the
|
||||
// interp's arm. LLVM still compiles the
|
||||
// containing fn (the JIT module-wide) even if
|
||||
// main never calls it — so this op DOES reach
|
||||
// emit, just in dead-from-main's-perspective
|
||||
// code. Silent undef-i64 placeholder is the
|
||||
// right answer; the interp's arm catches real
|
||||
// misuse via `asTypeId orelse bailDetail`.
|
||||
self.mapRef(c.LLVMGetUndef(self.toLLVMType(instruction.ty)));
|
||||
},
|
||||
else => {
|
||||
|
||||
Reference in New Issue
Block a user