IRGen: fix async typed throws miscompiles on Wasm - #89715
Merged
Conversation
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 5, 2026 17:16
5ad9de1 to
259a442
Compare
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci smoke test macos |
Contributor
Author
|
@swift-ci smoke test linux |
This was referenced Jun 10, 2026
Draft
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 10, 2026 11:25
259a442 to
30755d4
Compare
Contributor
Author
|
@swift-ci smoke test |
Contributor
Author
|
@swift-ci test macos |
This was referenced Jun 11, 2026
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 11, 2026 18:29
30755d4 to
e5dc062
Compare
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci test windows |
Contributor
Author
|
@swift-ci test macos |
Contributor
Author
|
@swift-ci test windows |
1 similar comment
Contributor
Author
|
@swift-ci test windows |
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 15, 2026 14:31
866c136 to
9840b12
Compare
Contributor
Author
|
@swift-ci test |
MaxDesiatov
marked this pull request as ready for review
June 16, 2026 12:30
MaxDesiatov
marked this pull request as draft
June 16, 2026 12:30
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 16, 2026 12:43
9840b12 to
91ba7dd
Compare
Contributor
Author
|
@swift-ci smoke test |
MaxDesiatov
marked this pull request as ready for review
June 18, 2026 20:01
Contributor
Author
|
@swift-ci test |
Contributor
Author
|
@swift-ci build toolchain macos |
Contributor
Author
|
@swift-ci build toolchain linux |
Contributor
Author
|
@swift-ci test macos arm64 |
kateinoigakukun
approved these changes
Jun 28, 2026
MaxDesiatov
requested review from
hjyamauchi
and removed request for
aschwaighofer
June 28, 2026 10:48
drexin
approved these changes
Jun 30, 2026
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
June 30, 2026 22:35
c467db0 to
18dde8d
Compare
Contributor
Author
|
@swift-ci build toolchain |
Contributor
Author
|
@swift-ci test |
rjmccall
reviewed
Jul 1, 2026
rjmccall
reviewed
Jul 1, 2026
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
2 times, most recently
from
July 1, 2026 14:07
0fef043 to
ec662d8
Compare
Contributor
Author
|
@swift-ci build toolchain |
Contributor
Author
|
@swift-ci test |
rjmccall
reviewed
Jul 1, 2026
rjmccall
left a comment
Contributor
There was a problem hiding this comment.
Thanks, this looks good. My only remaining comment is that you keep talking about ind_error in the comments when this AFAIK doesn't actually refer to anything specific; probably best to just talk about the indirect error slot normally in prose.
# Conflicts: # test/Interpreter/async_typed_throws_wasm.swift # Conflicts: # test/stdlib/Result+asyncInit.swift
MaxDesiatov
force-pushed
the
maxd/wasm-async-typed-throws2
branch
from
July 5, 2026 20:43
ec662d8 to
5732641
Compare
Contributor
Author
|
@swift-ci test |
MaxDesiatov
added a commit
that referenced
this pull request
Jul 23, 2026
Cherry-pick of #89715, merged as 4c99082 **Explanation**: On wasm32 the WebAssembly backend pads the `swiftself` and `swifterror` parameters, which left the indirect typed-error pointer and the `swiftself`/context slot at different LLVM-IR positions for Thin versus Thick async callers; caller and callee then disagreed on which trailing pointer held the typed-error slot and miscompiled async typed-throws calls (#89155: `Result.init(catching:) async` trapped in a value-witness copy on Wasm). With this change `SignatureExpansion::expandAsyncEntryType` now emits `addIndirectThrowingResult` before the `swiftself`/context slot, so the trailing pair is always `[ind_error, swiftself]` and Thin and Thick agree on the position regardless of parameter padding. The result-shape decision moves behind one gate, `hasTrailingAsyncErrorContextPair` (`GenCall.h`), consumed by the three sites that read these slots positionally: `AsyncCallEmission::setFromCallee`, `AsyncPartialApplicationForwarderEmission`, and `AsyncNativeCCEntryPointArgumentEmission::mapAsyncParameters` (the last also pre-extracts the witness-method Self/witness-table that trail the pair). **Scope**: IRGen async typed-throws lowering only; while resulting LLVM IR has different ordering of parameters, non-Wasm native codegen is unchanged. **Risk**: Low. Non-Wasm codegen is unchanged (the reorder only moves IR operands; `swiftself`/`swifterror` stay register-pinned by attribute). The only calling-convention change is on Wasm, which was already miscompiling. **Testing**: New execution test reproduces #89155 on Wasm; IRGen tests updated to pin the new parameter order. **Issue**: #89320, rdar://177615931 **Reviewed by**: @drexin @kateinoigakukun @rjmccall
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.
Follow up to currently-reverted #89416.
On wasm32 the WebAssembly backend pads the
swiftselfandswifterrorparameters, which left the indirect typed-error pointer and theswiftself/context slot at different LLVM-IR positions for Thin versus Thick async callers; caller and callee then disagreed on which trailing pointer held the typed-error slot and miscompiled async typed-throws calls (#89155:Result.init(catching:) asynctrapped in a value-witness copy on Wasm).With this change
SignatureExpansion::expandAsyncEntryTypenow emitsaddIndirectThrowingResultbefore theswiftself/context slot, so the trailing pair is always[ind_error, swiftself]and Thin and Thick agree on the position regardless of parameter padding. The result-shape decision moves behind one gate,hasTrailingAsyncErrorContextPair(GenCall.h), consumed by the three sites that read these slots positionally:AsyncCallEmission::setFromCallee,AsyncPartialApplicationForwarderEmission, andAsyncNativeCCEntryPointArgumentEmission::mapAsyncParameters(the last also pre-extracts the witness-method Self/witness-table that trail the pair).Each consumer carries an assertion that fires if the gate ever diverges from the slots actually filled.
Fixes #89320.