Skip to content

Sema, MIR: a call lowers against the signature Sema resolved for it, never the name looked up again (#2723) - #2739

Merged
ehartford merged 1 commit into
fix-2722from
fix-2723
Oct 26, 2026
Merged

ehartford merged 1 commit into
fix-2722from
fix-2723

Conversation

@ehartford

@ehartford ehartford commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

MirLower took a plain call's signature from Sema's resolved_call_sigs when
there was one, else resolved the callee's name again (call_sig_for_sym ->
Sema.get_sig). Sema recorded the resolution only for method calls, and
get_sig answers relative to Sema's current module, which during MIR lowering
is whatever module it checked last, not the caller's. On Windows the runtime
declares Winsock's extern fn accept(s: i64, addr, addrlen), so a program's
own fn accept(value: G) was lowered against the extern's signature: the
argument became copy _2 (an i64 parameter consumes nothing) and the
caller dropped _2 after accept had dropped it. analyze on
--target=windows_x86_64 showed accept copy copy _2 against darwin's
move move _2, and sig 938 (the extern, 3 parameters) beside sig 940.
The argument's ownership was decided the same way: lower_call_arg asks
extern_param_is_bit_copy (MirLower.w 12969), which judged by the flat
symbol (extern_fn_names.contains(fn_sym)), so with sig 940 resolved the
argument was still re-issued as copy _2; it now returns 0 for a
signature that is not an extern's (extern_sig_modules). check_call also
records the signature it resolved for every direct call,
so MirLower reads Sema's answer (D65: one owner for the call target).
da_generic_call_results failed on Windows for this reason.

Test: test/behavior/behav_2723_call_lowers_against_sema_signature.w
(prints "2 3 5" on Windows before the fix, "1 2 3" after).

Closes #2723

@ehartford
ehartford added this pull request to stack #2743 October 26, 2026 04:07
@ehartford ehartford changed the title fix 2723 Sema, MIR: a call lowers against the signature Sema resolved for it, never the name looked up again (#2723) Oct 26, 2026
…never the name looked up again (#2723)

MirLower took a plain call's signature from Sema's resolved_call_sigs when
there was one, else resolved the callee's name again (call_sig_for_sym ->
Sema.get_sig). Sema recorded the resolution only for method calls, and
get_sig answers relative to Sema's current module, which during MIR lowering
is whatever module it checked last, not the caller's. On Windows the runtime
declares Winsock's `extern fn accept(s: i64, addr, addrlen)`, so a program's
own `fn accept(value: G)` was lowered against the extern's signature: the
argument became `copy _2` (an i64 parameter consumes nothing) and the
caller dropped `_2` after accept had dropped it. `analyze` on
--target=windows_x86_64 showed `accept copy copy _2` against darwin's
`move move _2`, and sig 938 (the extern, 3 parameters) beside sig 940.
The argument's ownership was decided the same way: lower_call_arg asks
extern_param_is_bit_copy (MirLower.w 12969), which judged by the flat
symbol (`extern_fn_names.contains(fn_sym)`), so with sig 940 resolved the
argument was still re-issued as `copy _2`; it now returns 0 for a
signature that is not an extern's (extern_sig_modules). check_call also
records the signature it resolved for every direct call,
so MirLower reads Sema's answer (D65: one owner for the call target).
da_generic_call_results failed on Windows for this reason.

Test: test/behavior/behav_2723_call_lowers_against_sema_signature.w
(prints "2 3 5" on Windows before the fix, "1 2 3" after).
@ehartford
ehartford marked this pull request as ready for review October 26, 2026 04:31
@ehartford
ehartford merged commit 013ba52 into main Oct 26, 2026
@ehartford
ehartford deleted the fix-2723 branch October 26, 2026 04:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: a generic call's result passed to a consuming parameter is dropped the wrong number of times (da_generic_call_results)

1 participant