Skip to content

SILGen support for throwing indirect errors #69529

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
merged 3 commits into from
Nov 1, 2023

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Oct 31, 2023

In a typed throws world, the thrown error type might be address-only. In this case we return it via the new @error_indirect convention. The type lowering and SILGen prolog generation for this was previously landed in #69430. This PR makes throw and try call(...) work.

Throwing is handled with a new throw_addr instruction; instead of taking an operand it assumes the indirect error result was initialized already.

If the callee has an indirect error result, try_apply takes a temporary allocation to use as the indirect error result. Then, instead of the thrown error being an argument to the error basic block, we instead assume the indirect error result is live in the error block.

Note that do {} catch {} doesn't work with indirect errors yet.

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

Copy link
Contributor

@eeckstein eeckstein left a comment

Choose a reason for hiding this comment

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

lgtm!

docs/SIL.rst Outdated
// indirect error result must be initialized at this point

Exits the current function and returns control to the calling
function. The current function must have an ndirect error result,
Copy link
Contributor

Choose a reason for hiding this comment

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

... indirect ...

@slavapestov slavapestov changed the title SIL: Introduce ThrowAddrInst SILGen support for throwing indirect errors Oct 31, 2023
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov slavapestov merged commit 05271d3 into swiftlang:main Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants