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
[Concurrency] Introduce Actor protocol to which actor classes all conform #34111
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…form. Introduce a new Actor protocol, which is a class-bound protocol with only one requirement: func enqueue(partialTask: PartialAsyncTask) All actor classes implicitly conform to this protocol, and will synthesize a (currently empty) definition of `enqueue(partialTask:)` unless a suitable one is provided explicitly.
theblixguy
reviewed
Sep 29, 2020
When an actor class has its `enqueue(partialTask:)` implicitly synthesized, also synthesize a stored property for the actor's queue. The type of the property is defined by the _Concurrency library (`_DefaultActorQueue`), and it will be initialized with a call to `_defaultActorQueueCreate` (also provided by the _Concurrency library). Also synthesize the body of the implicitly-generated `enqueue(partialTask:)`, which will be a call to `_defaultActorQueueEnqueuePartialTask(actor:queue:partialTask:)`. Together, all of these allow us to experiment with the form of the queue and the queue operation without affecting the type checker. When `enqueue(partialTask:)` is not implicitly synthesized, the queue storage is not synthesized either. In such cases, the user has taken over the execution of tasks for the actor, rather than using the default implementation.
@swift-ci please smoke test |
…bles. Actor classes never have non-actor superclasses, so we can ensure that all actor classes have a common vtable prefix for the `enqueue(partialTask:)` operation. This allows us to treat all actor classes uniformly, without having to go through the Actor witness table every time.
…minator. For actor class's implementations of `enqueue(partialTask:)`, use a fixed ptrauth discriminator. Paired with the fixed vtable location, this allows one to invoke this operation on any native actor instance without knowing the specific type.
Actor-isolated operations must not be directly accessible from anywhere that is not already guaranteed to be running within the actor context. Prevent such operations from being `@objc`, because that would allow Objective-C code to violate actor isolation.
NSObject is guaranteed to have no state and no Swift vtable, and is necessary for Swift classes to implement the NSObject protocol. Allow it (and only it) as the superclass of an actor class, so that actor classes can be exposed to Objective-C.
@swift-ci please smoke test |
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Introduce a new
Actor
protocol, which is a class-bound protocol with onlyone requirement:
All actor classes implicitly conform to this protocol, and will synthesize
a definition of
enqueue(partialTask:)
along with storage for the runtimeto manager in the actor.
This design also lets us loosen the constraints on actors somewhat, so that
an actor class can be
@objc
and inherit directly fromNSObject
. Allow this,and tighten up
@objc
checking to maintain actor isolation across thelanguage boundary.