Skip to content

Commit 4ca9867

Browse files
committed
Add test: lifetime_dependence/scopefixup.sil
1 parent 8db7dc3 commit 4ca9867

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// RUN: %target-sil-opt %s \
2+
// RUN: --lifetime-dependence-scope-fixup \
3+
// RUN: -sil-verify-all \
4+
// RUN: -enable-experimental-feature LifetimeDependence \
5+
// RUN: -enable-experimental-feature LifetimeDependenceDiagnoseTrivial \
6+
// RUN: 2>&1 | %FileCheck %s
7+
8+
// REQUIRES: swift_in_compiler
9+
// REQUIRES: swift_feature_LifetimeDependence
10+
11+
// Test the SIL representation for lifetime dependence scope fixup.
12+
13+
sil_stage raw
14+
15+
import Builtin
16+
import Swift
17+
18+
struct NE : ~Escapable {
19+
}
20+
21+
struct Wrapper : ~Escapable {
22+
@_hasStorage var _ne: NE { get set }
23+
var ne: NE { get set } // _read
24+
init(_ ne: consuming NE)
25+
}
26+
27+
struct NCContainer : ~Copyable {
28+
@_hasStorage let ptr: UnsafeRawBufferPointer { get }
29+
@_hasStorage let c: Int { get }
30+
init(_ ptr: UnsafeRawBufferPointer, _ c: Int)
31+
var ne: NE { get } // _read
32+
var wrapper: Wrapper { get } // _read
33+
}
34+
35+
sil [ossa] @Wrapper_init : $@convention(method) (@owned NE, @thin Wrapper.Type) -> @lifetime(copy 0) @owned Wrapper
36+
37+
sil [ossa] @NCContainer_ne_read : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed NE
38+
39+
// NCContainer.wrapper._read:
40+
// var wrapper: Wrapper {
41+
// _read {
42+
// yield Wrapper(view)
43+
// }
44+
// }
45+
//
46+
// Sink end_apply into the resume and unwind paths.
47+
//
48+
// CHECK-LABEL: sil hidden [ossa] @NCContainer_wrapper_read : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper {
49+
// CHECK: ([[YIELD:%.*]], [[TOKEN:%.*]]) = begin_apply %{{.*}}(%0) : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed NE
50+
// CHECK: [[MD:%.*]] = mark_dependence [unresolved] [[YIELD]] on [[TOKEN]]
51+
// CHECK: [[CP:%.*]] = copy_value [[MD]]
52+
// CHECK: [[WRAPPER:%.*]] = apply %{{.*}}([[CP]], %{{.*}}) : $@convention(method) (@owned NE, @thin Wrapper.Type) -> @lifetime(copy 0) @owned Wrapper
53+
// CHECK: yield [[WRAPPER]], resume bb1, unwind bb2
54+
// CHECK: bb1:
55+
// CHECK: destroy_value [[WRAPPER]]
56+
// CHECK: end_apply [[TOKEN]] as $()
57+
// CHECK: return
58+
// CHECK: bb2:
59+
// CHECK: destroy_value [[WRAPPER]]
60+
// CHECK: end_apply [[TOKEN]] as $()
61+
// CHECK: unwind
62+
// CHECK-LABEL: } // end sil function 'NCContainer_wrapper_read'
63+
sil hidden [ossa] @NCContainer_wrapper_read : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed Wrapper {
64+
bb0(%0 : @guaranteed $NCContainer):
65+
debug_value %0, let, name "self", argno 1
66+
%2 = metatype $@thin Wrapper.Type
67+
%3 = function_ref @NCContainer_ne_read : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed NE
68+
(%4, %5) = begin_apply %3(%0) : $@yield_once @convention(method) (@guaranteed NCContainer) -> @lifetime(borrow 0) @yields @guaranteed NE
69+
%6 = mark_dependence [unresolved] %4 on %5
70+
%7 = copy_value %6
71+
%8 = end_apply %5 as $()
72+
%9 = function_ref @Wrapper_init : $@convention(method) (@owned NE, @thin Wrapper.Type) -> @lifetime(copy 0) @owned Wrapper
73+
%10 = apply %9(%7, %2) : $@convention(method) (@owned NE, @thin Wrapper.Type) -> @lifetime(copy 0) @owned Wrapper
74+
yield %10, resume bb1, unwind bb2
75+
76+
bb1:
77+
destroy_value %10
78+
%13 = tuple ()
79+
return %13
80+
81+
bb2:
82+
destroy_value %10
83+
unwind
84+
}

0 commit comments

Comments
 (0)