@@ -19,16 +19,6 @@ struct NCContainer : ~Copyable {
1919 }
2020}
2121
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-
3222struct View : ~ Escapable {
3323 let ptr : UnsafeRawBufferPointer
3424 let c : Int
@@ -45,7 +35,7 @@ struct View : ~Escapable {
4535 self . ptr = k. ptr
4636 self . c = k. c
4737 }
48- init ( _ k: consuming NEContainer ) {
38+ init ( _ k: consuming View ) {
4939 self . ptr = k. ptr
5040 self . c = k. c
5141 }
@@ -67,24 +57,15 @@ struct MutableView : ~Copyable, ~Escapable {
6757 self . ptr = k. ptr
6858 self . c = k. c
6959 }
70- init ( _ k: consuming NEContainer ) {
71- self . ptr = k. ptr
72- self . c = k. c
73- }
7460}
7561
7662func use( _ o : borrowing View ) { }
7763func mutate( _ x: inout NCContainer ) { }
7864func mutate( _ x: inout View ) { }
79- func mutate( _ x: inout NEContainer ) { }
8065func consume( _ o : consuming View ) { }
8166func use( _ o : borrowing MutableView ) { }
8267func consume( _ o : consuming MutableView ) { }
8368
84- func getConsumingView( _ x: consuming NEContainer ) -> _consume( x ) View {
85- return View ( x)
86- }
87-
8869func getConsumingView( _ x: consuming View ) -> _consume( x ) View {
8970 return View ( x. ptr, x. c)
9071}
@@ -97,13 +78,9 @@ func getBorrowingView(_ x: borrowing NCContainer) -> _borrow(x) View {
9778 return View ( x. ptr, x. c)
9879}
9980
100- func getBorrowingView( _ x: borrowing NEContainer ) -> _borrow( x ) View {
101- return View ( x. ptr, x. c)
102- }
103-
10481func test1( _ a: Array < Int > ) {
10582 a. withUnsafeBytes {
106- var x = NEContainer ( $0, a. count)
83+ var x = View ( $0, a. count)
10784 mutate ( & x)
10885 let view = getConsumingView ( x)
10986 let newView = View ( view)
@@ -161,7 +138,7 @@ func test4(_ a: Array<Int>) {
161138
162139func test5( _ a: Array < Int > ) {
163140 a. withUnsafeBytes {
164- let x = NEContainer ( $0, a. count)
141+ let x = View ( $0, a. count)
165142 let view = getBorrowingView ( x)
166143 let anotherView = getConsumingView ( view)
167144 use ( anotherView)
@@ -192,23 +169,27 @@ func test6(_ a: Array<Int>) {
192169// CHECK: end_access [[BA]] : $*NEContainer
193170// CHECK-LABEL: } // end sil function '$s31lifetime_dependence_scope_fixup5test7yySWF'
194171func test7( _ a: UnsafeRawBufferPointer ) {
195- var x = NEContainer ( a, a. count)
172+ var x = View ( a, a. count)
196173 do {
197174 let view = getBorrowingView ( x)
198175 use ( view)
199176 }
200177 mutate ( & x)
201178}
202179
180+ /*
181+ // Currently fails because the lifetime dependence util isn't analyzing a
182+ // def-use chain involving a stack temporary
203183func test8(_ a: Array<Int>) {
204184 a.withUnsafeBytes {
205- var x = NEContainer ( $0, a. count)
185+ var x = View ($0, a.count)
206186 mutate(&x)
207187 let view = MutableView(x)
208188 use(view)
209189 consume(view)
210190 }
211191}
192+ */
212193
213194struct Wrapper : ~ Escapable {
214195 var _view : View
@@ -235,3 +216,19 @@ func test9() {
235216 }
236217}
237218
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