Skip to content

[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

Merged
merged 9 commits into from
May 13, 2024

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented May 9, 2024

[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

@gottesmm
Copy link
Contributor Author

gottesmm commented May 9, 2024

@swift-ci smoke test

@gottesmm gottesmm enabled auto-merge May 9, 2024 23:35
gottesmm added 5 commits May 10, 2024 15:33
…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
@gottesmm gottesmm force-pushed the rdar127295657_127844737 branch from 82e26a5 to 085f3d7 Compare May 10, 2024 23:11
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

… a header.

This works around a layering violation where libSwiftBasic includes parts of the
AST even though it shouldn't.
@gottesmm
Copy link
Contributor Author

@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.
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

…ctor types.

I also added some docs to SIL.rst about sil_isolated as well.
@gottesmm
Copy link
Contributor Author

@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.
@gottesmm gottesmm disabled auto-merge May 13, 2024 05:15
@gottesmm
Copy link
Contributor Author

@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.
Copy link
Contributor

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?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cut off sentence?

Copy link
Contributor Author

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}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice diagnostic improvement :)

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