Skip to content

Commit e99c397

Browse files
committed
reproduce deinit not running
1 parent 6f0ebe5 commit e99c397

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

test/Distributed/Inputs/FakeDistributedActorSystems.swift

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ public final class FakeRoundtripActorSystem: DistributedActorSystem, @unchecked
226226

227227
public init() {}
228228

229+
public func shutdown() {
230+
self.activeActors = [:]
231+
}
232+
229233
public func resolve<Act>(id: ActorID, as actorType: Act.Type)
230234
throws -> Act? where Act: DistributedActor {
231235
print("| resolve \(id) as remote // this system always resolves as remote")
@@ -394,7 +398,14 @@ public struct FakeInvocationEncoder : DistributedTargetInvocationEncoder {
394398
print(" > done recording")
395399
}
396400

397-
public func makeDecoder() -> FakeInvocationDecoder {
401+
public mutating func makeDecoder() -> FakeInvocationDecoder {
402+
defer {
403+
// reset the decoder; we don't want to keep these values retained by accident here
404+
genericSubs = []
405+
arguments = []
406+
returnType = nil
407+
errorType = nil
408+
}
398409
return .init(
399410
args: arguments,
400411
substitutions: genericSubs,
@@ -406,32 +417,13 @@ public struct FakeInvocationEncoder : DistributedTargetInvocationEncoder {
406417

407418
// === decoding --------------------------------------------------------------
408419

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-
426420
// !!! WARNING !!!
427421
// This is a 'final class' on purpose, to see that we retain the ad-hoc witness
428422
// for 'decodeNextArgument'; Do not change it to just a class!
429423
@available(SwiftStdlib 5.7, *)
430424
public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
431425
public typealias SerializationRequirement = Codable
432426

433-
let x = Guardian(FakeInvocationDecoder.self)
434-
435427
var genericSubs: [Any.Type] = []
436428
var arguments: [Any] = []
437429
var returnType: Any.Type? = nil
@@ -466,8 +458,6 @@ public final class FakeInvocationDecoder: DistributedTargetInvocationDecoder {
466458
fatalError("Cannot cast argument\(anyArgument) to expected \(Argument.self)")
467459
}
468460

469-
arguments = []
470-
471461
print(" > decode argument: \(argument)")
472462
argumentIndex += 1
473463
return argument

test/Distributed/Runtime/distributed_actor_func_calls_decoded_args_deinit.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,15 @@ import FakeDistributedActorSystems
2121
typealias DefaultDistributedActorSystem = FakeRoundtripActorSystem
2222

2323
final class SomeClass<T>: Sendable, Codable {
24-
init() {
25-
print("SomeClass: init")
24+
let file: String
25+
let line: UInt
26+
init(file: String = #fileID, line: UInt = #line) {
27+
self.file = file
28+
self.line = line
29+
print("SomeClass: init @ \(file):\(line)")
2630
}
2731
deinit {
28-
print("SomeClass: deinit")
32+
print("SomeClass: deinit @ \(file):\(line)")
2933
}
3034
}
3135

@@ -40,15 +44,16 @@ distributed actor Greeter {
4044

4145
func test() async throws {
4246
let system = DefaultDistributedActorSystem()
47+
defer { system.shutdown() }
4348

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

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+
var value = SomeClass<Int>()
53+
try await ref.test1(value)
54+
print("RETAIN COUNT: \(_swift_retainCount(value))")
55+
_swift_release(value) // FIXME: we're missing a release!
56+
print("RETAIN COUNT: \(_swift_retainCount(value))")
5257
// CHECK: SomeClass: init
5358
// CHECK: SomeClass: deinit
5459
}
@@ -58,3 +63,8 @@ func test() async throws {
5863
try! await test()
5964
}
6065
}
66+
67+
@_silgen_name("swift_release")
68+
func _swift_release(_: AnyObject)
69+
@_silgen_name("swift_retainCount")
70+
func _swift_retainCount(_: AnyObject) -> Int

0 commit comments

Comments
 (0)