Skip to content

[concurrency] Perform some fixes so that transfernonsendable_closureliterals_isolationinference.swift now passes. #82858

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 2 commits into from
Jul 8, 2025

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Jul 7, 2025

The reason why this failed is that concurrently to @xedin landing
79af04c, I enabled
NonisolatedNonsendingByDefault on a bunch of other tests. That change broke the
test and so we needed to fix it.

This commit fixes a few issues that were exposed:

  1. We do not propagate nonisolated(nonsending) into a closure if its inferred
    context isolation is global actor isolated or if the closure captures an
    isolated parameter. We previously just always inferred
    nonisolated(nonsending). Unfortunately since we do not yet have capture
    information in CSApply, this required us to put the isolation change into
    TypeCheckConcurrency.cpp and basically have function conversions of the form:
(function_conversion_expr type="nonisolated(nonsending) () async -> Void"
   (closure_expr type="() async -> ()" isolated_to_caller_isolation))

Notice how we have a function conversion to nonisolated(nonsending) from a
closure expr that has an isolation that is isolated_to_caller.

  1. With this in hand, we found that this pattern caused us to first thunk a
    nonisolated(nonsending) function to an @Concurrent function and then thunk that
    back to nonisolated(nonsending), causing the final function to always be
    concurrent. I put into SILGen a peephole that recognizes this pattern and emits
    the correct code.

  2. With that in hand, we found that we were emitting nonisolated(nonsending)
    parameters for inheritActorContext functions. This was then fixed by @xedin in

With all this in hand, closure literal isolation and all of the other RBI tests
with nonisolated(nonsending) enabled pass.

rdar://154969621

@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 7, 2025

@swift-ci smoke test

xedin and others added 2 commits July 7, 2025 17:21
…nt` on `@_inheritActorContext` parameters

`@_inheritActorContext` is a form of isolation which precludes
direct use of inference of `nonisolated(nonsending)` and `@concurrent`
just like other isolation attributes/modifiers would i.e. `isolated`
or `@isolated(any)`.
…iterals_isolationinference.swift now passes.

The reason why this failed is that concurrently to @xedin landing
79af04c, I enabled
NonisolatedNonsendingByDefault on a bunch of other tests. That change broke the
test and so we needed to fix it.

This commit fixes a few issues that were exposed:

1. We do not propagate nonisolated(nonsending) into a closure if its inferred
context isolation is global actor isolated or if the closure captures an
isolated parameter. We previously just always inferred
nonisolated(nonsending). Unfortunately since we do not yet have capture
information in CSApply, this required us to put the isolation change into
TypeCheckConcurrency.cpp and basically have function conversions of the form:

```
(function_conversion_expr type="nonisolated(nonsending) () async -> Void"
   (closure_expr type="() async -> ()" isolated_to_caller_isolation))
```

Notice how we have a function conversion to nonisolated(nonsending) from a
closure expr that has an isolation that is isolated_to_caller.

2. With this in hand, we found that this pattern caused us to first thunk a
nonisolated(nonsending) function to an @Concurrent function and then thunk that
back to nonisolated(nonsending), causing the final function to always be
concurrent. I put into SILGen a peephole that recognizes this pattern and emits
the correct code.

3. With that in hand, we found that we were emitting nonisolated(nonsending)
parameters for inheritActorContext functions. This was then fixed by @xedin in

With all this in hand, closure literal isolation and all of the other RBI tests
with nonisolated(nonsending) enabled pass.

rdar://154969621
@gottesmm
Copy link
Contributor Author

gottesmm commented Jul 8, 2025

@swift-ci smoke test

@xedin xedin merged commit 785e7b1 into swiftlang:main Jul 8, 2025
3 checks passed
@gottesmm gottesmm deleted the rdar154969621 branch July 8, 2025 07:26
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