Skip to content

Commit 040a4a3

Browse files
committed
[Concurrency][Distributed] Move AnyActor to Concurrency module
1 parent e25b822 commit 040a4a3

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

stdlib/public/Concurrency/Actor.swift

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2020 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2020-2022 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -13,12 +13,29 @@
1313
import Swift
1414
@_implementationOnly import _SwiftConcurrencyShims
1515

16+
/// Common marker protocol providing a shared "base" for both (local) `Actor`
17+
/// and (potentially remote) `DistributedActor` types.
18+
///
19+
/// The `AnyActor` marker protocol generalizes over all actor types, including
20+
/// distributed ones. In practice, this protocol can be used to restrict
21+
/// protocols, or generic parameters to only be usable with actors, which
22+
/// provides the guarantee that calls may be safely made on instances of given
23+
/// type without worrying about the thread-safety of it -- as they are
24+
/// guaranteed to follow the actor-style isolation semantics.
25+
///
26+
/// While both local and distributed actors are conceptually "actors", there are
27+
/// some important isolation model differences between the two, which make it
28+
/// impossible for one to refine the other.
29+
@_marker
30+
@available(SwiftStdlib 5.1, *)
31+
public protocol AnyActor: AnyObject, Sendable {}
32+
1633
/// Common protocol to which all actors conform.
1734
///
18-
/// The `Actor` protocol generalizes over all actor types. Actor types
35+
/// The `Actor` protocol generalizes over all `actor` types. Actor types
1936
/// implicitly conform to this protocol.
2037
@available(SwiftStdlib 5.1, *)
21-
public protocol Actor: AnyObject, Sendable {
38+
public protocol Actor: AnyActor, Sendable {
2239

2340
/// Retrieve the executor for this actor as an optimized, unowned
2441
/// reference.

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,6 @@
1313
import Swift
1414
import _Concurrency
1515

16-
// ==== Any Actor -------------------------------------------------------------
17-
18-
/// Shared "base" protocol for both (local) `Actor` and (potentially remote)
19-
/// `DistributedActor`.
20-
///
21-
/// FIXME(distributed): We'd need Actor to also conform to this, but don't want to add that conformance in _Concurrency yet.
22-
@_marker
23-
@available(SwiftStdlib 5.7, *)
24-
public protocol AnyActor: Sendable, AnyObject {
25-
}
26-
2716
// ==== Distributed Actor -----------------------------------------------------
2817

2918
/// Common protocol to which all distributed actors conform implicitly.

test/Distributed/actor_protocols.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ class C: Actor, UnsafeSendable {
2222
}
2323

2424
struct S: Actor {
25-
// expected-error@-1{{non-class type 'S' cannot conform to class protocol 'Actor'}}
25+
// expected-error@-1{{non-class type 'S' cannot conform to class protocol 'AnyActor'}}
26+
// expected-error@-2{{non-class type 'S' cannot conform to class protocol 'Actor'}}
2627
nonisolated var unownedExecutor: UnownedSerialExecutor {
2728
fatalError()
2829
}
2930
}
3031

3132
struct E: Actor {
32-
// expected-error@-1{{non-class type 'E' cannot conform to class protocol 'Actor'}}
33+
// expected-error@-1{{non-class type 'E' cannot conform to class protocol 'AnyActor'}}
34+
// expected-error@-2{{non-class type 'E' cannot conform to class protocol 'Actor'}}
3335
nonisolated var unownedExecutor: UnownedSerialExecutor {
3436
fatalError()
3537
}

0 commit comments

Comments
 (0)