|
| 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 | +} |
0 commit comments