|
| 1 | +// RUN: %target-sil-opt %s \ |
| 2 | +// RUN: -early-inline \ |
| 3 | +// RUN: -sil-print-types \ |
| 4 | +// RUN: -enable-experimental-feature Lifetimes | %FileCheck %s |
| 5 | + |
| 6 | +// REQUIRES: swift_in_compiler |
| 7 | +// REQUIRES: swift_feature_Lifetimes |
| 8 | + |
| 9 | +import Swift |
| 10 | +import Builtin |
| 11 | + |
| 12 | +struct Wrapper : ~Copyable { |
| 13 | +} |
| 14 | + |
| 15 | +struct NE : ~Escapable { |
| 16 | +} |
| 17 | + |
| 18 | +struct MyBox : ~Copyable { |
| 19 | +} |
| 20 | + |
| 21 | +sil @$s4test7WrapperVACycfC : $@convention(method) (@thin Wrapper.Type) -> @owned Wrapper |
| 22 | +sil @$s4test2NEVyAcA7WrapperVhcfC : $@convention(method) (@guaranteed Wrapper, @thin NE.Type) -> @lifetime(borrow 0) @owned NE |
| 23 | +sil @$s4test5MyBoxVACycfC : $@convention(method) (@thin MyBox.Type) -> @owned MyBox |
| 24 | +sil @$s4test3useyyAA2NEVF : $@convention(thin) (@guaranteed NE) -> () |
| 25 | + |
| 26 | +sil hidden [ossa] @$s4test5MyBoxV5valueAA2NEVvr : $@yield_once @convention(method) (@guaranteed MyBox) -> @lifetime(borrow 0) @yields @guaranteed NE { |
| 27 | +bb0(%0 : @guaranteed $MyBox): |
| 28 | + %1 = copy_value %0 |
| 29 | + %2 = mark_unresolved_non_copyable_value [no_consume_or_assign] %1 |
| 30 | + %4 = alloc_box ${ let Wrapper }, let, name "w" |
| 31 | + %5 = begin_borrow [lexical] [var_decl] %4 |
| 32 | + %6 = project_box %5, 0 |
| 33 | + %7 = metatype $@thin Wrapper.Type |
| 34 | + %8 = function_ref @$s4test7WrapperVACycfC : $@convention(method) (@thin Wrapper.Type) -> @owned Wrapper |
| 35 | + %9 = apply %8(%7) : $@convention(method) (@thin Wrapper.Type) -> @owned Wrapper |
| 36 | + store %9 to [init] %6 |
| 37 | + %11 = metatype $@thin NE.Type |
| 38 | + %12 = mark_unresolved_non_copyable_value [no_consume_or_assign] %6 |
| 39 | + %13 = load_borrow %12 |
| 40 | + %14 = function_ref @$s4test2NEVyAcA7WrapperVhcfC : $@convention(method) (@guaranteed Wrapper, @thin NE.Type) -> @lifetime(borrow 0) @owned NE |
| 41 | + %15 = apply %14(%13, %11) : $@convention(method) (@guaranteed Wrapper, @thin NE.Type) -> @lifetime(borrow 0) @owned NE |
| 42 | + %16 = mark_dependence [nonescaping] %15 on %5 |
| 43 | + end_borrow %13 |
| 44 | + yield %16, resume bb1, unwind bb2 |
| 45 | + |
| 46 | +bb1: |
| 47 | + destroy_value %16 |
| 48 | + end_borrow %5 |
| 49 | + destroy_value %4 |
| 50 | + destroy_value %2 |
| 51 | + %23 = tuple () |
| 52 | + return %23 |
| 53 | + |
| 54 | +bb2: |
| 55 | + destroy_value %16 |
| 56 | + end_borrow %5 |
| 57 | + destroy_value %4 |
| 58 | + destroy_value %2 |
| 59 | + unwind |
| 60 | +} |
| 61 | + |
| 62 | +// Reduced SIL for validation-test/SILOptimizer/rdar151568816.swift |
| 63 | + |
| 64 | +// CHECK-LABEL: sil hidden [ossa] @$s4test3fooyyF : |
| 65 | +// CHECK: [[W:%.*]] = alloc_box ${ let Wrapper }, let, name "w" |
| 66 | +// CHECK: [[B:%.*]] = begin_borrow [lexical] [var_decl] [[W]] : ${ let Wrapper } |
| 67 | +// CHECK: [[INITFN:%.*]] = function_ref @$s4test2NEVyAcA7WrapperVhcfC : $@convention(method) (@guaranteed Wrapper, @thin NE.Type) -> @lifetime(borrow 0) @owned NE |
| 68 | +// CHECK: [[NE:%.*]] = apply [[INITFN]]({{.*}}) : $@convention(method) (@guaranteed Wrapper, @thin NE.Type) -> @lifetime(borrow 0) @owned NE |
| 69 | +// CHECK: [[MDI:%.*]] = mark_dependence [nonescaping] [[NE]] : $NE on [[B]] : ${ let Wrapper } |
| 70 | +// CHECK-LABEL: } // end sil function '$s4test3fooyyF' |
| 71 | +sil hidden [ossa] @$s4test3fooyyF : $@convention(thin) () -> () { |
| 72 | +bb0: |
| 73 | + %0 = alloc_box ${ let MyBox }, let, name "box" |
| 74 | + %1 = begin_borrow [lexical] [var_decl] %0 |
| 75 | + %2 = project_box %1, 0 |
| 76 | + %3 = metatype $@thin MyBox.Type |
| 77 | + %4 = function_ref @$s4test5MyBoxVACycfC : $@convention(method) (@thin MyBox.Type) -> @owned MyBox |
| 78 | + %5 = apply %4(%3) : $@convention(method) (@thin MyBox.Type) -> @owned MyBox |
| 79 | + store %5 to [init] %2 |
| 80 | + %7 = mark_unresolved_non_copyable_value [no_consume_or_assign] %2 |
| 81 | + %8 = load_borrow %7 |
| 82 | + %9 = function_ref @$s4test5MyBoxV5valueAA2NEVvr : $@yield_once @convention(method) (@guaranteed MyBox) -> @lifetime(borrow 0) @yields @guaranteed NE |
| 83 | + (%10, %11) = begin_apply %9(%8) : $@yield_once @convention(method) (@guaranteed MyBox) -> @lifetime(borrow 0) @yields @guaranteed NE |
| 84 | + %12 = mark_dependence [nonescaping] %10 on %11 |
| 85 | + %13 = mark_dependence [nonescaping] %12 on %1 |
| 86 | + %14 = copy_value %13 |
| 87 | + %15 = move_value [var_decl] %14 |
| 88 | + %17 = begin_borrow %15 |
| 89 | + %18 = function_ref @$s4test3useyyAA2NEVF : $@convention(thin) (@guaranteed NE) -> () |
| 90 | + %19 = apply %18(%17) : $@convention(thin) (@guaranteed NE) -> () |
| 91 | + end_borrow %17 |
| 92 | + destroy_value %15 |
| 93 | + %22 = end_apply %11 as $() |
| 94 | + end_borrow %8 |
| 95 | + end_borrow %1 |
| 96 | + destroy_value %0 |
| 97 | + %26 = tuple () |
| 98 | + return %26 |
| 99 | +} |
| 100 | + |
0 commit comments