-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[region-isolation] When inferring isolation for an argument, handle non-self isolated parameters as well as self parameters that are actor isolated. #73556
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
Conversation
@swift-ci smoke test |
…e next commit. Specifically, I added a few helper methods and improved the logging printing. This all makes the next commit a more focused commit.
…on-self isolated parameters as well as self parameters that are actor isolated. As part of this I went through how we handled inference and rather than using a grab-bag getActorIsolation that was confusing to use, I created split APIs for specific use cases (actor instance, global actor, just an apply expr crossing) that makes it clearer inside the SILIsolationInfo::get* APIs what we are actually trying to model. I found a few issues as a result and fixed most of them if they were small. I also fixed one bigger one around computed property initializers in the next commit. There is a larger change I didn't fix around allowing function ref/partial_apply with isolated self parameters have a delayed flow sensitive actor isolation... this will be fixed in a subsequent commit. This also fixes a bunch of cases where we were printing actor-isolated instead of 'self' isolated. rdar://127295657
rdar://127844737
…use when printing SIL instructions.
82e26a5
to
085f3d7
Compare
@swift-ci smoke test |
… a header. This works around a layering violation where libSwiftBasic includes parts of the AST even though it shouldn't.
@swift-ci smoke test |
…g isolation of a sil_isolated parameter. It is unnecessary and seems to be slightly out of sync sometimes around closures.
@swift-ci smoke test |
…ctor types. I also added some docs to SIL.rst about sil_isolated as well.
@swift-ci smoke test |
The specific problem was that the AST was looking for Actor/AnyActor in _Concurrency... but I named the module of the test borrowing (for some reason). So the machinery was failing to think that my stubbed out protocols where the true known protocols. By changing the module name to _Concurrency, everything worked out.
@swift-ci smoke test |
``@sil_isolated``. An ``@sil_isolated`` parameter must be one of: | ||
|
||
- An actor or any actor type. | ||
- A generic type that conforms to Actor or AnyActor. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnyActor being a marker protocol, I am wondering if this means Actor or DistributedActor in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. What is important is that both have the semantics of Actors (namely they can create isolation).
@@ -122,18 +181,29 @@ class SILIsolationInfo { | |||
|
|||
/// If set this is the SILValue that represents the actor instance that we | |||
/// derived isolatedValue from. | |||
SILValue actorInstance; | |||
/// | |||
/// If set to (SILValue(), 1), then we are in an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cut off sentence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll fix this in a follow on commit.
@@ -97,7 +97,7 @@ public actor MyActor: MyProto { | |||
func g(ns1: NS1) async { | |||
await nonisolatedAsyncFunc1(ns1) // expected-targeted-and-complete-warning{{passing argument of non-sendable type 'NS1' outside of actor-isolated context may introduce data races}} | |||
// expected-tns-warning @-1 {{sending 'ns1' risks causing data races}} | |||
// expected-tns-note @-2 {{sending actor-isolated 'ns1' to nonisolated global function 'nonisolatedAsyncFunc1' risks causing data races between nonisolated and actor-isolated uses}} | |||
// expected-tns-note @-2 {{sending 'self'-isolated 'ns1' to nonisolated global function 'nonisolatedAsyncFunc1' risks causing data races between nonisolated and 'self'-isolated uses}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice diagnostic improvement :)
[region-isolation] When inferring isolation for an argument, handle non-self isolated parameters as well as self parameters that are actor isolated.
As part of this I went through how we handled inference and rather than using a
grab-bag getActorIsolation that was confusing to use, I created split APIs for
specific use cases (actor instance, global actor, just an apply expr crossing)
that makes it clearer inside the SILIsolationInfo::get* APIs what we are
actually trying to model. I found a few issues as a result and fixed most of
them if they were small. I also fixed one bigger one around computed property
initializers in the next commit. There is a larger change I didn't fix around allowing function
ref/partial_apply with isolated self parameters have a delayed flow sensitive
actor isolation... this will be fixed in a subsequent commit.
This also fixes a bunch of cases where we were printing actor-isolated instead
of 'self' isolated.
rdar://127295657
NOTE: The third commit is the commit that fixes inferred isolation in property initializers in actors.
rdar://127844737