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
}

0 commit comments

Comments
 (0)