Skip to content

Commit 135e3f2

Browse files
authored
Merge pull request #73889 from hborla/deprecate-anyactor
[Concurrency] Deprecate `AnyActor`.
2 parents 6a19ca0 + c20b0e0 commit 135e3f2

File tree

17 files changed

+37
-60
lines changed

17 files changed

+37
-60
lines changed

include/swift/AST/KnownProtocols.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
BUILTIN_EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(name, "_" #name)
7878

7979
PROTOCOL(Actor)
80-
PROTOCOL(AnyActor)
8180
PROTOCOL(Sequence)
8281
PROTOCOL(Identifiable)
8382
PROTOCOL(IteratorProtocol)

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,6 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
13081308
M = getLoadedModule(Id_Differentiation);
13091309
break;
13101310
case KnownProtocolKind::Actor:
1311-
case KnownProtocolKind::AnyActor:
13121311
case KnownProtocolKind::GlobalActor:
13131312
case KnownProtocolKind::AsyncSequence:
13141313
case KnownProtocolKind::AsyncIteratorProtocol:

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6803,7 +6803,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
68036803
case KnownProtocolKind::Differentiable:
68046804
case KnownProtocolKind::FloatingPoint:
68056805
case KnownProtocolKind::Identifiable:
6806-
case KnownProtocolKind::AnyActor:
68076806
case KnownProtocolKind::Actor:
68086807
case KnownProtocolKind::DistributedActor:
68096808
case KnownProtocolKind::DistributedActorSystem:

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7019,10 +7019,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
70197019
auto genericSig = FTy->getInvocationGenericSignature();
70207020
auto &ctx = F.getASTContext();
70217021
auto *actorProtocol = ctx.getProtocol(KnownProtocolKind::Actor);
7022-
auto *anyActorProtocol = ctx.getProtocol(KnownProtocolKind::AnyActor);
7022+
auto *distributedProtocol = ctx.getProtocol(KnownProtocolKind::DistributedActor);
70237023
require(argType->isAnyActorType() ||
7024-
genericSig->requiresProtocol(argType, actorProtocol) ||
7025-
genericSig->requiresProtocol(argType, anyActorProtocol),
7024+
genericSig->requiresProtocol(argType, actorProtocol) ||
7025+
genericSig->requiresProtocol(argType, distributedProtocol),
70267026
"Only any actor types can be isolated");
70277027
require(!foundIsolatedParameter, "Two isolated parameters");
70287028
foundIsolatedParameter = true;

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static void checkInheritanceClause(
317317
continue;
318318

319319
// AnyObject is not allowed except on protocols.
320-
if (layout.hasExplicitAnyObject) {
320+
if (layout.hasExplicitAnyObject && !isa<ClassDecl>(decl)) {
321321
decl->diagnose(diag::inheritance_from_anyobject);
322322
continue;
323323
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6108,19 +6108,6 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
61086108
}
61096109
break;
61106110
}
6111-
case KnownProtocolKind::AnyActor: {
6112-
if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6113-
if (!classDecl->isExplicitActor() &&
6114-
!classDecl->isExplicitDistributedActor()) {
6115-
dc->getSelfNominalTypeDecl()
6116-
->diagnose(diag::actor_protocol_illegal_inheritance,
6117-
dc->getSelfNominalTypeDecl()->getName(),
6118-
proto->getName())
6119-
.fixItReplace(nominal->getStartLoc(), "actor");
6120-
}
6121-
}
6122-
break;
6123-
}
61246111
case KnownProtocolKind::UnsafeSendable: {
61256112
hasDeprecatedUnsafeSendable = true;
61266113
break;

stdlib/public/Concurrency/Actor.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ import Swift
2626
/// While both local and distributed actors are conceptually "actors", there are
2727
/// some important isolation model differences between the two, which make it
2828
/// impossible for one to refine the other.
29-
@_marker
3029
@available(SwiftStdlib 5.1, *)
31-
public protocol AnyActor: AnyObject, Sendable {}
30+
@available(*, deprecated, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
31+
@available(swift, obsoleted: 6.0, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
32+
public typealias AnyActor = AnyObject & Sendable
3233

3334
/// Common protocol to which all actors conform.
3435
///
3536
/// The `Actor` protocol generalizes over all `actor` types. Actor types
3637
/// implicitly conform to this protocol.
3738
@available(SwiftStdlib 5.1, *)
38-
public protocol Actor: AnyActor {
39+
public protocol Actor: AnyObject, Sendable {
3940

4041
/// Retrieve the executor for this actor as an optimized, unowned
4142
/// reference.

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ import _Concurrency
197197
/// - SeeAlso: ``Actor``
198198
/// - SeeAlso: ``AnyActor``
199199
@available(SwiftStdlib 5.7, *)
200-
public protocol DistributedActor: AnyActor, Identifiable, Hashable
200+
public protocol DistributedActor: AnyObject, Sendable, Identifiable, Hashable
201201
where ID == ActorSystem.ActorID,
202202
SerializationRequirement == ActorSystem.SerializationRequirement {
203203

stdlib/public/core/Sendable.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,14 @@
147147
///
148148
/// struct MyStructure: @unchecked Sendable { ... }
149149
@available(*, deprecated, message: "Use @unchecked Sendable instead")
150+
@available(swift, obsoleted: 6.0, message: "Use @unchecked Sendable instead")
150151
@_marker public protocol UnsafeSendable: Sendable { }
151152

152153
// Historical names
153154
@available(*, deprecated, renamed: "Sendable")
155+
@available(swift, obsoleted: 6.0, renamed: "Sendable")
154156
public typealias ConcurrentValue = Sendable
155157

156158
@available(*, deprecated, renamed: "Sendable")
159+
@available(swift, obsoleted: 6.0, renamed: "Sendable")
157160
public typealias UnsafeConcurrentValue = UnsafeSendable

test/Concurrency/actor_isolation.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,8 +1105,7 @@ actor A: Actor { // ok
11051105
@available(SwiftStdlib 5.1, *)
11061106
class C: Actor, UnsafeSendable {
11071107
// expected-error@-1{{non-actor type 'C' cannot conform to the 'Actor' protocol}}
1108-
// expected-error@-2{{non-actor type 'C' cannot conform to the 'AnyActor' protocol}}
1109-
// expected-warning@-3{{'UnsafeSendable' is deprecated: Use @unchecked Sendable instead}}
1108+
// expected-warning@-2{{'UnsafeSendable' is deprecated: Use @unchecked Sendable instead}}
11101109
nonisolated var unownedExecutor: UnownedSerialExecutor {
11111110
fatalError()
11121111
}

test/Concurrency/isolated_parameters.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ func isolated_generic_bad_2<T: Equatable>(_ t: isolated T) {}
356356
// expected-error@-1 {{'isolated' parameter type 'T' does not conform to 'Actor' or 'DistributedActor'}}
357357
func isolated_generic_bad_3<T: AnyActor>(_ t: isolated T) {}
358358
// expected-error@-1 {{'isolated' parameter type 'T' does not conform to 'Actor' or 'DistributedActor'}}
359+
// expected-warning@-2 {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
359360

360361
func isolated_generic_bad_4<T>(_ t: isolated Array<T>) {}
361362
// expected-error@-1 {{'isolated' parameter type 'Array<T>' does not conform to 'Actor' or 'DistributedActor'}}
@@ -475,7 +476,7 @@ nonisolated func fromNonisolated(ns: NotSendable) async -> NotSendable {
475476
await pass(value: ns, isolation: nil)
476477
}
477478

478-
func invalidIsolatedClosureParam<A: AnyActor> (
479+
func invalidIsolatedClosureParam<A: AnyActor> ( // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
479480
_: (isolated A) async throws -> Void // expected-error {{'isolated' parameter type 'A' does not conform to 'Actor' or 'DistributedActor'}}
480481
) {}
481482

test/Distributed/actor_protocols.swift

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,22 @@ typealias DefaultDistributedActorSystem = FakeActorSystem
1414
actor A: Actor {} // ok
1515

1616
class C: Actor, UnsafeSendable {
17-
// expected-error@-1{{non-actor type 'C' cannot conform to the 'AnyActor' protocol}} {{1-6=actor}}
18-
// expected-error@-2{{non-actor type 'C' cannot conform to the 'Actor' protocol}} {{1-6=actor}}
19-
// expected-warning@-3{{'UnsafeSendable' is deprecated: Use @unchecked Sendable instead}}
17+
// expected-error@-1{{non-actor type 'C' cannot conform to the 'Actor' protocol}} {{1-6=actor}}
18+
// expected-warning@-2{{'UnsafeSendable' is deprecated: Use @unchecked Sendable instead}}
2019
nonisolated var unownedExecutor: UnownedSerialExecutor {
2120
fatalError()
2221
}
2322
}
2423

2524
struct S: Actor {
26-
// expected-error@-1{{non-class type 'S' cannot conform to class protocol 'AnyActor'}}
27-
// expected-error@-2{{non-class type 'S' cannot conform to class protocol 'Actor'}}
25+
// expected-error@-1{{non-class type 'S' cannot conform to class protocol 'Actor'}}
2826
nonisolated var unownedExecutor: UnownedSerialExecutor {
2927
fatalError()
3028
}
3129
}
3230

3331
struct E: Actor {
34-
// expected-error@-1{{non-class type 'E' cannot conform to class protocol 'AnyActor'}}
35-
// expected-error@-2{{non-class type 'E' cannot conform to class protocol 'Actor'}}
32+
// expected-error@-1{{non-class type 'E' cannot conform to class protocol 'Actor'}}
3633
nonisolated var unownedExecutor: UnownedSerialExecutor {
3734
fatalError()
3835
}
@@ -65,8 +62,7 @@ actor A2: DistributedActor {
6562
}
6663

6764
final class DA2: DistributedActor {
68-
// expected-error@-1{{non-actor type 'DA2' cannot conform to the 'AnyActor' protocol}}
69-
// expected-error@-2{{non-distributed actor type 'DA2' cannot conform to the 'DistributedActor' protocol}}
65+
// expected-error@-1{{non-distributed actor type 'DA2' cannot conform to the 'DistributedActor' protocol}}
7066
nonisolated var id: ID {
7167
fatalError()
7268
}
@@ -87,23 +83,22 @@ final class DA2: DistributedActor {
8783

8884
struct S2: DistributedActor {
8985
// expected-error@-1{{non-class type 'S2' cannot conform to class protocol 'DistributedActor'}}
90-
// expected-error@-2{{non-class type 'S2' cannot conform to class protocol 'AnyActor'}}
91-
// expected-error@-3{{type 'S2' does not conform to protocol 'Identifiable'}}
86+
// expected-error@-2{{type 'S2' does not conform to protocol 'Identifiable'}}
9287
}
9388

9489
// ==== -----------------------------------------------------------------------
9590

96-
actor A3: AnyActor {} // ok
97-
distributed actor DA3: AnyActor {} // ok
91+
actor A3: AnyActor {} // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
92+
distributed actor DA3: AnyActor {} // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
9893

99-
class C3: AnyActor, @unchecked Sendable {
100-
// expected-error@-1{{non-actor type 'C3' cannot conform to the 'AnyActor' protocol}} {{1-6=actor}}
94+
class C3: AnyActor { // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
95+
// expected-warning@-1 {{non-final class 'C3' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
10196
}
10297

103-
struct S3: AnyActor {
104-
// expected-error@-1{{non-class type 'S3' cannot conform to class protocol 'AnyActor'}}
98+
struct S3: AnyActor { // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
99+
// expected-error@-1{{only protocols can inherit from 'AnyObject'}}
105100
}
106101

107-
enum E3: AnyActor {
108-
// expected-error@-1{{non-class type 'E3' cannot conform to class protocol 'AnyActor'}}
102+
enum E3: AnyActor { // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
103+
// expected-error@-1{{only protocols can inherit from 'AnyObject'}}
109104
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ Func _asyncLet_get(_:_:) has mangled name changing from '_Concurrency._asyncLet_
5858
Func _asyncLet_get(_:_:) has return type change from Builtin.RawPointer to ()
5959
Func _asyncLet_get_throwing(_:_:) has mangled name changing from '_Concurrency._asyncLet_get_throwing(Builtin.RawPointer, Builtin.RawPointer) async throws -> Builtin.RawPointer' to '_Concurrency._asyncLet_get_throwing(Builtin.RawPointer, Builtin.RawPointer) async throws -> ()'
6060
Func _asyncLet_get_throwing(_:_:) has return type change from Builtin.RawPointer to ()
61-
Protocol Actor has added inherited protocol AnyActor
6261
Protocol Actor has added inherited protocol Copyable
6362
Protocol Actor has added inherited protocol Escapable
64-
Protocol Actor has generic signature change from <Self : AnyObject, Self : Swift.Sendable> to <Self : _Concurrency.AnyActor>
6563
Protocol AsyncIteratorProtocol has generic signature change from to <Self.Failure : Swift.Error>
6664
Protocol AsyncIteratorProtocol has added inherited protocol Copyable
6765
Protocol AsyncIteratorProtocol has added inherited protocol Escapable

test/decl/class/actor/basic.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ actor MyActor { }
77
class MyActorSubclass1: MyActor { }
88
// expected-error@-1{{actor types do not support inheritance}}
99
// expected-error@-2{{type 'MyActorSubclass1' cannot conform to the 'Actor' protocol}}
10-
// expected-error@-3{{non-actor type 'MyActorSubclass1' cannot conform to the 'AnyActor' protocol}}
11-
// expected-warning@-4 {{non-final class 'MyActorSubclass1' cannot conform to 'Sendable'; use '@unchecked Sendable'; this is an error in the Swift 6 language mode}}
10+
// expected-warning@-3 {{non-final class 'MyActorSubclass1' cannot conform to 'Sendable'; use '@unchecked Sendable'; this is an error in the Swift 6 language mode}}
1211

1312
actor MyActorSubclass2: MyActor { } // expected-error{{actor types do not support inheritance}}
1413

test/decl/protocol/conforms/placement.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ extension ExplicitSub1 : P1 { } // expected-error{{redundant conformance of 'Exp
105105
// ---------------------------------------------------------------------------
106106
// Suppression of synthesized conformances
107107
// ---------------------------------------------------------------------------
108-
class SynthesizedClass1 : AnyObject { } // expected-error{{only protocols can inherit from 'AnyObject'}}
108+
class SynthesizedClass1 : AnyObject { }
109109

110110
class SynthesizedClass2 { }
111111
extension SynthesizedClass2 : AnyObject { } // expected-error{{only protocols can inherit from 'AnyObject'}}
@@ -115,7 +115,7 @@ class SynthesizedClass3 : AnyObjectRefinement { }
115115
class SynthesizedClass4 { }
116116
extension SynthesizedClass4 : AnyObjectRefinement { }
117117

118-
class SynthesizedSubClass1 : SynthesizedClass1, AnyObject { } // expected-error{{only protocols can inherit from 'AnyObject'}}
118+
class SynthesizedSubClass1 : SynthesizedClass1, AnyObject { }
119119

120120
class SynthesizedSubClass2 : SynthesizedClass2 { }
121121
extension SynthesizedSubClass2 : AnyObject { } // expected-error{{only protocols can inherit from 'AnyObject'}}

test/decl/protocol/special/Actor.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ actor A7 {
4444
@available(SwiftStdlib 5.1, *)
4545
class C1: Actor {
4646
// expected-error@-1{{non-actor type 'C1' cannot conform to the 'Actor' protocol}}
47-
// expected-error@-2{{non-actor type 'C1' cannot conform to the 'AnyActor' protocol}}
48-
// expected-warning@-3{{non-final class 'C1' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
47+
// expected-warning@-2{{non-final class 'C1' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
4948
nonisolated var unownedExecutor: UnownedSerialExecutor {
5049
fatalError("")
5150
}
@@ -54,8 +53,7 @@ class C1: Actor {
5453
@available(SwiftStdlib 5.1, *)
5554
class C2: Actor {
5655
// expected-error@-1{{non-actor type 'C2' cannot conform to the 'Actor' protocol}}
57-
// expected-error@-2{{non-actor type 'C2' cannot conform to the 'AnyActor' protocol}}
58-
// expected-warning@-3{{non-final class 'C2' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
56+
// expected-warning@-2{{non-final class 'C2' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
5957
// FIXME: this should be an isolation violation
6058
var unownedExecutor: UnownedSerialExecutor {
6159
fatalError("")
@@ -66,8 +64,7 @@ class C2: Actor {
6664
class C3: Actor {
6765
// expected-error@-1{{type 'C3' does not conform to protocol 'Actor'}}
6866
// expected-error@-2{{non-actor type 'C3' cannot conform to the 'Actor' protocol}}
69-
// expected-error@-3{{non-actor type 'C3' cannot conform to the 'AnyActor' protocol}}
70-
// expected-warning@-4{{non-final class 'C3' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
67+
// expected-warning@-3{{non-final class 'C3' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
7168
nonisolated func enqueue(_ job: UnownedJob) { }
7269
}
7370

test/decl/protocol/special/DistributedActor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ distributed actor D5: P1 {
6868

6969
// Make sure the conformances have been added implicitly.
7070
func acceptDistributedActor<Act: DistributedActor>(_: Act.Type) { }
71-
func acceptAnyActor<Act: AnyActor>(_: Act.Type) { }
71+
func acceptAnyActor<Act: AnyActor>(_: Act.Type) { } // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
7272

7373
func testConformance() {
7474
acceptDistributedActor(D1.self)
@@ -86,4 +86,4 @@ distributed actor A: P {
8686
distributed func foo() { }
8787
// expected-error@-1{{actor-isolated distributed instance method 'foo()' cannot be used to satisfy nonisolated protocol requirement}}
8888
}
89-
// ---
89+
// ---

0 commit comments

Comments
 (0)