Skip to content

Commit a98a30d

Browse files
committed
[Distributed] More tests for primary associated types in protocols
1 parent 6e9224c commit a98a30d

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

test/Distributed/Runtime/distributed_actor_func_calls_remoteCall_through_generic.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import FakeDistributedActorSystems
2020

2121
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
2222

23+
@available(SwiftStdlib 6.0, *)
2324
protocol PlainWorker {
2425
associatedtype WorkItem: Sendable & Codable
2526
associatedtype WorkResult: Sendable & Codable
@@ -28,7 +29,9 @@ protocol PlainWorker {
2829
func asyncThrows(work: WorkItem) async throws -> WorkResult
2930
}
3031

31-
protocol DistributedWorker: DistributedActor where ActorSystem == DefaultDistributedActorSystem {
32+
@Resolvable
33+
@available(SwiftStdlib 6.0, *)
34+
protocol DistributedWorker<WorkItem, WorkResult>: DistributedActor where ActorSystem == DefaultDistributedActorSystem {
3235
associatedtype WorkItem: Sendable & Codable
3336
associatedtype WorkResult: Sendable & Codable
3437

@@ -49,6 +52,7 @@ protocol DistributedWorker: DistributedActor where ActorSystem == DefaultDistrib
4952
func asyncThrowsReq_witnessDistributed_asyncThrows(work: WorkItem) async throws -> WorkResult
5053
}
5154

55+
@available(SwiftStdlib 6.0, *)
5256
distributed actor ThePlainWorker: PlainWorker {
5357
typealias ActorSystem = DefaultDistributedActorSystem
5458
typealias WorkItem = String
@@ -59,6 +63,7 @@ distributed actor ThePlainWorker: PlainWorker {
5963
}
6064
}
6165

66+
@available(SwiftStdlib 6.0, *)
6267
distributed actor TheWorker: DistributedWorker {
6368
typealias ActorSystem = DefaultDistributedActorSystem
6469
typealias WorkItem = String
@@ -105,6 +110,7 @@ distributed actor TheWorker: DistributedWorker {
105110

106111
}
107112

113+
@available(SwiftStdlib 6.0, *)
108114
func test_generic(system: DefaultDistributedActorSystem) async throws {
109115
let localW = TheWorker(actorSystem: system)
110116
let remoteW = try! TheWorker.resolve(id: localW.id, using: system)
@@ -218,6 +224,7 @@ func test_generic(system: DefaultDistributedActorSystem) async throws {
218224
// distributedness of those witnesses never actually is used remotely, but at
219225
// least check we invoke the right methods.
220226

227+
@available(SwiftStdlib 6.0, *)
221228
func call_requirement_witnessedByDistributed_sync<W: DistributedWorker>(w: W) async throws -> String where W.WorkItem == String, W.WorkResult == String {
222229
try await w.whenLocal { __secretlyKnownToBeLocal in
223230
try await __secretlyKnownToBeLocal.asyncThrowsReq_witnessDistributed_sync(work: "Hello")
@@ -231,6 +238,7 @@ func test_generic(system: DefaultDistributedActorSystem) async throws {
231238
}
232239
print("==== ----------------------------------------------------------------")
233240

241+
@available(SwiftStdlib 6.0, *)
234242
func call_requirement_witnessedByDistributed_async<W: DistributedWorker>(w: W) async throws -> String where W.WorkItem == String, W.WorkResult == String {
235243
try await w.whenLocal { __secretlyKnownToBeLocal in
236244
try await __secretlyKnownToBeLocal.asyncThrowsReq_witnessDistributed_async(work: "Hello")
@@ -244,6 +252,7 @@ func test_generic(system: DefaultDistributedActorSystem) async throws {
244252
}
245253
print("==== ----------------------------------------------------------------")
246254

255+
@available(SwiftStdlib 6.0, *)
247256
func call_requirement_witnessedByDistributed_syncThrows<W: DistributedWorker>(w: W) async throws -> String where W.WorkItem == String, W.WorkResult == String {
248257
try await w.whenLocal { __secretlyKnownToBeLocal in
249258
try await __secretlyKnownToBeLocal.asyncThrowsReq_witnessDistributed_syncThrows(work: "Hello")
@@ -257,6 +266,7 @@ func test_generic(system: DefaultDistributedActorSystem) async throws {
257266
}
258267
print("==== ----------------------------------------------------------------")
259268

269+
@available(SwiftStdlib 6.0, *)
260270
func call_requirement_witnessedByDistributed_asyncThrows<W: DistributedWorker>(w: W) async throws -> String where W.WorkItem == String, W.WorkResult == String {
261271
try await w.whenLocal { __secretlyKnownToBeLocal in
262272
try await __secretlyKnownToBeLocal.asyncThrowsReq_witnessDistributed_asyncThrows(work: "Hello")
@@ -271,6 +281,7 @@ func test_generic(system: DefaultDistributedActorSystem) async throws {
271281
print("==== ----------------------------------------------------------------")
272282
}
273283

284+
@available(SwiftStdlib 6.0, *)
274285
func test_whenLocal(system: DefaultDistributedActorSystem) async throws {
275286
let localW = TheWorker(actorSystem: system)
276287
let remoteW = try! TheWorker.resolve(id: localW.id, using: system)
@@ -341,6 +352,7 @@ func test_whenLocal(system: DefaultDistributedActorSystem) async throws {
341352
}
342353
}
343354

355+
@available(SwiftStdlib 6.0, *)
344356
func test_generic_plain(system: DefaultDistributedActorSystem) async throws {
345357
let localW = ThePlainWorker(actorSystem: system)
346358
let remoteW = try! ThePlainWorker.resolve(id: localW.id, using: system)
@@ -355,6 +367,7 @@ func test_generic_plain(system: DefaultDistributedActorSystem) async throws {
355367
}
356368
print("==== ----------------------------------------------------------------")
357369

370+
@available(SwiftStdlib 6.0, *)
358371
func call_plainWorker<W: PlainWorker>(w: W) async throws -> String where W.WorkItem == String, W.WorkResult == String {
359372
try await w.asyncThrows(work: "Hello")
360373
}
@@ -372,6 +385,7 @@ func test_generic_plain(system: DefaultDistributedActorSystem) async throws {
372385
}
373386
}
374387

388+
@available(SwiftStdlib 6.0, *)
375389
@main struct Main {
376390
static func main() async {
377391
let system = DefaultDistributedActorSystem()

test/Distributed/Runtime/distributed_actor_remoteCall_protocol_method_in_presence_of_multiple_systems.swift

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ protocol GreeterProtocol: DistributedActor where ActorSystem: DistributedActorSy
2323
distributed func greet() -> String
2424
}
2525

26+
protocol FruitProtocol: Codable {}
27+
struct Watermelon: FruitProtocol {}
28+
29+
protocol AnimalProtocol: Codable {}
30+
struct Capybara: AnimalProtocol {}
31+
32+
@Resolvable
33+
protocol FeederProtocol<Fruit, Animal>: DistributedActor where ActorSystem: DistributedActorSystem<any Codable> {
34+
associatedtype Fruit: FruitProtocol
35+
associatedtype Animal: AnimalProtocol
36+
distributed func give(fruit: Fruit, to animal: Animal)
37+
}
38+
2639
// ==== ------------------------------------------------------------------------
2740

2841
distributed actor DAFR: GreeterProtocol {
@@ -35,9 +48,17 @@ distributed actor DAFL: GreeterProtocol {
3548
distributed func greet() -> String { "\(Self.self)" }
3649
}
3750

51+
distributed actor Feeder: FeederProtocol {
52+
typealias ActorSystem = LocalTestingDistributedActorSystem
53+
distributed func give(fruit: Watermelon, to animal: Capybara) {
54+
// fake impl
55+
}
56+
}
57+
3858
@main struct Main {
3959
static func main() async throws {
4060
let fakeRoundtripSystem = FakeRoundtripActorSystem()
61+
4162
let fr = DAFR(actorSystem: fakeRoundtripSystem)
4263
let frid = fr.id
4364
_ = DAFL(actorSystem: .init())
@@ -46,16 +67,18 @@ distributed actor DAFL: GreeterProtocol {
4667

4768
print("resolved on \(fakeRoundtripSystem): \(type(of: gfr))")
4869
// CHECK: resolved on main.FakeRoundtripActorSystem: $GreeterProtocol<FakeRoundtripActorSystem>
49-
50-
// CHECK: > execute distributed target: main.$GreeterProtocol.greet(), identifier: $s4main16$GreeterProtocolC5greetSSyYaKFTE
70+
// CHECK-NEXT: > encode generic sub: main.$GreeterProtocol<main.FakeRoundtripActorSystem>
71+
// CHECK-NEXT: > encode return type: Swift.String
72+
// CHECK-NEXT: > done recording
73+
// CHECK-NEXT: >> remoteCall: on:main.$GreeterProtocol<main.FakeRoundtripActorSystem>, target:main.$GreeterProtocol.greet(), invocation:FakeInvocationEncoder(genericSubs: [main.$GreeterProtocol<main.FakeRoundtripActorSystem>], arguments: [], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
74+
// CHECK-NEXT: > execute distributed target: main.$GreeterProtocol.greet(), identifier: $s4main16$GreeterProtocolC5greetSSyYaKFTE
75+
// FIXME: was: > execute distributed target: main.$GreeterProtocol.greet(), identifier: $s4main16$GreeterProtocolC5greetSSyYaKAA0bC0RzlFTE
5176
// Notes:
5277
// - The call is made on the stub: $GreeterProtocol
5378
// - the record is name is 'HF' for the accessible function
5479

5580
let got = try await gfr.greet()
5681
print("got: \(got)")
57-
58-
print("ok") // CHECK: ok
5982
}
6083
}
6184

0 commit comments

Comments
 (0)