Skip to content

codegen(win64): indirect aggregate closure params by pointer; un-skip combinator tests (#806) - #821

Merged
ropoctl merged 4 commits into
windows-806-error-traitfrom
windows-806-combinator-indirect
Aug 18, 2026
Merged

ropoctl merged 4 commits into
windows-806-error-traitfrom
windows-806-combinator-indirect

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes the win64 Option/Result combinator wrong-output class under #806
and un-skips the two affected spec tests on Windows.

spec_ss10_3_option_result_combinators and
spec_ss10_6_result_combinators_complete produced wrong output on win64
(e.g. map_err(s => s.len()) returning 0 instead of 3).

Root cause (D6 — one ABI, read by both sides)

A closure callee built its parameter LLVM signature directly from each
parameter's by-value type. But the closure call site
(mir_build_closure_fn_type) applies internal_abi_needs_indirect_param,
so a win64 aggregate larger than 8 bytes — a 16-byte str, for instance —
is passed as a pointer. Caller and callee then disagreed on the
argument shape, so the aggregate arrived corrupted and the closure read
garbage.

This is the same single-ABI-source-of-truth divergence class as the
sibling dispatch-vs-vtable fix: one side re-derived the passing mode
independently of the other.

Fix

Mirror the call-site decision in gen_closure:

  • When a parameter is win64-indirect, declare it as ptr in the callee
    signature (matching the call site).
  • In the body prologue, load a callee-owned copy from the incoming pointer
    into a local alloca, so the body reads its own storage.

The path is gated on internal_abi_needs_indirect_param, which is
win64-only, so non-win64 targets are unchanged (the branch is a no-op
and the direct-by-value path is taken exactly as before).

Verification (native Windows VM)

Cross-built with the fixed stage1, run on the real Windows x86_64 VM:

test result
spec_ss10_3_option_result_combinators ok
spec_ss10_6_result_combinators_complete ok
combinator matrix (map / map_err / and_then / or_else / filter) all correct

Regression — the closure/dyn tests already un-skipped by #818/#819/#820
still pass on the VM: error_context, sequence_traverse_transpose,
no_suspend_blocks, error_trait → all ok.

Stacked on #820.

@ropoctl
ropoctl force-pushed the windows-806-combinator-indirect branch from 3f461c3 to b3bb099 Compare August 17, 2026 23:03
@ropoctl
ropoctl force-pushed the windows-806-combinator-indirect branch from f1ca9d1 to f3fe038 Compare August 18, 2026 00:14
@ropoctl
ropoctl force-pushed the windows-806-combinator-indirect branch from f3fe038 to b75e0c4 Compare August 18, 2026 01:16
@ropoctl
ropoctl force-pushed the windows-806-combinator-indirect branch from b75e0c4 to a1952b9 Compare August 18, 2026 02:24
The win64 dyn-trait sret-lowering fix in the previous commit makes
&dyn Error.source() (returning the 24-byte fat Option[&dyn Error])
produce correct output on Windows. Remove the skip-windows gate.
…callee (#806)

A closure callee built its parameter LLVM signature straight from each
param's by-value type, but the closure CALL site
(mir_build_closure_fn_type) applies internal_abi_needs_indirect_param and
passes a win64 aggregate >8B (e.g. a 16-byte str) as a pointer. Caller
and callee then disagreed on the argument shape, so the aggregate arrived
corrupted: map_err(s => s.len()) read a garbage str and returned 0.

Mirror the call-site ABI in gen_closure: when a param is win64-indirect,
declare it as ptr in the callee signature and, in the body prologue, load
a callee-owned copy from the incoming pointer into a local alloca. This
reads the single FnAbi-equivalent indirect decision that the call site
already uses (D6), so producer and consumer agree. The path is gated on
internal_abi_needs_indirect_param, which is win64-only, so non-win64
targets are unchanged.

Fixes the Option/Result combinator wrong-output class (#806).
The indirect-aggregate closure-param codegen fix makes the win64 closure
call ABI agree with the callee, so the Option/Result combinator tests now
produce correct output. Verified on the native Windows VM:
spec_ss10_3 -> ok, spec_ss10_6 -> ok.
@ropoctl
ropoctl force-pushed the windows-806-combinator-indirect branch from a1952b9 to 7e768b7 Compare August 18, 2026 02:58
@ropoctl
ropoctl merged commit b6e422a into main Aug 18, 2026
3 of 5 checks passed
@ehartford
ehartford deleted the windows-806-combinator-indirect branch September 24, 2026 16:58
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.

1 participant