Skip to content

[6.4.x] IRGen: fix async typed throws miscompiles on Wasm - #90761

Merged
MaxDesiatov merged 1 commit into
swiftlang:release/6.4.xfrom
MaxDesiatov:maxd/6.4.x-wasm-async-typed-throws
Jul 23, 2026
Merged

[6.4.x] IRGen: fix async typed throws miscompiles on Wasm#90761
MaxDesiatov merged 1 commit into
swiftlang:release/6.4.xfrom
MaxDesiatov:maxd/6.4.x-wasm-async-typed-throws

Conversation

@MaxDesiatov

@MaxDesiatov MaxDesiatov commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

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

# Conflicts:
#	test/Interpreter/async_typed_throws_wasm.swift

# Conflicts:
#	test/stdlib/Result+asyncInit.swift

# Conflicts:
#	test/stdlib/Result+asyncInit.swift
@MaxDesiatov MaxDesiatov changed the title IRGen: fix async typed throws miscompiles on Wasm [6.4.x] IRGen: fix async typed throws miscompiles on Wasm Jul 17, 2026
@MaxDesiatov

Copy link
Copy Markdown
Contributor Author

@swift-ci build toolchain

@MaxDesiatov

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@MaxDesiatov MaxDesiatov added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. async & await Feature → concurrency: asynchronous function aka the async/await pattern WebAssembly Platform: WebAssembly typed throws Feature → error handling → throws & rethrows: Typed throws swift 6.4 labels Jul 17, 2026
@MaxDesiatov MaxDesiatov moved this to In Progress in Swift for Wasm Jul 17, 2026
@MaxDesiatov
MaxDesiatov marked this pull request as ready for review July 21, 2026 13:22
@MaxDesiatov
MaxDesiatov requested a review from a team as a code owner July 21, 2026 13:22
@MaxDesiatov
MaxDesiatov merged commit 3491a7d into swiftlang:release/6.4.x Jul 23, 2026
9 checks passed
@MaxDesiatov
MaxDesiatov deleted the maxd/6.4.x-wasm-async-typed-throws branch July 23, 2026 16:26
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Swift for Wasm Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

async & await Feature → concurrency: asynchronous function aka the async/await pattern bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. swift 6.4 typed throws Feature → error handling → throws & rethrows: Typed throws WebAssembly Platform: WebAssembly

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants