Files
swift-mirror/test/Interpreter/moveonly_deinit_autoclosure.swift
Joe Groff ed2cbca04f ClosureLifetimeFixup: Remove copy of borrowed move-only nonescaping captures when possible.
SILGen introduces a copy of the capture, because the semantics of escaping partial_apply's
requires the closure to take ownership of the parameters. We don't know when a closure is
strictly nonescaping or its final lifetime until ClosureLifetimeFixup runs, but that replaces
the consume of the copy with a borrow of the copy normally, hoping later passes fix it up.
We can't wait that long for move-only types, which can't be copied, so try to remove the
copy up front when the copy lives long enough and has no interfering uses other than the
partial_apply. rdar://110137169
2023-06-20 12:10:31 -07:00

35 lines
558 B
Swift

// RUN: %target-run-simple-swift
// REQUIRES: executable_test
internal func _myPrecondition(
_ body: @autoclosure () -> Bool
) {
guard body() else {
fatalError("condition failed")
}
}
var deinitCounter = 0
struct MyCounter<T>: ~Copyable {
let expectedCount = 1
let box: T
init(_ t: T) {
self.box = t
}
deinit {
print("hello")
deinitCounter += 1
_myPrecondition(deinitCounter == self.expectedCount)
}
}
func test() {
_ = MyCounter(4343)
}
// CHECK: hello
test()
// CHECK-NEXT: great success
print("great success")