Skip to content

Commit 746720c

Browse files
committed
[Distributed] additional test coverage
1 parent 4da5b64 commit 746720c

File tree

3 files changed

+140
-1
lines changed

3 files changed

+140
-1
lines changed

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4464,8 +4464,9 @@ void ASTMangler::appendDistributedThunk(
44644464
auto M = thunk->getModuleContext();
44654465

44664466
SmallVector<ValueDecl *, 1> stubClassLookupResults;
4467-
C.lookupInModule(M, ("$" + P->getNameStr()).str(), stubClassLookupResults);
4467+
C.lookupInModule(M, llvm::Twine("$", P->getNameStr()).str(), stubClassLookupResults);
44684468

4469+
assert(stubClassLookupResults.size() <= 1 && "Found multiple distributed stub types!");
44694470
if (stubClassLookupResults.size() > 0) {
44704471
stubActorDecl =
44714472
dyn_cast_or_null<NominalTypeDecl>(stubClassLookupResults.front());
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -plugin-path %swift-plugin-dir -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -target %target-swift-5.7-abi-triple %S/../Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-build-swift -module-name main -plugin-path %swift-plugin-dir -target %target-swift-5.7-abi-triple -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
4+
// RUN: %target-codesign %t/a.out
5+
// RUN: %target-run %t/a.out | %FileCheck %s --dump-input=always
6+
7+
// REQUIRES: executable_test
8+
// REQUIRES: concurrency
9+
// REQUIRES: distributed
10+
11+
// rdar://76038845
12+
// UNSUPPORTED: use_os_stdlib
13+
// UNSUPPORTED: back_deployment_runtime
14+
15+
// UNSUPPORTED: OS=windows-msvc
16+
17+
import Distributed
18+
import FakeDistributedActorSystems
19+
20+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
21+
22+
@Resolvable
23+
@available(SwiftStdlib 6.0, *)
24+
protocol Service: DistributedActor where ActorSystem == FakeRoundtripActorSystem {
25+
distributed func getArray(a1: [Int], a2: String?) async throws -> [Int]
26+
27+
// Make sure method-level generics also work fine
28+
distributed func getArrayGeneric<Gen: Codable & Sendable>(a1: [Int], a2: String?, gen: Gen) async throws -> [Int]
29+
}
30+
31+
@available(SwiftStdlib 6.0, *)
32+
distributed actor ServiceImpl: Service {
33+
distributed func getArray(a1: [Int], a2: String?) async throws -> [Int] {
34+
return a1 + [4, 5]
35+
}
36+
37+
distributed func getArrayGeneric<Gen: Codable & Sendable>(a1: [Int], a2: String?, gen: Gen) async throws -> [Int] {
38+
return a1 + [4, 5]
39+
}
40+
}
41+
42+
@available(SwiftStdlib 6.0, *)
43+
func test() async throws {
44+
let system = DefaultDistributedActorSystem()
45+
46+
let local = ServiceImpl(actorSystem: system)
47+
48+
let implRef = try ServiceImpl.resolve(id: local.id, using: system)
49+
let r1 = try await implRef.getArray(a1: [1, 2, 3], a2: "second")
50+
// CHECK: >> remoteCall: on:main.ServiceImpl, target:main.ServiceImpl.getArray(a1:a2:), invocation:FakeInvocationEncoder(genericSubs: [], arguments: [[[ARGS:.*]]], returnType: Optional(Swift.Array<Swift.Int>), errorType: Optional(Swift.Error)), throwing:Swift.Error, returning:Swift.Array<Swift.Int>
51+
// CHECK: > execute distributed target: main.ServiceImpl.getArray(a1:a2:), identifier: $s4main11ServiceImplC8getArray2a12a2SaySiGAG_SSSgtYaKFTE
52+
print("reply 1: \(r1)")
53+
// CHECK: reply 1: [1, 2, 3, 4, 5]
54+
55+
let ref = try $Service.resolve(id: local.id, using: system)
56+
let r2 = try await ref.getArray(a1: [1, 2, 3], a2: "second")
57+
// CHECK: >> remoteCall: on:main.$Service, target:main.$Service.getArray(a1:a2:), invocation:FakeInvocationEncoder(genericSubs: [main.$Service], arguments: [[[ARGS:.*]]], returnType: Optional(Swift.Array<Swift.Int>), errorType: Optional(Swift.Error)), throwing:Swift.Error, returning:Swift.Array<Swift.Int>
58+
// CHECK: > execute distributed target: main.$Service.getArray(a1:a2:), identifier: $s4main8$ServiceC8getArray2a12a2SaySiGAG_SSSgtYaKFTE
59+
// CHECK: > decode generic subs: [main.$Service]
60+
// CHECK: > decode return type: Swift.Array<Swift.Int>
61+
// CHECK: > decode argument: [1, 2, 3]
62+
// CHECK: > decode argument: Optional("second")
63+
print("reply 2: \(r2)")
64+
// CHECK: reply 2: [1, 2, 3, 4, 5]
65+
66+
_ = try await ref.getArrayGeneric(a1: [1, 2, 3], a2: "third", gen: 12)
67+
// CHECK: remoteCall: on:main.$Service, target:main.$Service.getArrayGeneric(a1:a2:gen:), invocation:FakeInvocationEncoder(genericSubs: [main.$Service, Swift.Int], arguments: [[[ARGS:.*]]], returnType: Optional(Swift.Array<Swift.Int>), errorType: Optional(Swift.Error)), throwing:Swift.Error, returning:Swift.Array<Swift.Int>
68+
// CHECK: > execute distributed target: main.$Service.getArrayGeneric(a1:a2:gen:), identifier: $s4main8$ServiceC15getArrayGeneric2a12a23genSaySiGAH_SSSgqd__tYaKSeRd__SERd__lFTE
69+
// CHECK: > decode generic subs: [main.$Service, Swift.Int]
70+
// CHECK: > decode return type: Swift.Array<Swift.Int>
71+
// CHECK: > decode argument: [1, 2, 3]
72+
// CHECK: > decode argument: Optional("third")
73+
// CHECK: > decode argument: 12
74+
}
75+
76+
@available(SwiftStdlib 6.0, *)
77+
@main struct Main {
78+
static func main() async {
79+
try! await test()
80+
81+
print("Done")
82+
// CHECK: Done
83+
}
84+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-build-swift -module-name main -j2 -parse-as-library -I %t %s -plugin-path %swift-plugin-dir -o %t/a.out
3+
// RUN: %target-codesign %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+
// rdar://90373022
15+
// UNSUPPORTED: OS=watchos
16+
17+
// rdar://125628060
18+
// UNSUPPORTED: CPU=arm64e
19+
20+
import Distributed
21+
22+
@Resolvable
23+
@available(SwiftStdlib 6.0, *)
24+
protocol WorkerProtocol: DistributedActor where ActorSystem == LocalTestingDistributedActorSystem {
25+
distributed var distributedVariable: String { get }
26+
}
27+
28+
@available(SwiftStdlib 6.0, *)
29+
distributed actor Worker: WorkerProtocol {
30+
distributed var distributedVariable: String {
31+
"implemented variable"
32+
}
33+
}
34+
35+
// ==== Execute ----------------------------------------------------------------
36+
37+
38+
@available(SwiftStdlib 6.0, *)
39+
func test_distributedVariable<DA: WorkerProtocol>(actor: DA) async throws -> String {
40+
try await actor.distributedVariable
41+
}
42+
43+
@available(SwiftStdlib 6.0, *)
44+
@main struct Main {
45+
static func main() async throws {
46+
let system = LocalTestingDistributedActorSystem()
47+
48+
let actor: any WorkerProtocol = Worker(actorSystem: system)
49+
50+
// force a call through witness table
51+
let v1 = try await test_distributedVariable(actor: actor)
52+
print("v1 = \(v1)") // CHECK: v1 = implemented variable
53+
}
54+
}

0 commit comments

Comments
 (0)