Skip to content

Commit 9318928

Browse files
committed
LifetimeDependence stored property unit tests
1 parent 08be9ae commit 9318928

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

test/SILOptimizer/lifetime_dependence_borrow.swift

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,78 @@
88
// REQUIRES: asserts
99
// REQUIRES: swift_in_compiler
1010

11+
// Some container-ish thing.
12+
struct CN: ~Copyable {
13+
let p: UnsafeRawPointer
14+
let i: Int
15+
}
16+
17+
// Some Bufferview-ish thing.
1118
@_nonescapable
1219
struct BV {
1320
let p: UnsafeRawPointer
14-
let c: Int
21+
let i: Int
1522

16-
public var isEmpty: Bool { c == 0 }
23+
public var isEmpty: Bool { i == 0 }
1724

1825
@_unsafeNonescapableResult
19-
init(_ p: UnsafeRawPointer, _ c: Int) {
26+
init(_ p: UnsafeRawPointer, _ i: Int) {
2027
self.p = p
21-
self.c = c
28+
self.i = i
29+
}
30+
31+
init(_ cn: borrowing CN) {
32+
self.p = cn.p
33+
self.i = cn.i
2234
}
2335
}
2436

37+
// Some MutableBufferview-ish thing.
2538
@_nonescapable
26-
struct NCNE : ~Copyable {
39+
struct MBV : ~Copyable {
2740
let p: UnsafeRawPointer
28-
let c: Int
41+
let i: Int
2942

3043
@_unsafeNonescapableResult
31-
init(_ p: UnsafeRawPointer, _ c: Int) {
44+
init(_ p: UnsafeRawPointer, _ i: Int) {
3245
self.p = p
33-
self.c = c
46+
self.i = i
3447
}
3548

3649
// Requires a borrow.
3750
borrowing func getBV() -> _borrow(self) BV {
38-
BV(p, c)
51+
BV(p, i)
52+
}
53+
}
54+
55+
// Nonescapable wrapper.
56+
@_nonescapable
57+
struct NEBV {
58+
var bv: BV
59+
60+
init(_ bv: consuming BV) {
61+
self.bv = bv
3962
}
4063
}
4164

4265
// Propagate a borrow.
43-
func bv_get_borrow(container: borrowing NCNE) -> _borrow(container) BV {
66+
func bv_get_borrow(container: borrowing MBV) -> _borrow(container) BV {
4467
container.getBV()
4568
}
4669

4770
// Copy a borrow.
48-
func bv_get_copy(container: borrowing NCNE) -> _copy(container) BV {
71+
func bv_get_copy(container: borrowing MBV) -> _copy(container) BV {
4972
return container.getBV()
5073
}
5174

5275
// Recognize nested accesses as part of the same dependence scope.
53-
func bv_get_mutate(container: inout NCNE) -> _mutate(container) BV {
76+
func bv_get_mutate(container: inout MBV) -> _mutate(container) BV {
5477
container.getBV()
5578
}
79+
80+
// Create and decompose a nonescapable aggregate.
81+
func ne_wrap_and_extract_member(cn: borrowing CN) -> _borrow(cn) BV {
82+
let bv = BV(cn)
83+
let ne = NEBV(bv)
84+
return ne.bv
85+
}

test/SILOptimizer/lifetime_dependence_inherit.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ struct NE {
4141
func bv_derive(bv: consuming BV) -> _consume(bv) BV {
4242
bv.derive()
4343
}
44+
45+
// Test lifetime inheritance through stored properties.
46+
func ne_extract_member(ne: consuming NE) -> _consume(ne) BV {
47+
return ne.bv
48+
}

0 commit comments

Comments
 (0)