Skip to content

Commit c20b0e0

Browse files
committed
[Concurrency] Obsolete AnyActor in Swift 6 using a typealias.
1 parent 1011e4d commit c20b0e0

File tree

14 files changed

+25
-53
lines changed

14 files changed

+25
-53
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
@@ -7016,10 +7016,10 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
70167016
auto genericSig = FTy->getInvocationGenericSignature();
70177017
auto &ctx = F.getASTContext();
70187018
auto *actorProtocol = ctx.getProtocol(KnownProtocolKind::Actor);
7019-
auto *anyActorProtocol = ctx.getProtocol(KnownProtocolKind::AnyActor);
7019+
auto *distributedProtocol = ctx.getProtocol(KnownProtocolKind::DistributedActor);
70207020
require(argType->isAnyActorType() ||
7021-
genericSig->requiresProtocol(argType, actorProtocol) ||
7022-
genericSig->requiresProtocol(argType, anyActorProtocol),
7021+
genericSig->requiresProtocol(argType, actorProtocol) ||
7022+
genericSig->requiresProtocol(argType, distributedProtocol),
70237023
"Only any actor types can be isolated");
70247024
require(!foundIsolatedParameter, "Two isolated parameters");
70257025
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
@@ -6094,19 +6094,6 @@ void TypeChecker::checkConformancesInContext(IterableDeclContext *idc) {
60946094
}
60956095
break;
60966096
}
6097-
case KnownProtocolKind::AnyActor: {
6098-
if (auto classDecl = dyn_cast<ClassDecl>(nominal)) {
6099-
if (!classDecl->isExplicitActor() &&
6100-
!classDecl->isExplicitDistributedActor()) {
6101-
dc->getSelfNominalTypeDecl()
6102-
->diagnose(diag::actor_protocol_illegal_inheritance,
6103-
dc->getSelfNominalTypeDecl()->getName(),
6104-
proto->getName())
6105-
.fixItReplace(nominal->getStartLoc(), "actor");
6106-
}
6107-
}
6108-
break;
6109-
}
61106097
case KnownProtocolKind::UnsafeSendable: {
61116098
hasDeprecatedUnsafeSendable = true;
61126099
break;

stdlib/public/Concurrency/Actor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +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, *)
3130
@available(*, deprecated, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
32-
public protocol AnyActor: AnyObject, Sendable {}
31+
@available(swift, obsoleted: 6.0, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
32+
public typealias AnyActor = AnyObject & Sendable
3333

3434
/// Common protocol to which all actors conform.
3535
///
3636
/// The `Actor` protocol generalizes over all `actor` types. Actor types
3737
/// implicitly conform to this protocol.
3838
@available(SwiftStdlib 5.1, *)
39-
public protocol Actor: AnyActor {
39+
public protocol Actor: AnyObject, Sendable {
4040

4141
/// Retrieve the executor for this actor as an optimized, unowned
4242
/// 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

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/Distributed/actor_protocols.swift

Lines changed: 10 additions & 15 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

9691
actor A3: AnyActor {} // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
9792
distributed actor DA3: AnyActor {} // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
9893

99-
class C3: AnyActor, @unchecked Sendable { // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
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

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

107102
enum E3: AnyActor { // expected-warning {{'AnyActor' is deprecated: Use 'any Actor' with 'DistributedActor.asLocalActor' instead}}
108-
// expected-error@-1{{non-class type 'E3' cannot conform to class protocol 'AnyActor'}}
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

0 commit comments

Comments
 (0)