Skip to content

[5.10] Provide ability to use CheckedContinuation when suspending for an async ObjC call #69139

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Oct 11, 2023

Cherry-pick of #68390


  • Explanation:

To provide enhanced debugging and runtime checking for the correct usage
of continuations passed in a call to ObjC from Swift, this PR introduces a flag
for the swift-frontend that uses a CheckedContinuation when calling an
async ObjC function from Swift. When enabled, the underlying block value
passed as a completion-handler is created using CheckedContinuation
instead of just an UnsafeContinuation, which was what was used previously.
The checked continuation ensures that the block is only invoked once.

As of now, the swift-frontend flag is -checked-async-objc-bridging={on, off}

xedin added 7 commits October 11, 2023 13:46
…handler generator

Instead of relying on `continuationType` for information, let's
take it from the source.

(cherry picked from commit a602531)
…to checked continuations

(cherry picked from commit b8fb94b)
… `CheckedContinuation`

(cherry picked from commit 6e48d44)
Because `CheckedContinuation` is not a @Frozen struct we have
to use `Any` to store it in @block_storage indirectly. If the
flag is enabled, we'd emit a block storage with `Any` and
initialize the existential with stack allocated `CheckedContinuation`
formed from `UnsafeContinuation`. Inside of the completion handler
`Any` is going to be projected and cast back to `CheckedContinuation`.

(cherry picked from commit 4b22620)
…t's using async continuations

(cherry picked from commit 7d6c4b7)
…king continuations mode

(cherry picked from commit 6ecbb08)
@xedin xedin added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.10 labels Oct 11, 2023
@xedin xedin requested a review from hborla October 11, 2023 20:51
@xedin xedin requested a review from a team as a code owner October 11, 2023 20:51
@xedin
Copy link
Contributor Author

xedin commented Oct 11, 2023

@swift-ci please test

@xedin xedin merged commit 580213b into swiftlang:release/5.10 Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.10
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants