Skip to content

[Distributed] fix all distributed *runtime* tests; they are currently not running on CI #38502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions stdlib/public/Distributed/DistributedActor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,16 @@ extension DistributedActor {
public protocol ActorIdentity: Sendable, Hashable, Codable {}

@available(SwiftStdlib 5.5, *)
public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable, CustomStringConvertible {
@usableFromInline let _hashInto: (inout Hasher) -> ()
@usableFromInline let _equalTo: (Any) -> Bool
@usableFromInline let _encodeTo: (Encoder) throws -> ()
@usableFromInline let _description: () -> String

public init<ID>(_ identity: ID) where ID: ActorIdentity {
_hashInto = { hasher in identity.hash(into: &hasher) }
_hashInto = { hasher in identity
.hash(into: &hasher)
}
_equalTo = { other in
guard let rhs = other as? ID else {
return false
Expand All @@ -142,6 +145,9 @@ public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
_encodeTo = { encoder in
try identity.encode(to: encoder)
}
_description = { () in
"\(identity)"
}
}

public init(from decoder: Decoder) throws {
Expand All @@ -158,6 +164,10 @@ public struct AnyActorIdentity: ActorIdentity, @unchecked Sendable {
try _encodeTo(encoder)
}

public var description: String {
"\(Self.self)(\(self._description()))"
}

public func hash(into hasher: inout Hasher) {
_hashInto(&hasher)
}
Expand Down
22 changes: 11 additions & 11 deletions test/Distributed/Runtime/distributed_actor_deinit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// REQUIRES: radar78290608
// REQUIRES: rdar78290608

import _Distributed

Expand Down Expand Up @@ -97,27 +97,27 @@ func test() {

_ = DA(transport: transport)
// CHECK: assign type:DA, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.DA, address:[[ADDRESS]]
// CHECK: resign address:[[ADDRESS]]
// CHECK: ready actor:main.DA, address:AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))

_ = DA_userDefined(transport: transport)
// CHECK: assign type:DA_userDefined, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.DA_userDefined, address:[[ADDRESS]]
// CHECK: resign address:[[ADDRESS]]
// CHECK: ready actor:main.DA_userDefined, address:AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))

// resign must happen as the _last thing_ after user-deinit completed
_ = DA_userDefined2(transport: transport)
// CHECK: assign type:DA_userDefined2, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.DA_userDefined2, address:[[ADDRESS]]
// CHECK: Deinitializing [[ADDRESS]]
// CHECK-NEXT: resign address:[[ADDRESS]]
// CHECK: ready actor:main.DA_userDefined2, address:AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK: Deinitializing AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK-NEXT: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))

// resign must happen as the _last thing_ after user-deinit completed
_ = DA_state(transport: transport)
// CHECK: assign type:DA_state, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.DA_state, address:[[ADDRESS]]
// CHECK: Deinitializing [[ADDRESS]]
// CHECK-NEXT: resign address:[[ADDRESS]]
// CHECK: ready actor:main.DA_state, address:AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK: Deinitializing AnyActorIdentity(ActorAddress(address: "xxx"))
// CHECK-NEXT: resign address:AnyActorIdentity(ActorAddress(address: "xxx"))

// a remote actor should not resign it's address, it was never "assigned" it
print("before")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// REQUIRES: radar78290608
// REQUIRES: rdar78290608

import _Distributed

Expand Down Expand Up @@ -39,6 +39,7 @@ extension LocalWorker {

// ==== Fake Transport ---------------------------------------------------------


@available(SwiftStdlib 5.5, *)
struct ActorAddress: ActorIdentity {
let address: String
Expand All @@ -49,29 +50,29 @@ struct ActorAddress: ActorIdentity {

@available(SwiftStdlib 5.5, *)
struct FakeTransport: ActorTransport {
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
throws -> ActorResolved<Act> where Act: DistributedActor {
fatalError()
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
fatalError("not implemented:\(#function)")
}

func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
throws -> ActorResolved<Act>
where Act: DistributedActor {
.makeProxy
}

func assignIdentity<Act>(
_ actorType: Act.Type
) -> ActorAddress where Act : DistributedActor {
let address = ActorAddress(parse: "xxx")
print("assign type:\(actorType), address:\(address)")
return address
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
let id = ActorAddress(parse: "xxx")
print("assign type:\(actorType), id:\(id)")
return .init(id)
}

public func actorReady<Act>(
_ actor: Act
) where Act: DistributedActor {
print("ready actor:\(actor), address:\(actor.id)")
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
print("ready actor:\(actor), id:\(actor.id)")
}

public func resignIdentity(
_ address: ActorAddress
) {
print("ready address:\(address)")
func resignIdentity(_ id: AnyActorIdentity) {
print("ready id:\(id)")
}
}

Expand All @@ -84,8 +85,8 @@ func test_local() async throws {
let worker = LocalWorker(transport: transport)
let x = try await worker.function()
print("call: \(x)")
// CHECK: assign type:LocalWorker, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.LocalWorker, address:[[ADDRESS]]
// CHECK: assign type:LocalWorker, id:[[ADDRESS:.*]]
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity([[ADDRESS]])
// CHECK: call: local:
}

Expand All @@ -94,7 +95,7 @@ func test_remote() async throws {
let address = ActorAddress(parse: "")
let transport = FakeTransport()

let worker = try LocalWorker(resolve: address, using: transport)
let worker = try LocalWorker(resolve: .init(address), using: transport)
let x = try await worker.function()
print("call: \(x)")
// CHECK: call: _cluster_remote_function():
Expand Down
40 changes: 20 additions & 20 deletions test/Distributed/Runtime/distributed_actor_init_local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// REQUIRES: radar78290608
// REQUIRES: rdar78290608

import _Distributed

Expand All @@ -28,29 +28,29 @@ struct ActorAddress: ActorIdentity {

@available(SwiftStdlib 5.5, *)
struct FakeTransport: ActorTransport {
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
throws -> ActorResolved<Act> where Act: DistributedActor {
fatalError()
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
fatalError("not implemented:\(#function)")
}

func assignIdentity<Act>(
_ actorType: Act.Type
) -> ActorAddress where Act : DistributedActor {
let address = ActorAddress(parse: "xxx")
print("assign type:\(actorType), address:\(address)")
return address
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
throws -> ActorResolved<Act>
where Act: DistributedActor {
fatalError("not implemented:\(#function)")
}

public func actorReady<Act>(
_ actor: Act
) where Act: DistributedActor {
print("ready actor:\(actor), address:\(actor.id)")
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
let id = ActorAddress(parse: "xxx")
print("assign type:\(actorType), id:\(id)")
return .init(id)
}

public func resignIdentity(
_ address: ActorAddress
) {
print("ready address:\(address)")
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
print("ready actor:\(actor), id:\(actor.id)")
}

func resignIdentity(_ id: AnyActorIdentity) {
print("ready id:\(id)")
}
}

Expand All @@ -61,8 +61,8 @@ func test() {
let transport = FakeTransport()

_ = LocalWorker(transport: transport)
// CHECK: assign type:LocalWorker, address:[[ADDRESS:.*]]
// CHECK: ready actor:main.LocalWorker, address:[[ADDRESS]]
// CHECK: assign type:LocalWorker, id:[[ID:.*]]
// CHECK: ready actor:main.LocalWorker, id:AnyActorIdentity([[ID]])
}

@available(SwiftStdlib 5.5, *)
Expand Down
51 changes: 32 additions & 19 deletions test/Distributed/Runtime/distributed_actor_isRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// rdar://77798215
// UNSUPPORTED: OS=windows-msvc

// REQUIRES: radar78290608
// REQUIRES: rdar78290608

import _Distributed

Expand All @@ -25,9 +25,9 @@ distributed actor SomeSpecificDistributedActor {
@available(SwiftStdlib 5.5, *)
extension SomeSpecificDistributedActor {

@_dynamicReplacement(for: hello())
nonisolated func _remote_hello() async throws -> String {
return "remote impl (address: \(actor.id))"
@_dynamicReplacement(for: _remote_hello())
nonisolated func _remote_impl_hello() async throws -> String {
return "remote impl (address: \(self.id))"
}
}

Expand All @@ -40,30 +40,43 @@ struct FakeActorID: ActorIdentity {

@available(SwiftStdlib 5.5, *)
enum FakeTransportError: ActorTransportError {
case unsupportedActorIdentity(ActorIdentity)
case unsupportedActorIdentity(AnyActorIdentity)
}

@available(SwiftStdlib 5.5, *)
struct ActorAddress: ActorIdentity {
let address: String
init(parse address : String) {
self.address = address
}
}

@available(SwiftStdlib 5.5, *)
struct FakeTransport: ActorTransport {
func resolve<Act>(address: ActorAddress, as actorType: Act.Type)
throws -> ActorResolved<Act> where Act: DistributedActor {
return .makeProxy
func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
fatalError("not implemented:\(#function)")
}

func assignIdentity<Act>(
_ actorType: Act.Type
) -> ActorAddress where Act : DistributedActor {
ActorAddress(parse: "")
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type)
throws -> ActorResolved<Act>
where Act: DistributedActor {
.makeProxy
}

public func actorReady<Act>(
_ actor: Act
) where Act: DistributedActor {}
func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
let id = ActorAddress(parse: "xxx")
print("assign type:\(actorType), id:\(id)")
return .init(id)
}

public func resignIdentity(
_ address: AnyActorIdentity
) {}
func actorReady<Act>(_ actor: Act) where Act: DistributedActor {
print("ready actor:\(actor), id:\(actor.id)")
}

func resignIdentity(_ id: AnyActorIdentity) {
print("ready id:\(id)")
}
}

// ==== Execute ----------------------------------------------------------------
Expand All @@ -88,7 +101,7 @@ func test_remote() async {
assert(__isRemoteActor(local) == false, "should be local")

// assume it always makes a remote one
let remote = try! SomeSpecificDistributedActor(resolve: address, using: transport)
let remote = try! SomeSpecificDistributedActor(resolve: .init(address), using: transport)
assert(__isLocalActor(remote) == false, "should be remote")
assert(__isRemoteActor(remote) == true, "should be remote")

Expand Down
20 changes: 11 additions & 9 deletions test/Distributed/Runtime/distributed_actor_local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// REQUIRES: radar78290608
// REQUIRES: rdar78290608

import _Distributed

Expand All @@ -18,6 +18,10 @@ distributed actor SomeSpecificDistributedActor {
distributed func hello() async throws {
print("hello from \(self.id)")
}

distributed func echo(int: Int) async throws -> Int {
int
}
}

// ==== Execute ----------------------------------------------------------------
Expand All @@ -41,25 +45,23 @@ struct ActorAddress: ActorIdentity {

@available(SwiftStdlib 5.5, *)
struct FakeTransport: ActorTransport {

func decodeIdentity(from decoder: Decoder) throws -> AnyActorIdentity {
fatalError()
fatalError("not implemented \(#function)")
}

func resolve<Act>(identity: Act.ID, as actorType: Act.Type)
throws -> ActorResolved<Act>
func resolve<Act>(_ identity: Act.ID, as actorType: Act.Type) throws -> ActorResolved<Act>
where Act: DistributedActor {
fatalError()
return .makeProxy
}

func assignIdentity<Act>(_ actorType: Act.Type) -> AnyActorIdentity
where Act: DistributedActor {
ActorAddress(parse: "")
.init(ActorAddress(parse: ""))
}

public func actorReady<Act>(_ actor: Act)
where Act: DistributedActor {
fatalError()
print("\(#function):\(actor)")
}

func resignIdentity(_ id: AnyActorIdentity) {}
Expand All @@ -73,7 +75,7 @@ func test_initializers() {
let transport = FakeTransport()

_ = SomeSpecificDistributedActor(transport: transport)
_ = try! SomeSpecificDistributedActor.resolve(address, using: transport)
_ = try! SomeSpecificDistributedActor(resolve: .init(address), using: transport)
}

@available(SwiftStdlib 5.5, *)
Expand Down
Loading