Skip to content

Provide ability to use CheckedContinuation when suspending for an async ObjC call #68390

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

xedin
Copy link
Contributor

@xedin xedin commented Sep 8, 2023

Builds on @kavon's PR - #41772

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}

Resolves: rdar://89930501

…handler generator

Instead of relying on `continuationType` for information, let's
take it from the source.
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`.
Copy link
Contributor

@ktoso ktoso left a comment

Choose a reason for hiding this comment

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

AFAICS looks good but not too clear on the objc bits :)

@xedin
Copy link
Contributor Author

xedin commented Sep 8, 2023

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 8, 2023

@swift-ci please test source compatibility release

@xedin
Copy link
Contributor Author

xedin commented Sep 8, 2023

Source compatibility suite failures are unrelated:

/Users/ec2-user/jenkins/workspace/swift-PR-source-compat-suite-macos/swift-source-compat-suite/project_cache/swift-foundation/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift:16:16: error: package import can only be used from a module with a package name; set it with the compiler flag -package-name
package import _RopeModule
               ^

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.

3 participants