mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
35 lines
558 B
Swift
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")
|