[5.10][Concurrency] Suppress diagnostics about non-Sendable
async iterator arguments in implicit calls to next()
.
#70750
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.
#67730 closed a hole in strict concurrency checking that failed to diagnose non-
Sendable
self arguments crossing isolation boundaries. When that hole was closed, the compiler started diagnosing code that iterates over anAsyncSequence
type from an actor isolated context (including global actors):This is correct - nearly all
AsyncIteratorProtocol
types are notSendable
, andAsyncIteratorProtocol.next()
isnonisolated async
, so any call tonext()
from an actor-isolated context will pass a non-Sendable
iterator value over an isolation boundary! There's a whole big pitch discussion in Swift evolution right now about fixing this properly by makingnext()
polymorphic over actor isolation.However, in Swift 5.10, there's nothing that programmers can do to to resolve this warning. So instead, this change applies the
nonisolated(unsafe)
opt out to the generated iterator variable during constraint generation to suppress the warning. Note that I cherry picked the remainder of the implementation ofnonisolated(unsafe)
(most of the implementation had already been cherry picked) and enabled it in order to use this opt out. The feature has been accepted in Swift Evolution and enabled onmain
, and programmers will surely neednonisolated(unsafe)
in Swift 5.10 given the vast number ofSendable
checking holes that have been closed in Swift 5.10, leading to more warnings just like this one.Sendable
checking, andasync
iteration in particularnonisolated(unsafe)
does not impact other language features, and the only effect of applying it to async iterator variables is a suppressed warning under-strict-concurrency=complete
.-stict-concurrency=complete
.Sendable
async iterator arguments in implicit calls tonext()
. #70697