@@ -19,16 +19,6 @@ struct NCContainer : ~Copyable {
19
19
}
20
20
}
21
21
22
- struct NEContainer : ~ Escapable {
23
- let ptr : UnsafeRawBufferPointer
24
- let c : Int
25
- @_unsafeNonescapableResult
26
- init ( _ ptr: UnsafeRawBufferPointer , _ c: Int ) {
27
- self . ptr = ptr
28
- self . c = c
29
- }
30
- }
31
-
32
22
struct View : ~ Escapable {
33
23
let ptr : UnsafeRawBufferPointer
34
24
let c : Int
@@ -45,7 +35,7 @@ struct View : ~Escapable {
45
35
self . ptr = k. ptr
46
36
self . c = k. c
47
37
}
48
- init ( _ k: consuming NEContainer ) {
38
+ init ( _ k: consuming View ) {
49
39
self . ptr = k. ptr
50
40
self . c = k. c
51
41
}
@@ -67,24 +57,15 @@ struct MutableView : ~Copyable, ~Escapable {
67
57
self . ptr = k. ptr
68
58
self . c = k. c
69
59
}
70
- init ( _ k: consuming NEContainer ) {
71
- self . ptr = k. ptr
72
- self . c = k. c
73
- }
74
60
}
75
61
76
62
func use( _ o : borrowing View ) { }
77
63
func mutate( _ x: inout NCContainer ) { }
78
64
func mutate( _ x: inout View ) { }
79
- func mutate( _ x: inout NEContainer ) { }
80
65
func consume( _ o : consuming View ) { }
81
66
func use( _ o : borrowing MutableView ) { }
82
67
func consume( _ o : consuming MutableView ) { }
83
68
84
- func getConsumingView( _ x: consuming NEContainer ) -> _consume( x ) View {
85
- return View ( x)
86
- }
87
-
88
69
func getConsumingView( _ x: consuming View ) -> _consume( x ) View {
89
70
return View ( x. ptr, x. c)
90
71
}
@@ -97,13 +78,9 @@ func getBorrowingView(_ x: borrowing NCContainer) -> _borrow(x) View {
97
78
return View ( x. ptr, x. c)
98
79
}
99
80
100
- func getBorrowingView( _ x: borrowing NEContainer ) -> _borrow( x ) View {
101
- return View ( x. ptr, x. c)
102
- }
103
-
104
81
func test1( _ a: Array < Int > ) {
105
82
a. withUnsafeBytes {
106
- var x = NEContainer ( $0, a. count)
83
+ var x = View ( $0, a. count)
107
84
mutate ( & x)
108
85
let view = getConsumingView ( x)
109
86
let newView = View ( view)
@@ -161,7 +138,7 @@ func test4(_ a: Array<Int>) {
161
138
162
139
func test5( _ a: Array < Int > ) {
163
140
a. withUnsafeBytes {
164
- let x = NEContainer ( $0, a. count)
141
+ let x = View ( $0, a. count)
165
142
let view = getBorrowingView ( x)
166
143
let anotherView = getConsumingView ( view)
167
144
use ( anotherView)
@@ -192,23 +169,27 @@ func test6(_ a: Array<Int>) {
192
169
// CHECK: end_access [[BA]] : $*NEContainer
193
170
// CHECK-LABEL: } // end sil function '$s31lifetime_dependence_scope_fixup5test7yySWF'
194
171
func test7( _ a: UnsafeRawBufferPointer ) {
195
- var x = NEContainer ( a, a. count)
172
+ var x = View ( a, a. count)
196
173
do {
197
174
let view = getBorrowingView ( x)
198
175
use ( view)
199
176
}
200
177
mutate ( & x)
201
178
}
202
179
180
+ /*
181
+ // Currently fails because the lifetime dependence util isn't analyzing a
182
+ // def-use chain involving a stack temporary
203
183
func test8(_ a: Array<Int>) {
204
184
a.withUnsafeBytes {
205
- var x = NEContainer ( $0, a. count)
185
+ var x = View ($0, a.count)
206
186
mutate(&x)
207
187
let view = MutableView(x)
208
188
use(view)
209
189
consume(view)
210
190
}
211
191
}
192
+ */
212
193
213
194
struct Wrapper : ~ Escapable {
214
195
var _view : View
@@ -235,3 +216,19 @@ func test9() {
235
216
}
236
217
}
237
218
219
+ func getViewTuple( _ x: borrowing View ) -> ( View , View ) {
220
+ return ( View ( x. ptr, x. c) , View ( x. ptr, x. c) )
221
+ }
222
+
223
+ public func test10( ) {
224
+ let a = [ Int] ( repeating: 0 , count: 4 )
225
+ a. withUnsafeBytes {
226
+ var x = View ( $0, a. count)
227
+ mutate ( & x)
228
+ let view = getBorrowingView ( x)
229
+ let tuple = getViewTuple ( view)
230
+ use ( tuple. 0 )
231
+ use ( tuple. 1 )
232
+ }
233
+ }
234
+
0 commit comments