File: distributed_actor_thunk_doesnt_leak_arguments.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 (100 lines) | stat: -rw-r--r-- 2,823 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
91
92
93
94
95
96
97
98
99
100
// 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-swift-frontend -module-name no_to_arg_leaks -emit-irgen -disable-availability-checking -I %t 2>&1 %s | %IRGenFileCheck %s -check-prefix CHECK-%target-import-type

// UNSUPPORTED: back_deploy_concurrency
// REQUIRES: concurrency
// REQUIRES: distributed

// REQUIRES: CPU=x86_64 || CPU=arm64

// UNSUPPORTED: OS=windows-msvc

import Distributed
import FakeDistributedActorSystems

@available(SwiftStdlib 5.5, *)
typealias DefaultDistributedActorSystem = FakeActorSystem

final class SomeClass<T>: Sendable, Codable {
  init() {}
}

struct S<T> : Codable {
  var data: SomeClass<T>
}


class Sentinel {
  let str: String = ""
}

struct InnerStruct1 {
  let sentinel: Sentinel
  let innerStruct2: InnerStruct2

  init() {
    self.sentinel = Sentinel()
    self.innerStruct2 = InnerStruct2()
  }
}

struct InnerStruct2 {
  let sentinel: Sentinel

  init() {
    self.sentinel = Sentinel()
  }
}

enum InnerEnum {
  case v1(String)
  case v2(InnerStruct1)
}

struct ArgumentType: Codable {
  let sentinel: Sentinel
  let value: Int
  let innerEnum: InnerEnum

  init() {
    self.sentinel = Sentinel()
    self.value = 100
    self.innerEnum = .v2(InnerStruct1())
  }

  init(from decoder: Decoder) throws {
    fatalError("Not implemented")
  }

  func encode(to encoder: Encoder) throws {}
}

distributed actor Greeter {
  // CHECK-LABEL: define linkonce_odr hidden swifttailcc void @"$s15no_to_arg_leaks7GreeterC5test1yyAA9SomeClassCyxGYaKlFTETF"
  // CHECK: call void {{.*}}(ptr noalias [[PARAM:%.*]], ptr %arg_type)
  // CHECK-NEXT: call swiftcc void @swift_task_dealloc(ptr [[PARAM]])
  distributed func test1<T>(_: SomeClass<T>) {
  }

  // CHECK-LABEL: define linkonce_odr hidden swifttailcc void @"$s15no_to_arg_leaks7GreeterC5test2yyAA1SVyxGYaKlFTETF"
  // CHECK: call void {{.*}}(ptr noalias [[PARAM:%.*]], ptr %arg_type)
  // CHECK-NEXT: call swiftcc void @swift_task_dealloc(ptr [[PARAM]])
  distributed func test2<T>(_: S<T>) {}

  // CHECK-LABEL: define linkonce_odr hidden swifttailcc void @"$s15no_to_arg_leaks7GreeterC5test3yyAA12ArgumentTypeVYaKFTETF"
  // CHECK: call void {{.*}}(ptr noalias [[PARAM:%.*]], ptr %arg_type)
  // CHECK-NEXT: call swiftcc void @swift_task_dealloc(ptr [[PARAM]])
  distributed func test3(_: ArgumentType) {}
}

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

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

  try await ref.test1(SomeClass<Int>())
  try await ref.test2(S(data: SomeClass<Int>()))
  try await ref.test3(.init())
}