Skip to content

Distributed actor isolation #39558

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 12 commits into from
Oct 2, 2021

Conversation

DougGregor
Copy link
Member

@DougGregor DougGregor commented Oct 2, 2021

Clean up some aspects of checking distributed actor isolation rules:

  • Hopping to a global actor from a distributed-actor isolated context does not go through a distributed thunk (global actors can't have one).
  • "Unrestricted" declarations are always unrestricted, so we don't need an extra distributed check here (it won't ever occur).
  • Actor isolation computation doesn't need a special case for distributed; it marks too much, overriding (e.g.) global actor isolation.
  • Model @_distributedActorIndependent like nonisolated, simplifying away many special cases
  • Unify and simplify the checking when performing a cross-actor reference to an entity that is distributed-actor-isolated

Remove a few places where we are introducing extra distributed-related
actor isolation checking that either isn't necesssary or is incorrect.
Specifically:

* Hopping to a global actor *from* a distributed-actor isolated context
does not go through a distributed thunk (global actors can't have one).
* "Unrestricted" declarations are always unrestricted, so we don't
need an extra distributed check here (it won't ever occur).
* Actor isolation computation doesn't need a special case for
distributed; it marks too much, overriding (e.g.) global actor
isolation.

The primary semantic change visible here is that distributed actors
can now have truly 'nonisolated' members. They aren't required to be
'distributed' because they can't touch state anyway.
@@ -115,6 +114,9 @@ distributed actor DistributedActor_1 {
await self.distHelloAsync()
try self.distHelloThrows()
try await self.distHelloAsyncThrows()

// Hops over to the global actor.
_ = await DistributedActor_1.staticMainActorFunc()
Copy link
Contributor

Choose a reason for hiding this comment

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

Yay! Glad that just works, we'll need to double check if we reject distributed func getting a global actor -- I'm guessing that's nonsense hmmm

@@ -33,7 +31,7 @@ distributed actor DA {
// self is a distributed actor self is NOT isolated
_ = self.local // expected-error{{distributed actor-isolated property 'local' can only be referenced inside the distributed actor}}
_ = try await self.dist() // ok, was made implicitly throwing and async
_ = self.computedNonisolated // expected-error{{only 'distributed' functions can be called from outside the distributed actor}}
_ = self.computedNonisolated // it's okay, only the body of computedNonisolated is wrong
Copy link
Contributor

Choose a reason for hiding this comment

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

Uff, yes absolutely you're right on that

@ktoso ktoso added the distributed Feature → concurrency: distributed actor label Oct 2, 2021
The `@__distributedActorIndependent` attribute is effectively the same
as nonisolated, so start treating it that way by making actor-isolation
checking look for it specifically and conclude "nonisolated". Remove
various special cases for this attribute that don't need to exist.
This is an non-user-visible attribute that is semantically identical to
`nonisolated` except that it allows use in distributed actors. It is
only, and can only, be used for the two fields that distributed actors
have in both the local actor and in the remote proxy, "id" and
"actorTransport". So, special-case the "nonisolated" check for those
fields and stop using `@_distributedActorIndependent`.
All its uses have been subsumed into `nonisolated`.
ABIStableToAdd | ABIStableToRemove |
APIBreakingToAdd | APIBreakingToRemove,
119)
// 110 is unused
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo, 119 right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, whoops

@@ -385,20 +385,6 @@ ActorIsolationRestriction ActorIsolationRestriction::forDeclaration(
if (auto func = dyn_cast<AbstractFunctionDecl>(decl)) {
if (func->isAsyncContext())
isAccessibleAcrossActors = true;

// FIXME: move diagnosis out of this function entirely (!)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks a lot!


/// References to declarations that are part of a distributed actor are
/// only permitted if they are async.
CrossDistributedActorSelf, // FIXME(distributed): remove this case entirely rdar://83713366
Copy link
Contributor

Choose a reason for hiding this comment

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

Great to get rid of it too, yay

Unify the logic for checking and marking accesses as
async/throws/uses-distributed-thunk to reduce the overall amount of
code, clarify the isolated/local/potentially-remote cases, and
consistently set these options. There are tiny semantic improvements
here where, e.g., one can asynchronously use non-distributed
functions, properties, and subscripts if we're in a context where we
know the actor is not remote.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@calijoefornium
Copy link

@DougGregor @ktoso : can you merge my PR if possible #39536

Sorry for posting this here I have tried reaching all but dint found and solution

@ktoso ktoso merged commit 59311ba into swiftlang:main Oct 2, 2021
@DougGregor DougGregor deleted the distributed-actor-isolation branch October 2, 2021 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
distributed Feature → concurrency: distributed actor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants