Files
swift-mirror/test/SILGen/ownership.swift
Joe Groff 69e4b95fb8 SIL: Model noescape partial_applys with ownership in OSSA.
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.
2023-02-16 21:43:53 -08:00

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 {
}
}