Repository navigation
codegen(win64): sret-lower dyn-trait wrappers for sync aggregate returns (#806) - #820
Merged
Merged
Conversation
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 17, 2026 23:03
bcd7c3a to
140385c
Compare
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 17, 2026 23:19
140385c to
a45fb75
Compare
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 18, 2026 00:14
a45fb75 to
f7b1a5a
Compare
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 18, 2026 01:16
f7b1a5a to
bb90f38
Compare
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 18, 2026 02:24
bb90f38 to
b726643
Compare
…rns (#806) A vtable wrapper for a trait method whose return is a >8B aggregate was built to return by value unless the method was async, while the dyn call site (`mir_emit_dyn_trait_call`) always reconstructs the slot type with `dyn_trait_method_fn_type`, which applies the win64 native ABI and sret- lowers such a return (void ret + leading sret pointer). So a sync method like `Error.source() -> Option[&dyn Error]` (a 24-byte `{i32,{ptr,ptr}}`) got a by-value wrapper `{i32,{ptr,ptr}} @__dynwrap_..._source(ptr self)` against a caller emitting `call void %slot(ptr sret, ptr self)`: the wrapper reads the sret pointer as self and corrupts the frame — the exact caller/callee ABI divergence D6 forbids. Fix: the three vtable-build sites now read the same `dyn_trait_method_fn_type` descriptor the call site reads, so producer and consumer agree, and `create_dyn_wrapper` detects the sret slot structurally (void return with one extra leading param vs the real method) so it fires for sync aggregate returns, not only async Task. A method whose signature mentions Self (e.g. `Ord.cmp`, never dynamically dispatchable) can't be lowered by `dyn_trait_method_fn_type`; a new `report_errors=false` variant lets those slots fall back to the real method's by-value type as a placeholder without failing the whole compilation.
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.
ropoctl
force-pushed
the
windows-806-error-trait
branch
from
August 18, 2026 02:58
b726643 to
21b0a91
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.
#806 — win64 dyn-trait sret ABI for sync aggregate returns
&dyn Error.source()returnsOption[&dyn Error]— a 24-byte fat aggregate{ i32, { ptr, ptr } }. On win64 an aggregate larger than 8 bytes is returnedvia an implicit sret pointer, so the call site emits
call void %slot(ptr %sret, ptr %self). But the vtable wrapper__dynwrap_ParseError_sourcewas built from a second, independent ABIderivation that returned the aggregate by value (
{i32,{ptr,ptr}} @wrap(ptr %self)).Producer and consumer disagreed: the wrapper read the caller's sret pointer as
self→ stack-frame corruption → the program produced no output and exited 0.This is the same D6 class as the dispatch-vs-vtable divergence: one function
signature must have exactly one ABI descriptor.
Fix
All three vtable-build sites in
CodegenTraits.wnow read the samedyn_trait_method_fn_typedescriptor that the call site(
mir_emit_dyn_trait_call) reads, so producer and consumer agree byconstruction.
create_dyn_wrapperdetects sret structurally(
ret_ty == void && dyn_param_count == orig_param_count + 1) instead of gatingon the async flag, so a sync fat-aggregate return is sret-lowered too.
A
report_errors=falsevariant of the descriptor lets a non-dispatchable slot(one whose signature mentions
Self, e.g.Ord.cmp) fall back to the realmethod's by-value type without failing compilation — matching the prior
tolerant behavior for those slots.
Verification
Cross-built each affected test to win64 and ran under wine:
spec_ss10_8_error_trait→ok(was: no output, exit 1)dyn_source_is_none(&dyn Error)repro → correctobject_safety,box_dyn(16Bstraggregate, also sret-lowered now),implicit_trait_object_coercion,dyn_async_trait_methods.Instruction-level: the wrapper went from
define {i32,{ptr,ptr}} @__dynwrap_ParseError_source(ptr %0)todefine void @__dynwrap_ParseError_source(ptr %0, ptr %1), matching the callercall void %6(ptr %1, ptr %3).Un-skips
spec_ss10_8_error_trait.