Skip to content

Commit 6f0ebe5

Browse files
committed
more tests
1 parent c6160d2 commit 6f0ebe5

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

test/Distributed/Inputs/FakeDistributedActorSystems.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,32 @@ public struct FakeInvocationEncoder : DistributedTargetInvocationEncoder {
406406

407407
// === decoding --------------------------------------------------------------
408408

409+
class Guardian {
410+
let type: String
411+
let file: String
412+
let line: UInt
413+
414+
init(_ type: any Any.Type, file: String = #fileID, line: UInt = #line) {
415+
self.type = "\(type)"
416+
self.file = file
417+
self.line = line
418+
print("init Guardian(\(type)) @ \(file):\(line)")
419+
}
420+
421+
deinit {
422+
print("deinit Guardian(\(type)) @ \(file):\(line)")
423+
}
424+
}
425+
409426
// !!! WARNING !!!
410427
// This is a 'final class' on purpose, to see that we retain the ad-hoc witness
411428
// for 'decodeNextArgument'; Do not change it to just a class!
412429
@available(SwiftStdlib 5.7, *)
413430
public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
414431
public typealias SerializationRequirement = Codable
415432

433+
let x = Guardian(FakeInvocationDecoder.self)
434+
416435
var genericSubs: [Any.Type] = []
417436
var arguments: [Any] = []
418437
var returnType: Any.Type? = nil
@@ -447,6 +466,8 @@ public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
447466
fatalError("Cannot cast argument\(anyArgument) to expected \(Argument.self)")
448467
}
449468

469+
arguments = []
470+
450471
print(" > decode argument: \(argument)")
451472
argumentIndex += 1
452473
return argument
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 -disable-availability-checking -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 --color --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+
// FIXME(distributed): Distributed actors currently have some issues on windows, isRemote always returns false. rdar://82593574
16+
// UNSUPPORTED: OS=windows-msvc
17+
18+
import Distributed
19+
import FakeDistributedActorSystems
20+
21+
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
22+
23+
final class SomeClass<T>: Sendable, Codable {
24+
init() {
25+
print("SomeClass: init")
26+
}
27+
deinit {
28+
print("SomeClass: deinit")
29+
}
30+
}
31+
32+
struct S<T> : Codable {
33+
var data: SomeClass<T>
34+
}
35+
36+
distributed actor Greeter {
37+
distributed func test1<T>(_: SomeClass<T>) {}
38+
distributed func test2<T>(_: S<T>) {}
39+
}
40+
41+
func test() async throws {
42+
let system = DefaultDistributedActorSystem()
43+
44+
let local = Greeter(actorSystem: system)
45+
let ref = try Greeter.resolve(id: local.id, using: system)
46+
47+
try await ref.test1(SomeClass<Int>())
48+
// CHECK: SomeClass: init
49+
// CHECK: SomeClass: deinit
50+
51+
// try await ref.test2(S(data: SomeClass<Int>()))
52+
// CHECK: SomeClass: init
53+
// CHECK: SomeClass: deinit
54+
}
55+
56+
@main struct Main {
57+
static func main() async {
58+
try! await test()
59+
}
60+
}

test/Distributed/distributed_actor_thunk_doesnt_leak_class_arguments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
2-
// 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
2+
// 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 --dump-input=always
33

44
// UNSUPPORTED: back_deploy_concurrency
55
// REQUIRES: concurrency

0 commit comments

Comments
 (0)