File: distributed_actor_func_calls_remoteCall_genericFunc.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (90 lines) | stat: -rw-r--r-- 3,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/../Inputs/FakeDistributedActorSystems.swift
// RUN: %target-build-swift -module-name main  -Xfrontend -disable-availability-checking -j2 -parse-as-library -I %t %s %S/../Inputs/FakeDistributedActorSystems.swift -o %t/a.out
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s

// REQUIRES: executable_test
// REQUIRES: concurrency
// REQUIRES: distributed

// rdar://76038845
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime

// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
// UNSUPPORTED: OS=windows-msvc

import Distributed
import FakeDistributedActorSystems

typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem

distributed actor Greeter {
  distributed func generic<V: Codable>(_ value: V) -> String {
    _ = V.self
    return "\(value)"
  }

  distributed func generic2<A: Codable, B: Codable>(
      strict: Double, _ value: A, _ bs: [B]) -> String {
    return "\(value) \(bs)"
  }

}

distributed actor GenericGreeter<Greeting: Sendable & Codable> {
  distributed func echo(greeting: Greeting) -> Greeting {
    greeting
  }
}

func test() async throws {
  let system = DefaultDistributedActorSystem()

  let local = Greeter(actorSystem: system)
  let ref = try Greeter.resolve(id: local.id, using: system)

  let r1 = try await ref.generic("Caplin")
  // CHECK: > encode generic sub: Swift.String
  // CHECK: > encode argument name:_, value: Caplin
  // CHECK: > encode return type: Swift.String
  // CHECK: > done recording
  // CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.generic(_:), invocation:FakeInvocationEncoder(genericSubs: [Swift.String], arguments: ["Caplin"], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
  print("reply: \(r1)")
  // CHECK: reply: Caplin

  let r2 = try await ref.generic2(
      strict: 2.0,
      "Caplin",
      [1, 2, 3]
  )
  // CHECK: > encode generic sub: Swift.String
  // CHECK: > encode generic sub: Swift.Int
  // CHECK: > encode argument name:strict, value: 2.0
  // CHECK: > encode argument name:_, value: Caplin
  // CHECK: > encode argument name:_, value: [1, 2, 3]
  // CHECK: > encode return type: Swift.String
  // CHECK: > done recording
  // CHECK: >> remoteCall: on:main.Greeter, target:main.Greeter.generic2(strict:_:_:), invocation:FakeInvocationEncoder(genericSubs: [Swift.String, Swift.Int], arguments: [2.0, "Caplin", [1, 2, 3]], returnType: Optional(Swift.String), errorType: nil), throwing:Swift.Never, returning:Swift.String
  print("reply: \(r2)")
  // CHECK: reply: Caplin

  let gen = GenericGreeter<String>(actorSystem: system)
  let r3 = try await gen.echo(greeting: "Hello generics!")
  print("reply: \(r3)")
  // CHECK: reply: Hello generics!

  let genRef = try GenericGreeter<String>.resolve(id: gen.id, using: system)
  let r32 = try await genRef.echo(greeting: "Hello generics!")
  // CHECK: > encode generic sub: Swift.String
  // CHECK: > encode return type: Swift.String
  print("reply: \(r32)")
  // CHECK: reply: Hello generics!
}

@main struct Main {
  static func main() async {
    try! await test()
  }
}