Skip to content

Commit 033b8bf

Browse files
authored
Merge pull request #41722 from ktoso/wip-move-anyactor
2 parents db63c21 + 369f3e6 commit 033b8bf

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-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
}

test/api-digester/stability-concurrency-abi.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@ Func AsyncSequence.map(_:) is now with @preconcurrency
5858
Func AsyncSequence.prefix(while:) is now with @preconcurrency
5959
Func MainActor.run(resultType:body:) has generic signature change from <T where T : Swift.Sendable> to <T>
6060
Func MainActor.run(resultType:body:) has mangled name changing from 'static Swift.MainActor.run<A where A: Swift.Sendable>(resultType: A.Type, body: @Swift.MainActor @Sendable () throws -> A) async throws -> A' to 'static Swift.MainActor.run<A>(resultType: A.Type, body: @Swift.MainActor @Sendable () throws -> A) async throws -> A'
61+
Protocol Actor has added inherited protocol AnyActor
62+
Protocol Actor has generic signature change from <Self : AnyObject, Self : Swift.Sendable> to <Self : _Concurrency.AnyActor>
6163
Struct CheckedContinuation has removed conformance to UnsafeSendable
6264
// *** DO NOT DISABLE OR XFAIL THIS TEST. *** (See comment above.)

0 commit comments

Comments
 (0)