Repository navigation
codegen(win64): materialize dyn-trait fat pointers, sync + async (#806) - #817
Merged
Merged
Conversation
ropoctl
force-pushed
the
windows-codegen-806
branch
2 times, most recently
from
August 17, 2026 16:42
46a0e29 to
2799a22
Compare
ropoctl
force-pushed
the
windows-codegen-806
branch
from
August 17, 2026 18:54
2799a22 to
382b7e8
Compare
ropoctl
added a commit
that referenced
this pull request
Aug 17, 2026
…806) The #806 fat-pointer fix taught `dyn_trait_method_fn_type` to apply the native win64 ABI to vtable slots. That correctly sret-lowers an aggregate return >8B — but the `create_dyn_wrapper` vtable wrapper still built its signature and return from the pre-ABI shape, so for an async method (Task `{i32,ptr}`, 16B) the wrapper: - returned by value against a slot type that is now `void(sret, ...)`, shifting every argument by one, and - seeded the async Task aggregate from the sret-lowered `void` return, emitting `insertvalue void undef` — an LLVM verify error that aborted win64 codegen for any async dyn-trait program. Detect the sret lowering (async method whose `dyn_ft` returns void with one extra leading parameter), carry the sret slot as parameter 0, place self/args after it, reconstruct the real `{i32,ptr}` Task type for the spawn, and store the produced Task through the sret slot instead of returning it by value. The wrapper signature now matches the vtable slot and the dispatch call site (D6: one ABI, agreed at every reader). On SysV the 16B Task returns in registers (no sret), so `has_sret` is false and the wrapper is byte-identical to before — linux/mac and the sync sealed-trait path are untouched. Un-holds #817: `spec_ss11_5_dyn_async_trait_methods` and `spec_ss14_3_async_calling_is_unrestricted` now pass on win64.
…t ABI (#806) On x86_64-pc-windows-msvc a `dyn Trait` value is a 16-byte fat pointer `{data_ptr, vtable_ptr}` — larger than 8 bytes, so win64 classifies it as an indirect-aggregate parameter (passed by address) and a `str`-returning trait method as sret. Two call-lowering paths dropped the fat-pointer construction under that ABI, so the callee read a fat pointer out of a raw concrete's storage and dispatch/return went to garbage. The concrete → `dyn Trait` unsize coercion must survive the physical passing mode. Two fixes, both reading the single FnAbi rather than re-deriving per path: - By-value `dyn Trait` parameter. `mir_emit_call_term`'s two indirect-aggregate spill branches (win64 byval-mask and the `internal_abi_needs_indirect_param` fallback) ran before the dyn fat-pointer build and short-circuited through the raw place pointer, passing `&Concrete` where the callee loads `{ptr, ptr}`. Extract `mir_build_dyn_arg_fat_value`, hoist the callee's dyn-parameter trait lookup above the byval branch, and when the parameter is a dyn trait, build the fat pointer and spill *that* to a temporary, passing the temporary's address. - sret dyn dispatch. `dyn_trait_method_fn_type` rebuilt the call type from raw sema types with no ABI lowering, so a `str`-returning method dispatched as by-value against a vtable wrapper whose real ABI is `void(sret, self)`. Apply `internal_abi_needs_sret` / `internal_abi_needs_indirect_param` to the reconstructed type, and have `mir_emit_dyn_trait_call` materialize the sret destination, pass it as arg 0, and shift the remaining parameter indices. Both predicates are false off win64, so host/mac codegen is unchanged — verified byte-identical linux IR, and `with build` + `:fixpoint` + `:drop-audit` + `:move-audit` stay green. Confirmed on Windows x86_64 hardware: `test/behavior/sealed_trait_match.w` prints `ok`, exit 0 (was empty output before).
…ters materialize (#806) The preceding commit makes win64 codegen materialize dyn-trait fat pointers across the indirect ABI, which fixes the non-async `match s: c: Circle => ... / r: Rect => ...` dispatch that sealed_trait_match exercises. KNOWN-RED (held): this same #806 fix regresses async dyn-trait dispatch — spec_ss11_5_dyn_async_trait_methods and spec_ss14_3_async_calling_is_unrestricted are green on main and fail with this fix. This PR stays red until the async path is fixed; see #80. It must NOT merge ahead of that fix.
…806) The #806 fat-pointer fix taught `dyn_trait_method_fn_type` to apply the native win64 ABI to vtable slots. That correctly sret-lowers an aggregate return >8B — but the `create_dyn_wrapper` vtable wrapper still built its signature and return from the pre-ABI shape, so for an async method (Task `{i32,ptr}`, 16B) the wrapper: - returned by value against a slot type that is now `void(sret, ...)`, shifting every argument by one, and - seeded the async Task aggregate from the sret-lowered `void` return, emitting `insertvalue void undef` — an LLVM verify error that aborted win64 codegen for any async dyn-trait program. Detect the sret lowering (async method whose `dyn_ft` returns void with one extra leading parameter), carry the sret slot as parameter 0, place self/args after it, reconstruct the real `{i32,ptr}` Task type for the spawn, and store the produced Task through the sret slot instead of returning it by value. The wrapper signature now matches the vtable slot and the dispatch call site (D6: one ABI, agreed at every reader). On SysV the 16B Task returns in registers (no sret), so `has_sret` is false and the wrapper is byte-identical to before — linux/mac and the sync sealed-trait path are untouched. Un-holds #817: `spec_ss11_5_dyn_async_trait_methods` and `spec_ss14_3_async_calling_is_unrestricted` now pass on win64.
ropoctl
force-pushed
the
windows-codegen-806
branch
from
August 17, 2026 20:18
7b433b7 to
ef8bd59
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 #816.
Makes win64 codegen materialize
dyn Traitfat pointers across the indirectABI, fixing trait-object dispatch that previously produced wrong output on
Windows. Two parts:
sealed_trait_match(non-asyncmatch s: c: Circle => ...dispatch).dyn_trait_method_fn_typeapplies the native win64ABI to vtable slots, which sret-lowers an aggregate return >8B. An async
Task is
{i32,ptr}(16B), so its slot becomesvoid(sret, ...). Thevtable wrapper (
create_dyn_wrapper) now carries that sret slot as itsleading parameter, reconstructs the real Task type for the coroutine
spawn, and stores the result through the sret slot — matching the vtable
slot and the dispatch call site (D6: one ABI, agreed at every reader).
Previously the wrapper seeded the Task aggregate from the sret-lowered
voidreturn (insertvalue void undef), an LLVM verify error thataborted win64 codegen for any async dyn-trait program.
On SysV the 16B Task returns in registers (no sret), so the async path is
byte-identical to before — linux/mac and the sync path are untouched.
Un-skips (now passing on win64):
sealed_trait_match,spec_ss11_5_dyn_async_trait_methods,spec_ss14_3_async_calling_is_unrestricted.