Skip to content

Commit b65f66d

Browse files
committed
[DistributedDecl] Add DistributedActorSystem to known SDK types
1 parent 6594417 commit b65f66d

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

include/swift/AST/KnownSDKTypes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ KNOWN_SDK_TYPE_DECL(Concurrency, TaskLocal, ClassDecl, 1)
4545

4646
// Distributed actors
4747
KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0)
48+
KNOWN_SDK_TYPE_DECL(Distributed, DistributedActorSystem, ProtocolDecl, 0)
4849
KNOWN_SDK_TYPE_DECL(Distributed, RemoteCallTarget, StructDecl, 0)
4950

5051
// String processing

lib/AST/DistributedDecl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file implements the Decl class and subclasses.
13+
// This file handles lookups related to distributed actor decls.
1414
//
1515
//===----------------------------------------------------------------------===//
1616

@@ -89,7 +89,7 @@ Type swift::getDistributedActorSystemActorIDRequirementType(NominalTypeDecl *sys
8989
assert(!system->isDistributedActor());
9090
auto &ctx = system->getASTContext();
9191

92-
auto protocol = ctx.getProtocol(KnownProtocolKind::DistributedActorSystem);
92+
auto protocol = ctx.getDistributedActorSystemDecl();
9393
if (!protocol)
9494
return Type();
9595

@@ -128,7 +128,7 @@ Type ASTContext::getAssociatedTypeOfDistributedSystemOfActor(
128128
if (!actorSystemDecl)
129129
return Type();
130130

131-
auto actorSystemProtocol = ctx.getProtocol(KnownProtocolKind::DistributedActorSystem);
131+
auto actorSystemProtocol = ctx.getDistributedActorSystemDecl();
132132
if (!actorSystemProtocol)
133133
return Type();
134134

@@ -252,7 +252,7 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
252252

253253
// === Must be declared in a 'DistributedActorSystem' conforming type
254254
ProtocolDecl *systemProto =
255-
C.getProtocol(KnownProtocolKind::DistributedActorSystem);
255+
C.getDistributedActorSystemDecl();
256256

257257
auto systemNominal = getDeclContext()->getSelfNominalTypeDecl();
258258
auto distSystemConformance = module->lookupConformance(
@@ -968,7 +968,7 @@ llvm::SmallPtrSet<ProtocolDecl *, 2>
968968
swift::extractDistributedSerializationRequirements(
969969
ASTContext &C, ArrayRef<Requirement> allRequirements) {
970970
llvm::SmallPtrSet<ProtocolDecl *, 2> serializationReqs;
971-
auto systemProto = C.getProtocol(KnownProtocolKind::DistributedActorSystem);
971+
auto systemProto = C.getDistributedActorSystemDecl();
972972
auto serializationReqAssocType =
973973
systemProto->getAssociatedType(C.Id_SerializationRequirement);
974974
auto systemSerializationReqTy = serializationReqAssocType->getInterfaceType();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-build-swift -module-name main -Xfrontend -enable-experimental-distributed -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
4+
// RUN: %target-run %t/a.out | %FileCheck %s --color
5+
6+
// REQUIRES: executable_test
7+
// REQUIRES: concurrency
8+
// REQUIRES: distributed
9+
10+
// rdar://76038845
11+
// UNSUPPORTED: use_os_stdlib
12+
// UNSUPPORTED: back_deployment_runtime
13+
14+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
15+
// UNSUPPORTED: windows
16+
17+
import _Distributed
18+
import FakeDistributedActorSystems
19+
20+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
21+
22+
protocol LifecycleWatch: DistributedActor where ActorSystem == FakeRoundtripActorSystem {
23+
}
24+
25+
extension LifecycleWatch {
26+
func watch() async throws {
27+
// nothing here
28+
}
29+
30+
distributed func test() async throws {
31+
try await self.watch()
32+
}
33+
}
34+
35+
distributed actor Worker: LifecycleWatch {
36+
37+
}
38+
39+
@main struct Main {
40+
static func main() async {
41+
let worker: any LifecycleWatch = Worker(system: DefaultDistributedActorSystem())
42+
try! await worker.test()
43+
44+
print("OK") // CHECK: OK
45+
}
46+
}

0 commit comments

Comments
 (0)