1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
// RUN: %target-sil-opt -test-runner %s \
// RUN: -module-name Swift \
// RUN: -enable-experimental-feature NonescapableTypes \
// RUN: -o /dev/null 2>&1 | %FileCheck %s
// REQUIRES: asserts
// REQUIRES: swift_in_compiler
sil_stage canonical
import Builtin
@_marker protocol Copyable: ~Escapable {}
@_marker protocol Escapable: ~Copyable {}
struct NCNEInt: ~Copyable, ~Escapable {
var i: Builtin.Int64
@_unsafeNonescapableResult
init() {}
deinit {}
}
enum FakeOptional<T> {
case none
case some(T)
}
class C {}
sil @getC : $@convention(thin) () -> @owned C
sil @foo : $@convention(thin) () -> ()
struct PairC {
var first: C
var second: C
}
class D: C {
var object: C
@_borrowed var field: C { get }
}
sil @d_field_read : $@yield_once @convention(method) (@guaranteed D) -> @yields @guaranteed C
sil_vtable D {
#D.field!read: @d_field_read
}
struct NE : ~Escapable {
var d: D
@_unsafeNonescapableResult
init() { }
}
struct NEWrap : ~Escapable {
var ne: NE
@_unsafeNonescapableResult
init() { }
}
sil @coroutine : $@yield_once @convention(method) (@guaranteed NE) -> @yields @guaranteed NE
sil @capture : $@convention(thin) (@guaranteed NE) -> ()
sil @captureOwned : $@convention(thin) (@owned NE) -> ()
sil [ossa] @variable_introducer : $@convention(thin) (@owned C) -> () {
entry(%0 : @owned $C):
%1 = move_value [var_decl] %0 : $C
%move = move_value %1 : $C
specify_test "variable_introducer %move"
// CHECK-LABEL: variable_introducer: variable_introducer with: %move
// CHECK: Variable introducers of: %{{.*}} = move_value %{{.*}} : $C
// CHECK-NEXT: [ %{{.*}} = move_value [var_decl] %0 : $C
// CHECK-NEXT: variable_introducer: variable_introducer with: %move
%3 = begin_borrow [var_decl] %move : $C
%borrow = begin_borrow %3 : $C
specify_test "variable_introducer %borrow"
// CHECK-LABEL: variable_introducer: variable_introducer with: %borrow
// CHECK: Variable introducers of: %{{.*}} = begin_borrow %{{.*}} : $C
// CHECK-NEXT: [ %{{.*}} = begin_borrow [var_decl] %{{.*}} : $C
// CHECK-NEXT: variable_introducer: variable_introducer with: %borrow
end_borrow %borrow : $C
end_borrow %3 : $C
destroy_value %move : $C
%99 = tuple()
return %99 : $()
}
sil [ossa] @dependence_scope : $@convention(thin) (@owned C, @owned D, @guaranteed D, @in_guaranteed D, @inout D) -> () {
entry(%0 : @owned $C, %1 : @owned $D, %2 : @guaranteed $D, %3 : $*D, %4 : $*D):
%move = move_value %1 : $D
%owned_mark = mark_dependence [nonescaping] %0 : $C on %move : $D
specify_test "lifetime_dependence_scope %owned_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %owned_mark
// CHECK-NEXT: Owned: %{{.*}} = move_value %{{.*}} : $D
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %0 : $C on %{{.*}} : $D
// CHECK-NEXT: begin: %{{.*}} = move_value %{{.*}} : $D
// CHECK-NEXT: ends: destroy_value %{{.*}} : $D
// CHECK: dependence_scope: lifetime_dependence_scope with: %owned_mark
%borrow = begin_borrow %2 : $D
%d2c = upcast %borrow : $D to $C
%pair = struct $PairC(%d2c : $C, %d2c : $C)
%guaranteed_mark = mark_dependence [nonescaping] %owned_mark : $C on %pair : $PairC
specify_test "lifetime_dependence_scope %guaranteed_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %guaranteed_mark
// CHECK-NEXT: Caller: %2 = argument of bb0 : $D
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %{{.*}} : $PairC
// CHECK-NEXT: Caller range
// CHECK: dependence_scope: lifetime_dependence_scope with: %guaranteed_mark
%m = class_method %2 : $D, #D.field!read : (D) -> () -> (), $@yield_once @convention(method) (@guaranteed D) -> @yields @guaranteed C
(%yield, %token) = begin_apply %m(%2) : $@yield_once @convention(method) (@guaranteed D) -> @yields @guaranteed C
%yield_mark = mark_dependence [nonescaping] %guaranteed_mark : $C on %yield : $C
specify_test "lifetime_dependence_scope %yield_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %yield_mark
// CHECK-NEXT: Yield: (**%{{.*}}**, %{{.*}}) = begin_apply %{{.*}}(%{{.*}}) : $@yield_once @convention(method) (@guaranteed D) -> @yields @guaranteed C
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %{{.*}} : $C
// CHECK-NEXT: begin: (%{{.*}}, %{{.*}}) = begin_apply %{{.*}}(%{{.*}}) : $@yield_once @convention(method) (@guaranteed D) -> @yields @guaranteed C
// CHECK-NEXT: ends: end_apply %{{.*}}
// CHECK: dependence_scope: lifetime_dependence_scope with: %yield_mark
%zero = integer_literal $Builtin.Int1, 0
%trivial_mark = mark_dependence [nonescaping] %yield_mark : $C on %zero : $Builtin.Int1
specify_test "lifetime_dependence_scope %trivial_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %trivial_mark
// CHECK-NEXT: Trivial Dependence
// CHECK: dependence_scope: lifetime_dependence_scope with: %trivial_mark
%f = ref_element_addr %borrow : $D, #D.object
%access = begin_access [read] [static] %f : $*C
%access_mark = mark_dependence [nonescaping] %trivial_mark : $C on %access : $*C
specify_test "lifetime_dependence_scope %access_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %access_mark
// CHECK-NEXT: Access: %{{.*}} = begin_access [read] [static] %{{.*}} : $*C
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %{{.*}} : $*C
// CHECK-NEXT: begin: %{{.*}} = begin_access [read] [static] %{{.*}} : $*C
// CHECK-NEXT: ends: end_access %{{.*}} : $*C
// CHECK: dependence_scope: lifetime_dependence_scope with: %access_mark
%guaranteed_arg_mark = mark_dependence [nonescaping] %access_mark : $C on %2 : $D
specify_test "lifetime_dependence_scope %guaranteed_arg_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %guaranteed_arg_mark
// CHECK-NEXT: Caller: %2 = argument of bb0 : $D
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %2 : $D
// CHECK-NEXT: Caller range
// CHECK: dependence_scope: lifetime_dependence_scope with: %guaranteed_arg_mark
%inguaranteed_arg_mark = mark_dependence [nonescaping] %guaranteed_arg_mark : $C on %3 : $*D
specify_test "lifetime_dependence_scope %inguaranteed_arg_mark"
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %inguaranteed_arg_mark
// CHECK-NEXT: Initialized: %3 = argument of bb0 : $*D
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %3 : $*D
// CHECK-NEXT: begin: %{{.*}} = move_value %{{.*}} : $D
// CHECK-NEXT: ends:
// CHECK: dependence_scope: lifetime_dependence_scope with: %inguaranteed_arg_mark
%inout_arg_mark = mark_dependence [nonescaping] %inguaranteed_arg_mark : $C on %4 : $*D
specify_test "lifetime_dependence_scope %inout_arg_mark"
// @inout arguments are expected to have an access scope.
// A direct dependence on an @inout argument is considered "Unknown".
//
// CHECK-LABEL: dependence_scope: lifetime_dependence_scope with: %inout_arg_mark
// CHECK-NEXT: Unknown: %4 = argument of bb0 : $*D
// CHECK-NEXT: Dependent: %{{.*}} = mark_dependence [nonescaping] %{{.*}} : $C on %4 : $*D
// CHECK: dependence_scope: lifetime_dependence_scope with: %inout_arg_mark
destroy_value %inout_arg_mark : $C
end_access %access : $*C
end_apply %token
end_borrow %borrow : $D
destroy_value %move : $D
%99 = tuple()
return %99 : $()
}
sil [ossa] @dependence_root : $@convention(thin) (@owned D, @owned C) -> () {
entry(%0 : @owned $D, %1 : @owned $C):
%copy = copy_value %0 : $D
%move = move_value %copy : $D
%borrow = begin_borrow %move : $D
%d2c = upcast %borrow : $D to $C
%pair = struct $PairC(%d2c : $C, %d2c : $C)
%mark_pair = mark_dependence [nonescaping] %1 : $C on %pair : $PairC
specify_test "lifetime_dependence_root %mark_pair"
// CHECK-LABEL: dependence_root: lifetime_dependence_root with: %mark_pair
// CHECK-NEXT: Scope: Owned: %0 = argument of bb0 : $D
// CHECK-NEXT: dependence_root: lifetime_dependence_root with: %mark_pair
%f = ref_element_addr %borrow : $D, #D.object
%access = begin_access [read] [static] %f : $*C
%load = load [copy] %access : $*C
specify_test "lifetime_dependence_root %load"
// CHECK-LABEL: dependence_root: lifetime_dependence_root with: %load
// CHECK-NEXT: Scope: Access: %{{.*}} = begin_access [read] [static] %{{.*}} : $*C
// CHECK-NEXT: dependence_root: lifetime_dependence_root with: %load
destroy_value %load : $C
end_access %access : $*C
destroy_value %mark_pair : $C
end_borrow %borrow : $D
destroy_value %move : $D
destroy_value %0 : $D
%99 = tuple()
return %99 : $()
}
// CHECK-LABEL: dependence_access: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $*NE
// CHECK-NEXT: Leaf use: operand #0 of end_access %{{.*}} : $*NE
// CHECK-NEXT: dependence_access: lifetime_dependence_use with: %0
sil [ossa] @dependence_access : $@convention(thin) (@inout NE, @owned C) -> () {
bb0(%0 : $*NE, %1 : @owned $C):
specify_test "lifetime_dependence_use %0"
%access = begin_access [read] [static] %0 : $*NE
%dependence = mark_dependence [nonescaping] %1: $C on %access: $*NE
%stack = alloc_stack $C
%sb = store_borrow %dependence to %stack : $*C
end_borrow %sb : $*C
destroy_value %dependence : $C
end_access %access : $*NE
dealloc_stack %stack : $*C
%99 = tuple()
return %99 : $()
}
// CHECK-LABEL: dependence_borrow: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Leaf use: operand #0 of end_borrow %{{.*}} : $NE
// CHECK-NEXT: Leaf use: operand #0 of end_borrow %{{.*}} : $*NE
// CHECK-NEXT: Leaf use: operand #0 of %{{.*}} = load [copy] %{{.*}} : $*NE
// CHECK-NEXT: Leaf use: operand #0 of destroy_value %{{.*}} : $NE
// CHECK-NEXT: dependence_borrow: lifetime_dependence_use with: %0
sil [ossa] @dependence_borrow : $@convention(thin) (@guaranteed NE) -> () {
bb0(%0 : @guaranteed $NE):
specify_test "lifetime_dependence_use %0"
%borrow = begin_borrow %0 : $NE
%stack = alloc_stack $NE
%sb = store_borrow %borrow to %stack : $*NE
%load = load [copy] %sb : $*NE
end_borrow %sb : $*NE
dealloc_stack %stack : $*NE
end_borrow %borrow : $NE
destroy_value %load : $NE
%99 = tuple()
return %99 : $()
}
// CHECK-LABEL: dependence_coroutine: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Leaf use: operand #0 of end_apply %{{.*}}
// CHECK-NEXT: dependence_coroutine: lifetime_dependence_use with: %0
sil [ossa] @dependence_coroutine : $@convention(thin) (@guaranteed NE) -> () {
bb0(%0 : @guaranteed $NE):
specify_test "lifetime_dependence_use %0"
%coroutine = function_ref @coroutine : $@yield_once @convention(method) (@guaranteed NE) -> @yields @guaranteed NE
(%yield, %token) = begin_apply %coroutine(%0) : $@yield_once @convention(method) (@guaranteed NE) -> @yields @guaranteed NE
%copy = copy_value %yield : $NE
end_apply %token
destroy_value %copy : $NE
%99 = tuple()
return %99 : $()
}
// CHECK-LABEL: dependence_markdep: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Leaf use: operand #0 of destroy_value %{{.*}} : $NE
// CHECK-NEXT: dependence_markdep: lifetime_dependence_use with: %0
sil [ossa] @dependence_markdep : $@convention(thin) (@guaranteed NE, @owned NE) -> () {
bb0(%0 : @guaranteed $NE, %1 : @owned $NE):
specify_test "lifetime_dependence_use %0"
%dependence = mark_dependence [nonescaping] %0: $NE on %1: $NE
%copy = copy_value %dependence : $NE
destroy_value %copy : $NE
destroy_value %1 : $NE
%99 = tuple()
return %99 : $()
}
// FIXME: the lifetime uses should include the final destroy_value
// %noescape, but partial_apply on_stack "incorrectly" returns an
// escaping function type.
//
// CHECK-LABEL: dependence_noescape_closure: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Leaf use: operand #0 of destroy_value %{{.*}} : $@noescape @callee_guaranteed () -> ()
// CHECK-NEXT: Leaf use: operand #0 of %{{.*}} = apply %{{.*}}() : $@noescape @callee_guaranteed () -> ()
// CHECK-NEXT: dependence_noescape_closure: lifetime_dependence_use with: %0
sil [ossa] @dependence_noescape_closure : $@convention(thin) (@guaranteed NE) -> () {
bb0(%0 : @guaranteed $NE):
specify_test "lifetime_dependence_use %0"
%f = function_ref @capture : $@convention(thin) (@guaranteed NE) -> ()
%noescape = partial_apply [callee_guaranteed] [on_stack] %f(%0) : $@convention(thin) (@guaranteed NE) -> ()
%call = apply %noescape() : $@noescape @callee_guaranteed () -> ()
destroy_value %noescape : $@noescape @callee_guaranteed () -> ()
%99 = tuple ()
return %99: $()
}
// CHECK-LABEL: dependence_closure: lifetime_dependence_use with: %0
// CHECK-NEXT: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Escaping use: operand #1 of %{{.*}} = partial_apply [callee_guaranteed] %{{.*}}(%0) : $@convention(thin) (@owned NE) -> ()
// CHECK-NEXT: dependence_closure: lifetime_dependence_use with: %0
sil [ossa] @dependence_closure : $@convention(thin) (@owned NE) -> () {
bb0(%0 : @owned $NE):
specify_test "lifetime_dependence_use %0"
%f = function_ref @captureOwned : $@convention(thin) (@owned NE) -> ()
%closure = partial_apply [callee_guaranteed] %f(%0) : $@convention(thin) (@owned NE) -> ()
%borrow = begin_borrow %closure : $@callee_guaranteed () -> ()
%call = apply %borrow() : $@callee_guaranteed () -> ()
end_borrow %borrow : $@callee_guaranteed () -> ()
destroy_value %closure : $@callee_guaranteed () -> ()
%99 = tuple ()
return %99: $()
}
// CHECK-LABEL: dependence_forward: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NE
// CHECK-NEXT: Leaf use: operand #0 of destroy_value %{{.*}} : $NEWrap
// CHECK-NEXT: dependence_forward: lifetime_dependence_use with: %0
sil [ossa] @dependence_forward : $@convention(thin) (@owned NE) -> () {
bb0(%0 : @owned $NE):
specify_test "lifetime_dependence_use %0"
%1 = struct $NEWrap(%0 : $NE)
%2 = copyable_to_moveonlywrapper [owned] %1 : $NEWrap
%3 = moveonlywrapper_to_copyable [owned] %2 : $@moveOnly NEWrap
destroy_value %3 : $NEWrap
%99 = tuple()
return %99 : $()
}
// CHECK-LABEL: begin running test 1 of 1 on testInteriorDropDeinit: lifetime_dependence_use with: %0
// CHECK: LifetimeDependence uses of: %0 = argument of bb0 : $NCNEInt
// CHECK-NEXT: Leaf use: operand #0 of destroy_value
// CHECK-LABEL: end running test 1 of 1 on testInteriorDropDeinit: lifetime_dependence_use with: %0
sil [ossa] @testInteriorDropDeinit : $@convention(thin) (@owned NCNEInt) -> () {
bb0(%0 : @owned $NCNEInt):
specify_test "lifetime_dependence_use %0"
%nd = drop_deinit %0 : $NCNEInt
destroy_value %nd : $NCNEInt
%99 = tuple()
return %99 : $()
}
|