Skip to content

Add experimental feature to defer Sendable checking to SILGen #66994

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

Closed
wants to merge 1 commit into from

Conversation

JTurcotti
Copy link
Contributor

@JTurcotti JTurcotti commented Jun 28, 2023

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 in DeferredSendableDiagnostics - a class containing utilities for handling creation and accumulation that respects existing control flows - which are then placed in SendNonSendableExpr 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 with emit-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

@JTurcotti
Copy link
Contributor Author

@swift-ci please smoke test

@JTurcotti
Copy link
Contributor Author

@swift-ci please smoke test

…iagnostics from Sendable checking. Parts of TypeCheckConcurrency are refactored to defer these diagnostics, and tests are added to ensure the deferral happens as expected.
@JTurcotti
Copy link
Contributor Author

@swift-ci please smoke test

@JTurcotti JTurcotti changed the title [Draft] get the code in there Add experimental feature to defer Sendable checking to SILGen Jun 28, 2023
@JTurcotti
Copy link
Contributor Author

@swift-ci please smoke test

@JTurcotti
Copy link
Contributor Author

This approach scrapped - replaced by PR #67172

@JTurcotti JTurcotti closed this Jul 10, 2023
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.

1 participant