Skip to content

Commit 7af3886

Browse files
committed
[Concurrency] Deprecate and obsolete AnyActor.
This marker protocol isn't useful for abstracting over actors and distributed actors because it doesn't have any runtime requirements, so there's no way to switch to the given actor. Instead, you should use `isolated (any Actor)?` parameters, and the compiler will compute a local actor value from a distributed actor using `DistributedActor.asLocalActor`.
1 parent 3c6918a commit 7af3886

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

stdlib/public/Concurrency/Actor.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import Swift
2828
/// impossible for one to refine the other.
2929
@_marker
3030
@available(SwiftStdlib 5.1, *)
31+
@available(*, deprecated, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
32+
@available(swift, obsoleted: 6.0, message: "Use 'any Actor' with 'DistributedActor.asLocalActor' instead")
3133
public protocol AnyActor: AnyObject, Sendable {}
3234

3335
/// Common protocol to which all actors conform.

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

0 commit comments

Comments
 (0)