|
8 | 8 | // REQUIRES: asserts
|
9 | 9 | // REQUIRES: swift_in_compiler
|
10 | 10 |
|
| 11 | +// Some container-ish thing. |
| 12 | +struct CN: ~Copyable { |
| 13 | + let p: UnsafeRawPointer |
| 14 | + let i: Int |
| 15 | +} |
| 16 | + |
| 17 | +// Some Bufferview-ish thing. |
11 | 18 | @_nonescapable
|
12 | 19 | struct BV {
|
13 | 20 | let p: UnsafeRawPointer
|
14 |
| - let c: Int |
| 21 | + let i: Int |
15 | 22 |
|
16 |
| - public var isEmpty: Bool { c == 0 } |
| 23 | + public var isEmpty: Bool { i == 0 } |
17 | 24 |
|
18 | 25 | @_unsafeNonescapableResult
|
19 |
| - init(_ p: UnsafeRawPointer, _ c: Int) { |
| 26 | + init(_ p: UnsafeRawPointer, _ i: Int) { |
20 | 27 | 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 |
22 | 34 | }
|
23 | 35 | }
|
24 | 36 |
|
| 37 | +// Some MutableBufferview-ish thing. |
25 | 38 | @_nonescapable
|
26 |
| -struct NCNE : ~Copyable { |
| 39 | +struct MBV : ~Copyable { |
27 | 40 | let p: UnsafeRawPointer
|
28 |
| - let c: Int |
| 41 | + let i: Int |
29 | 42 |
|
30 | 43 | @_unsafeNonescapableResult
|
31 |
| - init(_ p: UnsafeRawPointer, _ c: Int) { |
| 44 | + init(_ p: UnsafeRawPointer, _ i: Int) { |
32 | 45 | self.p = p
|
33 |
| - self.c = c |
| 46 | + self.i = i |
34 | 47 | }
|
35 | 48 |
|
36 | 49 | // Requires a borrow.
|
37 | 50 | 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 |
39 | 62 | }
|
40 | 63 | }
|
41 | 64 |
|
42 | 65 | // 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 { |
44 | 67 | container.getBV()
|
45 | 68 | }
|
46 | 69 |
|
47 | 70 | // 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 { |
49 | 72 | return container.getBV()
|
50 | 73 | }
|
51 | 74 |
|
52 | 75 | // 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 { |
54 | 77 | container.getBV()
|
55 | 78 | }
|
| 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 | +} |
0 commit comments