Add experimental feature to defer Sendable checking to SILGen #66994
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.
Currently Sendable diagnostics such as
non-sendable type 'NonSendable' passed in call to actor-isolated instance method 'actorTakesNS' cannot cross actor boundary
are all produced during type checking. We want to add a SIL pass that uses flow-sensitive ownership analysis to determine that some of these diagnostic sites are actually safe (i.e. cannot yield data races), so the production of such diagnostics must be deferred to a SIL pass.This PR is an incremental step towards accomplishing that goal. Instead of being directly produced during type checking, a large class of sendable diagnostics (see the added test files in
swift/test/Concurrency/DeferredSendableChecking
for a characterization) are wrapped into closures that can be called later to produce the diagnostics. Those closures are wrapped inDeferredSendableDiagnostic
s - a class containing utilities for handling creation and accumulation that respects existing control flows - which are then placed inSendNonSendableExpr
AST nodes that are inserted at appropriate sites in the AST.SILGen responds to encountering these
SendNonSendableExpr
nodes by recursing to their subexpression, but calling their contained closure to emit the appropriate diagnostics before doing so.In particular, this PR defers diagnostics arising from passing Non-Sendable arguments to function calls that cross isolation domains. Others will come in future PRs.
swift/test/Concurrency/DeferredSendableChecking
contains two identical test files, except that one is run with-typecheck
and the other is run withemit-silgen
. The former produces no diagnostics, the latter produces all diagnostics.This behavior is guarded behind the
-enable-experimental-feature DeferredSendableChecking
flag.This PR supersedes #66929