|
| 1 | +// RUN: %target-run-simple-swift(-parse-as-library -Xfrontend -sil-verify-all -enable-experimental-feature MoveOnlyPartialConsumption) | %FileCheck %s |
| 2 | +// RUN: %target-run-simple-swift(-parse-as-library -O -Xfrontend -sil-verify-all -enable-experimental-feature MoveOnlyPartialConsumption) | %FileCheck %s |
| 3 | + |
| 4 | +// REQUIRES: executable_test |
| 5 | + |
| 6 | +@main struct App { static func main() { |
| 7 | + test1() |
| 8 | +}} |
| 9 | + |
| 10 | +func barrier() { print("barrier") } |
| 11 | + |
| 12 | +struct Ur : ~Copyable { |
| 13 | + var name: String |
| 14 | + init(named name: String) { |
| 15 | + self.name = name |
| 16 | + print("hi", name) |
| 17 | + } |
| 18 | + deinit { |
| 19 | + print("bye", name) |
| 20 | + } |
| 21 | +} |
| 22 | +func take(_ u: consuming Ur) {} |
| 23 | + |
| 24 | +struct Pair : ~Copyable { |
| 25 | + var u1: Ur |
| 26 | + var u2: Ur |
| 27 | + init(named name: String) { |
| 28 | + u1 = .init(named: "\(name).u1") |
| 29 | + u2 = .init(named: "\(name).u2") |
| 30 | + } |
| 31 | +} |
| 32 | +func take(_ u: consuming Pair) {} |
| 33 | + |
| 34 | +struct Quad : ~Copyable { |
| 35 | + var p1: Pair |
| 36 | + var p2: Pair |
| 37 | + init(named name: String) { |
| 38 | + p1 = .init(named: "\(name).p1") |
| 39 | + p2 = .init(named: "\(name).p2") |
| 40 | + } |
| 41 | +} |
| 42 | +func take(_ u: consuming Quad) {} |
| 43 | + |
| 44 | +func test1() { |
| 45 | +do { |
| 46 | + let q1 = Quad(named: "\(#function).q1") |
| 47 | + barrier() |
| 48 | + // CHECK: barrier |
| 49 | + // CHECK: bye test1().q1.p1.u1 |
| 50 | + // CHECK: bye test1().q1.p1.u2 |
| 51 | + // CHECK: bye test1().q1.p2.u1 |
| 52 | + // CHECK: bye test1().q1.p2.u2 |
| 53 | +} |
| 54 | + |
| 55 | + let q2 = Quad(named: "\(#function).q2") |
| 56 | + take(q2.p2.u2) |
| 57 | + take(q2.p2.u1) |
| 58 | + barrier() |
| 59 | + take(q2.p1.u2) |
| 60 | + take(q2.p1.u1) |
| 61 | + // CHECK: bye test1().q2.p2.u2 |
| 62 | + // CHECK: bye test1().q2.p2.u1 |
| 63 | + // CHECK: barrier |
| 64 | + // CHECK: bye test1().q2.p1.u2 |
| 65 | + // CHECK: bye test1().q2.p1.u1 |
| 66 | + |
| 67 | + let q3 = Quad(named: "\(#function).q3") |
| 68 | + _ = consume q3.p2.u2 |
| 69 | + _ = consume q3.p2.u1 |
| 70 | + _ = consume q3.p1.u2 |
| 71 | + barrier() |
| 72 | + _ = consume q3.p1.u1 |
| 73 | + // CHECK: bye test1().q3.p2.u2 |
| 74 | + // CHECK: bye test1().q3.p2.u1 |
| 75 | + // CHECK: bye test1().q3.p1.u2 |
| 76 | + // CHECK: barrier |
| 77 | + // CHECK: bye test1().q3.p1.u1 |
| 78 | + |
| 79 | + let q4 = Quad(named: "\(#function).q4") |
| 80 | + _ = consume q4.p1.u1 |
| 81 | + barrier() |
| 82 | + _ = consume q4.p2.u1 |
| 83 | + _ = consume q4.p1.u2 |
| 84 | + _ = consume q4.p2.u2 |
| 85 | + // CHECK: bye test1().q4.p1.u1 |
| 86 | + // CHECK: barrier |
| 87 | + // CHECK: bye test1().q4.p2.u1 |
| 88 | + // CHECK: bye test1().q4.p1.u2 |
| 89 | + // CHECK: bye test1().q4.p2.u2 |
| 90 | + |
| 91 | +do { |
| 92 | + let q5 = Quad(named: "\(#function).q5") |
| 93 | + take(q5.p1.u1) |
| 94 | + _ = consume q5.p2.u1 |
| 95 | + _ = consume q5.p1.u2 |
| 96 | + take(q5.p2.u2) |
| 97 | + // CHECK: bye test1().q5.p1.u1 |
| 98 | + // CHECK: bye test1().q5.p2.u1 |
| 99 | + // CHECK: bye test1().q5.p1.u2 |
| 100 | + // CHECK: bye test1().q5.p2.u2 |
| 101 | +} |
| 102 | +do { |
| 103 | + let q6 = Quad(named: "\(#function).q6") |
| 104 | + if Bool.random() { |
| 105 | + take(q6.p1.u1) |
| 106 | + _ = consume q6.p2.u1 |
| 107 | + } else { |
| 108 | + _ = consume q6.p1.u2 |
| 109 | + take(q6.p2.u2) |
| 110 | + } |
| 111 | +} |
| 112 | +} |
| 113 | + |
0 commit comments