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.
39 lines
1.2 KiB
Plaintext
39 lines
1.2 KiB
Plaintext
// Variadic heterogeneous type packs — step 4A final-slice
|
|
// follow-up. `type_name(<dynamic-arg>)` where the argument is
|
|
// NOT a static type expression (e.g. `list[i]` indexing into
|
|
// a `$args`-derived `[]Type` slice) silently folded to "s64"
|
|
// because `resolveTypeArg`'s catch-all `else => .s64` lied —
|
|
// the kind of silent unimplemented arm the project's REJECTED
|
|
// PATTERNS forbid.
|
|
//
|
|
// The fix: `tryLowerReflectionCall` now splits static vs
|
|
// dynamic args via `isStaticTypeArg(node)`. Static → fold to
|
|
// const_string at lower time (today's fast path). Dynamic →
|
|
// emit `callBuiltin(.type_name, [arg_ref])` for the interp's
|
|
// runtime arm to handle.
|
|
//
|
|
// Type values are comptime-only — the dynamic path only works
|
|
// inside a comptime context (`#run` / `#insert`). The test
|
|
// runs `walk(42, "hi")` at `#run` time and prints the result.
|
|
|
|
#import "modules/std.sx";
|
|
#import "modules/compiler.sx";
|
|
|
|
walk :: (..$args) -> string {
|
|
list := $args;
|
|
s := "";
|
|
i : s64 = 0;
|
|
while i < list.len {
|
|
s = concat(s, type_name(list[i]));
|
|
i = i + 1;
|
|
}
|
|
return s;
|
|
}
|
|
|
|
show :: () {
|
|
print("{}\n", walk(42, "hi"));
|
|
}
|
|
#run show();
|
|
|
|
main :: () { print("rt\n"); }
|