Repository navigation
MirLower: a call through a let-alias of a non-Copy fn field calls the stored callable, not a function named after the binding (#1635) - #1641
Merged
Conversation
… stored callable, not a function named after the binding (#1635) `let r = c.run; r(21)` with `run: fn(i32) -> i32` lowered to `call const fn sym(r)()` — a direct call to a function SYMBOL named `r` with the argument dropped — and codegen died with `FATAL: unhandled MirIntrinsic.GENERIC_CALL sym=r ... arg_count=0`. The build runner's own compile (build/corpora.w:74) hit it. Root cause (lldb on the :dev stage1, breakpoint on sym_is_generic_fn conditioned on sym 13356 = `r`): frame #0: MirBuilder.sym_is_generic_fn -> returns 0 frame #1: MirBuilder.generic_fn_node_for_sym -> returns 0 frame #2: MirBuilder.lower_expr (NK_CALL ident dispatch) frame #3: MirBuilder.lower_block_mode frame #4: MirBuilder.lower_expr frame #5: lower_fn_with_sig frame #6: lower_module frame #7: Compilation.run_mir_lower With the generic branch declining, the next ident branch in lower_expr's NK_CALL dispatch — "Check for builtin calls (embed_file, src, etc.) — no sig, not a local" — gated on if bu_sig < 0 and bu_local < 0: // bu_local = lookup_local(bu_sym) `r` is not a MIR local: under D63 a `fn(A) -> R` field is not Copy, so `let r = c.run` is a VIEW binding and lower_let_binding took the alias path (bind_alias_place, no local). lookup_local(r) < 0, the alias table was never consulted, and the branch emitted the "unresolved bare function" GENERIC_CALL with an empty argument list. lower_call / lower_callable_expr — which do handle place callees — were never reached. Fix: D29 precedence, applied once at the head of the ident dispatch. A callee ident that names a local OR an alias place (`ident_names_local_callable`, the #1230 helper) is an indirect call through what the binding names; it goes straight to lower_call before the variant/distinct/type/generic/builtin interpretations of the text. lower_callable_expr's in-place read (D63 §12.4: calling through a binding observes, never moves) now covers alias idents too, so the alias of a non-Copy callable is read from its place instead of moved out; the builtin branch's gate uses the same helper. Fixture: test/behavior/behav_callable_alias_field_call.w — borrowed, owned, nested field, plus `.clone()()` and the direct field call in one expression (42 / 21 / 126). A move-closure with an environment through every shape (direct, `&c.f`, alias, owned) returns the right value with leak count=0 under --debug-alloc. Verified: with-stage1 analyze build.w audit:codegen -> violations=0 ok (main: 10096 violations), and violations=0 ok on a :stage2 build too, where check src/main.w is clean and behav_fn_abi_callable.w passes; the 40 closure/callable fixtures green; :dev green. Filed from the hunt: #1638 (a non-move closure capturing a local by reference escapes its frame in a returned struct field, no diagnostic — independent of this fix, reproduces on the seed) and #1639 (validate-all was silent on this MIR: a direct call to an unresolvable CK_FN symbol with the source arguments dropped passed as ok).
ehartford
force-pushed
the
fix-alias-callable-call
branch
from
September 24, 2026 16:52
0449133 to
5c6fbee
Compare
ehartford
marked this pull request as ready for review
September 24, 2026 18:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MirLower: a call through a let-alias of a non-Copy fn field calls the stored callable, not a function named after the binding (#1635)
let r = c.run; r(21)withrun: fn(i32) -> i32lowered tocall const fn sym(r)()— a direct call to a function SYMBOL namedrwith the argument dropped — and codegen died with
FATAL: unhandled MirIntrinsic.GENERIC_CALL sym=r ... arg_count=0.The build runner's own compile (build/corpora.w:74) hit it.
Root cause (lldb on the :dev stage1, breakpoint on sym_is_generic_fn
conditioned on sym 13356 =
r):With the generic branch declining, the next ident branch in lower_expr's
NK_CALL dispatch — "Check for builtin calls (embed_file, src, etc.) — no
sig, not a local" — gated on
ris not a MIR local: under D63 afn(A) -> Rfield is not Copy, solet r = c.runis a VIEW binding and lower_let_binding took the aliaspath (bind_alias_place, no local). lookup_local(r) < 0, the alias table
was never consulted, and the branch emitted the "unresolved bare
function" GENERIC_CALL with an empty argument list. lower_call /
lower_callable_expr — which do handle place callees — were never reached.
Fix: D29 precedence, applied once at the head of the ident dispatch. A
callee ident that names a local OR an alias place
(
ident_names_local_callable, the #1230 helper) is an indirect callthrough what the binding names; it goes straight to lower_call before
the variant/distinct/type/generic/builtin interpretations of the text.
lower_callable_expr's in-place read (D63 §12.4: calling through a
binding observes, never moves) now covers alias idents too, so the alias
of a non-Copy callable is read from its place instead of moved out; the
builtin branch's gate uses the same helper.
Fixture: test/behavior/behav_callable_alias_field_call.w — borrowed,
owned, nested field, plus
.clone()()and the direct field call in oneexpression (42 / 21 / 126). A move-closure with an environment through
every shape (direct,
&c.f, alias, owned) returns the right value withleak count=0 under --debug-alloc.
Verified: with-stage1 analyze build.w audit:codegen -> violations=0 ok
(main: 10096 violations), and violations=0 ok on a :stage2 build too, where check src/main.w is clean and behav_fn_abi_callable.w passes; the 40 closure/callable fixtures green;
:dev green.
Filed from the hunt: #1638 (a non-move closure capturing a local by
reference escapes its frame in a returned struct field, no diagnostic —
independent of this fix, reproduces on the seed) and #1639 (validate-all
was silent on this MIR: a direct call to an unresolvable CK_FN symbol
with the source arguments dropped passed as ok).