mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Although nonescaping closures are representationally trivial pointers to their on-stack context, it is useful to model them as borrowing their captures, which allows for checking correct use of move-only values across the closure, and lets us model the lifetime dependence between a closure and its captures without an ad-hoc web of `mark_dependence` instructions. During ownership elimination, We eliminate copy/destroy_value instructions and end the partial_apply's lifetime with an explicit dealloc_stack as before, for compatibility with existing IRGen and non-OSSA aware passes.
24 lines
921 B
Swift
24 lines
921 B
Swift
// RUN: %target-swift-emit-silgen -parse-stdlib -module-name Swift -parse-as-library %s | %FileCheck %s
|
|
|
|
protocol Error {}
|
|
|
|
enum MyError : Error {
|
|
case case1
|
|
}
|
|
|
|
// CHECK: bb{{[0-9]+}}([[ERROR:%.*]] : @owned $any Error):
|
|
// CHECK-NEXT: end_borrow {{.*}} : ${{.*}}() ->
|
|
// CHECK-NEXT: destroy_value {{.*}} : ${{.*}}() ->
|
|
// CHECK-NEXT: [[BORROWED_ERROR:%.*]] = begin_borrow [[ERROR]]
|
|
// CHECK-NEXT: [[ERROR_SLOT:%.*]] = alloc_stack $any Error
|
|
// CHECK-NEXT: [[COPIED_BORROWED_ERROR:%.*]] = copy_value [[BORROWED_ERROR]]
|
|
// CHECK-NEXT: store [[COPIED_BORROWED_ERROR]] to [init] [[ERROR_SLOT]]
|
|
// CHECK-NEXT: [[ERROR_SLOT_CAST_RESULT:%.*]] = alloc_stack $MyError
|
|
// CHECK-NEXT: checked_cast_addr_br copy_on_success any Error in [[ERROR_SLOT]] : $*any Error to MyError in [[ERROR_SLOT_CAST_RESULT]] : $*MyError
|
|
func test1(f: () throws -> ()) throws {
|
|
do {
|
|
let _ = try f()
|
|
} catch MyError.case1 {
|
|
}
|
|
}
|