Repository navigation
codegen(win64): closure call type matches by-value callee return (#806) - #819
Merged
Merged
Conversation
ropoctl
force-pushed
the
windows-806-closure-callabi
branch
from
August 17, 2026 21:36
58865ae to
0eff756
Compare
This was referenced Aug 17, 2026
ropoctl
force-pushed
the
windows-806-closure-callabi
branch
from
August 17, 2026 23:03
0eff756 to
11fa778
Compare
ropoctl
force-pushed
the
windows-806-closure-callabi
branch
4 times, most recently
from
August 18, 2026 02:24
d0636d1 to
b683c92
Compare
…806) mir_build_closure_fn_type built the closure CALL type with manual win64 sret-lowering: when internal_abi_needs_sret(ret) it pushed an sret ptr param and set the return to void, ordering params env-first, sret-second. But the closure DEFINITION is always emitted with a by-value direct return (define %str @__closure(ptr %env)) — gen_closure forces current_function_name_sym = 0 so a closure never inherits the enclosing fn's sret verdict. LLVM then applies its own win64 sret to the callee: sret ptr in RCX, env shifted to RDX. The caller, however, passed env in RCX and the sret ptr in RDX. Swapped registers: the str result was written through the env pointer (garbage) and the real destination was never written, so a str-returning closure (e.g. .with_context(() => "lazy")) yielded a corrupt message. Remove the manual sret-lowering so the call type matches the always by-value callee. Contrast mir_build_raw_fn_type, whose sret lowering is correct because a named fn-pointer target is itself sret-lowered by declare_function; only the closure path diverged. Gated by internal_abi_needs_sret (false off win64) so linux/mac IR is unchanged.
The by-value closure call-type fix makes str-returning closures produce correct results on win64. Three spec tests that failed only through that path now match their linux baseline under cross-build + wine: - spec_ss10_6_error_context (str-returning with_context closure) - spec_ss10_5_sequence_traverse_transpose (fat-fn/closure str values) - spec_ss14_3_1_no_suspend_blocks (async closure value return) The remaining four #806 tests (option_result_combinators, result_combinators_complete, error_trait, collect_targets) still fail on win64 through a distinct data-flow path and stay skipped.
ropoctl
force-pushed
the
windows-806-closure-callabi
branch
from
August 18, 2026 02:58
b683c92 to
f553011
Compare
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.
Stacked on #818 (
windows-806-closure-sret).Codegen fix
mir_build_closure_fn_typebuilt the closure call type with manualwin64 sret-lowering: when
internal_abi_needs_sret(ret)was true itpushed an sret pointer parameter and set the return to
void, orderingthe params env-first, sret-second.
But the closure definition is always emitted with a by-value direct
return (
define %str @__closure(ptr %env)) —gen_closureforcescurrent_function_name_sym = 0, so a closure never inherits theenclosing function's sret verdict. LLVM then applies its own win64 sret
to the callee: sret pointer in RCX, env shifted to RDX. The caller,
however, passed env in RCX and the sret pointer in RDX. Swapped
registers: the
strresult was written through the env pointer(garbage) and the real destination was never written, so a
str-returning closure (e.g..with_context(() => "lazy")) yielded acorrupt message.
Removing the manual sret-lowering makes the call type match the
always-by-value callee. Contrast
mir_build_raw_fn_type, whose sretlowering is correct because a named fn-pointer target is itself
sret-lowered by
declare_function; only the closure path diverged.Gated behind
internal_abi_needs_sret(false off win64), so linux/macIR is byte-identical.
Test un-skips
Three spec tests failed only through the corrupted str-closure path and
now match their linux baseline (cross-built, run under wine, exit 0):
spec_ss10_6_error_context—str-returningwith_contextclosurespec_ss10_5_sequence_traverse_transpose— fat-fn/closurestrvaluesspec_ss14_3_1_no_suspend_blocks— async closure value returnThe remaining four #806 tests (
option_result_combinators,result_combinators_complete,error_trait,collect_targets) stillfail on win64 through a distinct data-flow path and stay skipped.