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:
@@ -1,21 +1,23 @@
|
||||
// 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 folds to "s64"
|
||||
// today because `resolveTypeArg`'s index_expr fall-through
|
||||
// returns `.s64`. That's exactly the kind of silent unimplemented
|
||||
// arm the CLAUDE.md REJECTED PATTERNS section forbids.
|
||||
// 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.
|
||||
//
|
||||
// Next commit teaches `tryLowerReflectionCall` to detect "arg
|
||||
// not statically resolvable" and emit a `builtin_call` to the
|
||||
// new `.type_name` builtin. The interp's arm (already wired in
|
||||
// commit 9600ba5) reads the runtime `.type_tag` Value and
|
||||
// returns the per-position concrete type name.
|
||||
// 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.
|
||||
//
|
||||
// Expected output after fix:
|
||||
// s64string
|
||||
// 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;
|
||||
@@ -28,7 +30,9 @@ walk :: (..$args) -> string {
|
||||
return s;
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
show :: () {
|
||||
print("{}\n", walk(42, "hi"));
|
||||
return 0;
|
||||
}
|
||||
#run show();
|
||||
|
||||
main :: () { print("rt\n"); }
|
||||
|
||||
Reference in New Issue
Block a user