Skip to content

[SILGen] Create thunks for non-throwing -> indirect error result conversions #73162

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Apr 20, 2024

When a non-throwing function is passed to a function that expects a throwing function with an indirect error result, we need to create a thunk because the indirect error result pointer is passed as an extra trailing parameter. Extra trailing parameters except for swifterror and swiftself are not allowed on some platforms like WebAssembly, so they need to be called as exactly the same function signature.

func passThrough<X>(_ c: () throws(X) -> Void) throws(X) {
  try c()
}
func neverThrow() {}
passThrough(neverThrow)

This patch repairs WebAssembly CI failure. It has been failing since the recent typed-throws introduction in Optional.map.

…ersions

When a non-throwing function is passed to a function that expects a
throwing function with an indirect error result, we need to create a
thunk because the indirect error result pointer is passed as an extra
trailing parameter. Extra trailing parameters except for `swifterror`
and `swiftself` are not allowed on some platforms like WebAssembly, so
they need to be called as exactly the same function signature.

```swift
func passThrough<X>(_ c: () throws(X) -> Void) throws(X) {
  try c()
}
func neverThrow() {}
passThrough(neverThrow)
```
@kateinoigakukun
Copy link
Member Author

@swift-ci test

@kateinoigakukun
Copy link
Member Author

@swift-ci test WebAssembly

@kateinoigakukun kateinoigakukun added SILGen Area → compiler: The SIL generation stage WebAssembly Platform: WebAssembly typed throws Feature → error handling → throws & rethrows: Typed throws labels Apr 20, 2024
@kateinoigakukun kateinoigakukun marked this pull request as ready for review April 22, 2024 05:58
@MaxDesiatov MaxDesiatov added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Apr 22, 2024
Copy link
Member

@DougGregor DougGregor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this!

@eeckstein
Copy link
Contributor

Tracked by rdar://128028703

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. SILGen Area → compiler: The SIL generation stage typed throws Feature → error handling → throws & rethrows: Typed throws WebAssembly Platform: WebAssembly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants