Skip to content

Commit 2025b44

Browse files
xedinktoso
authored andcommitted
[Distributed] Fix ActorSystem requests on protocols that conform to DistributedActor
1 parent ef10cd0 commit 2025b44

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

lib/AST/DistributedDecl.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
207207
return Type();
208208

209209
auto module = actor->getParentModule();
210+
211+
// In case of protocol, let's find a concrete `ActorSystem`
212+
if (auto *protocol = dyn_cast<ProtocolDecl>(actor)) {
213+
auto signature = protocol->getGenericSignatureOfContext();
214+
215+
auto systemTy =
216+
signature->getConcreteType(actorSystemDecl->getDeclaredInterfaceType());
217+
if (!systemTy)
218+
return Type();
219+
220+
auto conformance = module->lookupConformance(systemTy, actorSystemProtocol);
221+
if (conformance.isInvalid())
222+
return Type();
223+
224+
return conformance.getTypeWitnessByName(systemTy, member);
225+
}
226+
210227
Type selfType = actor->getSelfInterfaceType();
211228
auto conformance = module->lookupConformance(selfType, actorProtocol);
212229
Type dependentType = actorProtocol->getSelfInterfaceType();

test/Distributed/Runtime/distributed_actor_hop_to.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ protocol LifecycleWatch: DistributedActor where ActorSystem == FakeRoundtripActo
2424
}
2525

2626
extension LifecycleWatch {
27-
func watch() async throws {
27+
func watch<T: Codable>(x: Int, _ y: T) async throws {
2828
// nothing here
29-
print("executed: \(#function)")
29+
print("executed: \(#function) - x = \(x), y = \(y)")
3030
}
3131

32-
distributed func test() async throws {
32+
distributed func test<T: Codable>(x: Int, _ y: T) async throws {
3333
print("executed: \(#function)")
34-
try await self.watch()
34+
try await self.watch(x: x, y)
3535
print("done executed: \(#function)")
3636
}
3737
}
@@ -42,11 +42,11 @@ distributed actor Worker: LifecycleWatch {
4242
@main struct Main {
4343
static func main() async {
4444
let worker: any LifecycleWatch = Worker(actorSystem: DefaultDistributedActorSystem())
45-
try! await worker.test()
45+
try! await worker.test(x: 42, "on protocol")
4646

47-
// CHECK: executed: test()
48-
// CHECK: executed: watch()
49-
// CHECK: done executed: test()
47+
// CHECK: executed: test(x:_:)
48+
// CHECK: executed: watch(x:_:) - x = 42, y = on protocol
49+
// CHECK: done executed: test(x:_:)
5050

5151
print("OK") // CHECK: OK
5252
}

0 commit comments

Comments
 (0)