|
| 1 | +// RUN: %target-sil-opt %s \ |
| 2 | +// RUN: -lifetime-dependence-scope-fixup -sil-verify-all \ |
| 3 | +// RUN: -enable-experimental-feature LifetimeDependence | %FileCheck %s |
| 4 | + |
| 5 | +// REQUIRES: swift_in_compiler |
| 6 | +// REQUIRES: swift_feature_LifetimeDependence |
| 7 | + |
| 8 | +import Swift |
| 9 | +import SwiftShims |
| 10 | +import Builtin |
| 11 | + |
| 12 | +struct ArrayWrapper { |
| 13 | + private var a: [Int] |
| 14 | + var array: [Int] |
| 15 | + init(a: [Int]) |
| 16 | +} |
| 17 | + |
| 18 | +sil hidden [ossa] @$s23lifetime_dependence_cow12ArrayWrapperV5arraySaySiGvM : $@yield_once @convention(method) (@inout ArrayWrapper) -> @yields @inout Array<Int> { |
| 19 | +bb0(%0 : $*ArrayWrapper): |
| 20 | + debug_value %0, var, name "self", argno 1, expr op_deref |
| 21 | + %2 = begin_access [modify] [static] %0 |
| 22 | + %3 = struct_element_addr %2, #ArrayWrapper.a |
| 23 | + yield %3, resume bb1, unwind bb2 |
| 24 | + |
| 25 | +bb1: |
| 26 | + end_access %2 |
| 27 | + %6 = tuple () |
| 28 | + return %6 |
| 29 | + |
| 30 | +bb2: |
| 31 | + end_access %2 |
| 32 | + unwind |
| 33 | +} |
| 34 | + |
| 35 | +sil hidden_external [serialized] [available 9999] @$sSa11mutableSpans07MutableB0VyxGvg : $@convention(method) <τ_0_0> (@inout Array<τ_0_0>) -> @lifetime(borrow 0) @owned MutableSpan<τ_0_0> |
| 36 | + |
| 37 | +sil hidden_external [serialized] [available 10.14.4] @$ss11MutableSpanVsRi_zrlE7indicesSnySiGvg : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@guaranteed MutableSpan<τ_0_0>) -> Range<Int> |
| 38 | + |
| 39 | +sil [serialized] [always_inline] @$sSlss16IndexingIteratorVyxG0B0RtzrlE04makeB0ACyF : $@convention(method) <τ_0_0 where τ_0_0 : Collection, τ_0_0.Iterator == IndexingIterator<τ_0_0>> (@in τ_0_0) -> @out IndexingIterator<τ_0_0> |
| 40 | + |
| 41 | +sil [serialized] [always_inline] @$ss16IndexingIteratorV4next7ElementQzSgyF : $@convention(method) <τ_0_0 where τ_0_0 : Collection> (@inout IndexingIterator<τ_0_0>) -> @out Optional<τ_0_0.Element> |
| 42 | + |
| 43 | +sil hidden_external [serialized] [available 10.14.4] @$ss11MutableSpanVss15BitwiseCopyableRzlEyxSicis : $@convention(method) <τ_0_0 where τ_0_0 : BitwiseCopyable> (@in τ_0_0, Int, @lifetime(copy 2) @inout MutableSpan<τ_0_0>) -> () |
| 44 | + |
| 45 | +sil [transparent] [serialized] @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int |
| 46 | + |
| 47 | +sil hidden [noinline] [ossa] @$s23lifetime_dependence_cow14getMutableSpanys0eF0VySiGSaySiGzF : $@convention(thin) (@inout Array<Int>) -> @lifetime(borrow 0) @owned MutableSpan<Int> { |
| 48 | +bb0(%0 : $*Array<Int>): |
| 49 | + debug_value %0, var, name "array", argno 1, expr op_deref |
| 50 | + %2 = begin_access [modify] [static] %0 |
| 51 | + %3 = function_ref @$sSa11mutableSpans07MutableB0VyxGvg : $@convention(method) <τ_0_0> (@inout Array<τ_0_0>) -> @lifetime(borrow 0) @owned MutableSpan<τ_0_0> |
| 52 | + %4 = apply %3<Int>(%2) : $@convention(method) <τ_0_0> (@inout Array<τ_0_0>) -> @lifetime(borrow 0) @owned MutableSpan<τ_0_0> |
| 53 | + %5 = mark_dependence [nonescaping] %4 on %0 |
| 54 | + end_access %2 |
| 55 | + return %5 |
| 56 | +} |
| 57 | + |
| 58 | +// CHECK-LABEL: sil hidden [ossa] @$s23lifetime_dependence_cow9testWriteyyAA12ArrayWrapperVzF : |
| 59 | +// CHECK: [[FUN:%.*]] = function_ref @$s23lifetime_dependence_cow12ArrayWrapperV5arraySaySiGvM : $@yield_once @convention(method) (@inout ArrayWrapper) -> @yields @inout Array<Int> |
| 60 | +// CHECK: ([[Y:%.*]], [[T:%.*]]) = begin_apply %6(%5) : $@yield_once @convention(method) (@inout ArrayWrapper) -> @yields @inout Array<Int> |
| 61 | +// CHECK: end_cow_mutation_addr [[Y]] |
| 62 | +// CHECK: end_apply [[T]] as $() |
| 63 | +// CHECK-LABEL: } // end sil function '$s23lifetime_dependence_cow9testWriteyyAA12ArrayWrapperVzF' |
| 64 | +sil hidden [ossa] @$s23lifetime_dependence_cow9testWriteyyAA12ArrayWrapperVzF : $@convention(thin) (@inout ArrayWrapper) -> () { |
| 65 | +bb0(%0 : $*ArrayWrapper): |
| 66 | + debug_value %0, var, name "w", argno 1, expr op_deref |
| 67 | + %2 = alloc_box ${ var MutableSpan<Int> }, var, name "span" |
| 68 | + %3 = begin_borrow [lexical] [var_decl] %2 |
| 69 | + %4 = project_box %3, 0 |
| 70 | + %5 = begin_access [modify] [unknown] %0 |
| 71 | + %6 = function_ref @$s23lifetime_dependence_cow12ArrayWrapperV5arraySaySiGvM : $@yield_once @convention(method) (@inout ArrayWrapper) -> @yields @inout Array<Int> |
| 72 | + (%7, %8) = begin_apply %6(%5) : $@yield_once @convention(method) (@inout ArrayWrapper) -> @yields @inout Array<Int> |
| 73 | + %9 = function_ref @$s23lifetime_dependence_cow14getMutableSpanys0eF0VySiGSaySiGzF : $@convention(thin) (@inout Array<Int>) -> @lifetime(borrow 0) @owned MutableSpan<Int> |
| 74 | + %10 = apply %9(%7) : $@convention(thin) (@inout Array<Int>) -> @lifetime(borrow 0) @owned MutableSpan<Int> |
| 75 | + %11 = mark_dependence [unresolved] %10 on %7 |
| 76 | + %12 = end_apply %8 as $() |
| 77 | + end_access %5 |
| 78 | + store %11 to [init] %4 |
| 79 | + %15 = alloc_box ${ var IndexingIterator<Range<Int>> }, var, name "$i$generator" |
| 80 | + %16 = begin_borrow [var_decl] %15 |
| 81 | + %17 = project_box %16, 0 |
| 82 | + %18 = begin_access [read] [unknown] %4 |
| 83 | + %19 = mark_unresolved_non_copyable_value [no_consume_or_assign] %18 |
| 84 | + %20 = load_borrow [unchecked] %19 |
| 85 | + %21 = function_ref @$ss11MutableSpanVsRi_zrlE7indicesSnySiGvg : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@guaranteed MutableSpan<τ_0_0>) -> Range<Int> |
| 86 | + %22 = apply %21<Int>(%20) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@guaranteed MutableSpan<τ_0_0>) -> Range<Int> |
| 87 | + end_borrow %20 |
| 88 | + end_access %18 |
| 89 | + %25 = alloc_stack $Range<Int> |
| 90 | + store %22 to [trivial] %25 |
| 91 | + %27 = function_ref @$sSlss16IndexingIteratorVyxG0B0RtzrlE04makeB0ACyF : $@convention(method) <τ_0_0 where τ_0_0 : Collection, τ_0_0.Iterator == IndexingIterator<τ_0_0>> (@in τ_0_0) -> @out IndexingIterator<τ_0_0> |
| 92 | + %28 = apply %27<Range<Int>>(%17, %25) : $@convention(method) <τ_0_0 where τ_0_0 : Collection, τ_0_0.Iterator == IndexingIterator<τ_0_0>> (@in τ_0_0) -> @out IndexingIterator<τ_0_0> |
| 93 | + dealloc_stack %25 |
| 94 | + br bb1 |
| 95 | + |
| 96 | +bb1: |
| 97 | + %31 = alloc_stack $Optional<Int> |
| 98 | + %32 = begin_access [modify] [unknown] %17 |
| 99 | + %33 = function_ref @$ss16IndexingIteratorV4next7ElementQzSgyF : $@convention(method) <τ_0_0 where τ_0_0 : Collection> (@inout IndexingIterator<τ_0_0>) -> @out Optional<τ_0_0.Element> |
| 100 | + %34 = apply %33<Range<Int>>(%31, %32) : $@convention(method) <τ_0_0 where τ_0_0 : Collection> (@inout IndexingIterator<τ_0_0>) -> @out Optional<τ_0_0.Element> |
| 101 | + end_access %32 |
| 102 | + %36 = load [trivial] %31 |
| 103 | + dealloc_stack %31 |
| 104 | + switch_enum %36, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb3 |
| 105 | + |
| 106 | +bb2(%39 : $Int): |
| 107 | + %40 = move_value [var_decl] %39 |
| 108 | + debug_value %40, let, name "i" |
| 109 | + %42 = integer_literal $Builtin.IntLiteral, 0 |
| 110 | + %43 = metatype $@thin Int.Type |
| 111 | + |
| 112 | + %44 = function_ref @$sSi22_builtinIntegerLiteralSiBI_tcfC : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int |
| 113 | + %45 = apply %44(%42, %43) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int |
| 114 | + %46 = alloc_stack $Int |
| 115 | + store %45 to [trivial] %46 |
| 116 | + %48 = begin_access [modify] [unknown] %4 |
| 117 | + %49 = mark_unresolved_non_copyable_value [assignable_but_not_consumable] %48 |
| 118 | + %50 = function_ref @$ss11MutableSpanVss15BitwiseCopyableRzlEyxSicis : $@convention(method) <τ_0_0 where τ_0_0 : BitwiseCopyable> (@in τ_0_0, Int, @lifetime(copy 2) @inout MutableSpan<τ_0_0>) -> () |
| 119 | + %51 = apply %50<Int>(%46, %40, %49) : $@convention(method) <τ_0_0 where τ_0_0 : BitwiseCopyable> (@in τ_0_0, Int, @lifetime(copy 2) @inout MutableSpan<τ_0_0>) -> () |
| 120 | + end_access %48 |
| 121 | + dealloc_stack %46 |
| 122 | + extend_lifetime %40 |
| 123 | + br bb1 |
| 124 | + |
| 125 | +bb3: |
| 126 | + end_borrow %16 |
| 127 | + destroy_value %15 |
| 128 | + end_borrow %3 |
| 129 | + destroy_value %2 |
| 130 | + %60 = tuple () |
| 131 | + return %60 |
| 132 | +} |
0 commit comments