[concurrency] Ensure that we treat closures that are nonisolated(nonsending) via their ActorIsolation as nonisolated(nonsending). #81338
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some notes:
In most cases, I think we were getting lucky with this by just inferring the closure's isolation from its decl context. In the specific case that we were looking at here, this was not true since we are returning from an @Concurrent async function a nonisolated(nonsending) method that closes over self. This occurs since even when NonisolatedNonsendingByDefault we want to start importing objc async functions as nonisolated(nonsending).
I also discovered that in the ActorIsolationChecker we were not visiting the inner autoclosure meaning that we never set the ActorIsolation field on the closure. After some discussion with @xedin about potentially visiting the function in the ActorIsolationChecker, we came to the conclusion that this was likely to result in source stability changes. So we put in a targeted fix just for autoclosures in this specific case by setting their actor isolation in the type checker. This ensures that when we import objc async functions we do the correct thing. We still will not do the correct thing if we are able to create an autoclosure like this that is main actor isolated.
Beyond adding tests to objc_async_from_swift to make sure that when NonisolatedNonsendingByDefault is disabled we do the right thing, I noticed that we did not have any tests that actually tested the behavior around objc_async_from_swift when NonisolatedNonsendingByDefault is enabled. So I added the relevant test lines so we can be sure that we get correct behavior in such a case.
rdar://150209093