Skip to content

codegen(win64): sret-lower collect[String] runtime call (#806) - #822

Merged
ropoctl merged 3 commits into
windows-806-combinator-indirectfrom
windows-806-collect-string
Aug 18, 2026
Merged

ropoctl merged 3 commits into
windows-806-combinator-indirectfrom
windows-806-collect-string

Conversation

@ropoctl

@ropoctl ropoctl commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Problem

collect[String] produced corrupt output on win64 (exit 5/1). mir_emit_iter_collect hand-rolled a direct-return signature for the with_str_from_vec_u8 runtime call, but win64 returns a 16-byte str aggregate via sret (hidden pointer first param). This is exactly the per-path ABI divergence D6 forbids: one call site re-derived value vs sret locally instead of reading the single FnAbi/build_call_fn_value path.

Fix

Route the with_str_from_vec_u8 call through internal_abi_needs_sret + record_c_abi_transform + build_call_fn_value — the same single sret-aware path every other call uses. No per-path ABI decision remains.

Verification

  • IR (before): call %str @with_str_from_vec_u8(ptr %v) (direct)
  • IR (after, win64): call void @with_str_from_vec_u8(ptr sret(%str) %out, ptr %v) — matches callee prologue and sibling call sites
  • IR (after, linux/SysV): unchanged direct 16B return — no regression
  • VM (real Windows x86_64): ct_string.exe → ok EXIT=0; ct_collect_targets.exe → ok EXIT=0 (all 6 collect targets: Vec/HashSet/HashMap/BTreeSet/BTreeMap/String)
  • Un-skips test/spec/spec_ss13_3_collect_targets.w on Windows

Stacked on #821 (windows-806-combinator-indirect).

@ropoctl
ropoctl force-pushed the windows-806-collect-string branch from df30c13 to 9ab35c3 Compare August 18, 2026 01:16
@ropoctl
ropoctl force-pushed the windows-806-collect-string branch from 9ab35c3 to 10f1060 Compare August 18, 2026 02:24
mir_emit_iter_collect hand-rolled a direct-return LLVM signature for the
with_str_from_vec_u8 runtime call — `declare %str @with_str_from_vec_u8(ptr)`
called as `%v = call %str ...`. On win64 a 16-byte str is returned via sret
(hidden pointer first arg), so the callee prologue and every other call site
lower it as `void @with_str_from_vec_u8(ptr sret(%str), ptr)`. The collect
site was the single divergent caller: it read a 16-byte value out of a
function that writes through an sret pointer, so collect[String] produced a
corrupt str and the spec test exited non-zero on native Windows.

Route the call through the single FnAbi path instead of a per-site ABI
guess (D6): declare the callee sret-aware via internal_abi_needs_sret +
wl_add_sret_attr + record_c_abi_transform, then call through
build_call_fn_value, which allocates the sret slot and loads the result.
Gated on internal_abi_needs_sret, so SysV (16B in RAX:RDX) is unchanged.

Verified: win64 IR collect site becomes
`call void @with_str_from_vec_u8(ptr sret(%str) %slot, ptr)`, matching the
callee and sibling calls; linux IR stays direct-return. Cross-built and run
on the real Windows VM: collect[String] repro and spec_ss13_3_collect_targets
(all six targets) both print ok.
The collect[String] sret fix makes all six collect targets
(Vec/HashSet/HashMap/BTreeSet/BTreeMap/String) produce correct output on
native Windows. Verified on the real VM: the cross-built test prints ok.
Remove the skip-windows gate.
@ropoctl
ropoctl force-pushed the windows-806-collect-string branch from 10f1060 to a9cd505 Compare August 18, 2026 02:58
@ropoctl
ropoctl merged commit 2ea52e8 into main Aug 18, 2026
3 checks passed
@ehartford
ehartford deleted the windows-806-collect-string 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