Skip to content

Commit 7f6da3b

Browse files
committed
Make test independent of function processing order
This test verifies copy-on-write optimizations based on array semantics happen correctly. We test that if SIL has the right form in cowarray_opts.sil these optimizations happen. But I believe that it is important to test that SIL has the right form when we get to the cow hoisting pass. This test verifies this. Unfortunately, this requires a swift test case. rdar://23681223
1 parent 32f8492 commit 7f6da3b

File tree

1 file changed

+59
-41
lines changed

1 file changed

+59
-41
lines changed

test/SILPasses/array_mutable_assertonly.swift

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s
2-
// REQUIRES: rdar://23681223
1+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST1
2+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST2
3+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST3
4+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST4
5+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST5
6+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST6
7+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST7
8+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST8
9+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST9
10+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST10
11+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST11
12+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST12
13+
// RUN: %target-swift-frontend -O -emit-sil -Xllvm -debug-only=cowarray-opts -primary-file %s 2>&1 | FileCheck %s --check-prefix=TEST13
314
// asserts,swift_stdlib_no_asserts,optimized_stdlib
415

5-
// CHECK-LABEL: COW Array Opts in Func {{.*}}inoutarr{{.*}}
6-
// CHECK: Hoisting make_mutable
7-
// CHECK: COW Array Opts
16+
// TEST1-LABEL: COW Array Opts in Func {{.*}}inoutarr{{.*}}
17+
// TEST1: Hoisting make_mutable
18+
// TEST1: COW Array Opts
19+
820
func inoutarr(inout a: [Int]) {
921
for i in 0..<a.count {
1022
a[i] = 0
@@ -15,15 +27,16 @@ struct S {
1527
var a: [Int]
1628
}
1729

18-
// CHECK-LABEL: COW Array Opts in Func {{.*}}arrelt{{.*}}
19-
// CHECK: Hoisting make_mutable
20-
// CHECK: COW Array Opts
30+
// TEST2-LABEL: COW Array Opts in Func {{.*}}arrelt{{.*}}
31+
// TEST2: Hoisting make_mutable
32+
// TEST2: COW Array Opts
2133
func arrelt(inout s: S) {
2234
for i in 0..<s.a.count {
2335
s.a[i] = 0
2436
}
2537
}
2638

39+
2740
class ArrayInClass {
2841
final var A : [Int]
2942
final var B : [Int]
@@ -35,26 +48,28 @@ class ArrayInClass {
3548
C = [[]]
3649
}
3750

38-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoistInClass{{.*}}
39-
// CHECK: Hoisting make_mutable
51+
// TEST3-LABEL: COW Array Opts in Func {{.*}}hoistInClass{{.*}}
52+
// TEST3: Hoisting make_mutable
53+
// TEST3: COW Array Opts
4054
func hoistInClass() {
4155
for i in 0..<A.count {
4256
A[i] = 0
4357
}
4458
}
4559

46-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoistInClass2Arr{{.*}}
47-
// CHECK: Hoisting make_mutable
60+
// TEST4-LABEL: COW Array Opts in Func {{.*}}hoistInClass2Arr{{.*}}
61+
// TEST4: Hoisting make_mutable
62+
// TEST4: COW Array Opts
4863
func hoistInClass2Arr() {
4964
for i in 0..<A.count {
5065
A[i] = 0
5166
B[i] = 2
5267
}
5368
}
5469

55-
// CHECK-LABEL: COW Array Opts in Func {{.*}}dontHoistInClassAppend{{.*}}
56-
// CHECK-NOT: Hoisting make_mutable
57-
// CHECK: COW Array Opts in Func
70+
// TEST5-LABEL: COW Array Opts in Func {{.*}}dontHoistInClassAppend{{.*}}
71+
// TEST5-NOT: Hoisting make_mutable
72+
// TEST5: COW Array Opts in Func
5873
func dontHoistInClassAppend() {
5974
for i in 0..<A.count {
6075
A[i] = 0
@@ -69,13 +84,14 @@ struct Array2d {
6984
var rows : Int
7085
}
7186

72-
// CHECK-LABEL: COW Array Opts in Func {{.*}}test2DArrayLoop{{.*}}
73-
// CHECK: Array Opts in Loop Loop at depth 2
74-
// CHECK-NOT: COW Array Opts in
75-
// CHECK: Hoisting make_mutable
76-
// CHECK: Array Opts in Loop Loop at depth 1
77-
// CHECK-NOT: COW Array Opts in
78-
// CHECK: Hoisting make_mutable
87+
// TEST6-LABEL: COW Array Opts in Func {{.*}}test2DArrayLoop{{.*}}
88+
// TEST6: Array Opts in Loop Loop at depth 2
89+
// TEST6-NOT: COW Array Opts in
90+
// TEST6: Hoisting make_mutable
91+
// TEST6: Array Opts in Loop Loop at depth 1
92+
// TEST6-NOT: COW Array Opts in
93+
// TEST6: Hoisting make_mutable
94+
// TEST6: COW Array Opts in
7995

8096
func test2DArrayLoop(inout A : Array2d) {
8197
for r in 0 ..< A.rows {
@@ -87,18 +103,18 @@ func test2DArrayLoop(inout A : Array2d) {
87103

88104
class AClass {}
89105

90-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoistArrayOfClasses{{.*}}
91-
// CHECK: Hoisting make_mutable
92-
106+
// TEST7-LABEL: COW Array Opts in Func {{.*}}hoistArrayOfClasses{{.*}}
107+
// TEST7: Hoisting make_mutable
108+
// TEST7: COW Array Opts
93109
func hoistArrayOfClasses(inout A : [AClass], x: AClass) {
94110
for i in 0 ..< A.count {
95111
A[i] = x
96112
}
97113
}
98114

99-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoistMutableOfAppend{{.*}}
100-
// CHECK: Hoisting make_mutable
101-
// CHECK: COW Array Opts
115+
// TEST8-LABEL: COW Array Opts in Func {{.*}}hoistMutableOfAppend{{.*}}
116+
// TEST8: Hoisting make_mutable
117+
// TEST8: COW Array Opts
102118

103119
func hoistMutableOfAppend(inout A : [Int]) {
104120
for i in 0 ..< 10 {
@@ -114,9 +130,9 @@ class ArrayHolder {
114130
final var A : [[Int]]
115131
init() { A = [] }
116132

117-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoist2DArrayInClass
118-
// CHECK: Hoisting make_mutable
119-
// CHECK: COW Array Opts
133+
// TEST9-LABEL: COW Array Opts in Func {{.*}}hoist2DArrayInClass
134+
// TEST9: Hoisting make_mutable
135+
// TEST9: COW Array Opts
120136

121137
func hoist2DArrayInClass() {
122138
for i in 0 ..< 10 {
@@ -126,8 +142,9 @@ class ArrayHolder {
126142
}
127143
}
128144

129-
// CHECK-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray
130-
// CHECK-NOT: Hoisting make_mutable
145+
// TEST10-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray
146+
// TEST10-NOT: Hoisting make_mutable
147+
// TEST10: COW Array Opts
131148

132149
func dontHoist2DArray(){
133150
var escape : [Int] = []
@@ -140,8 +157,9 @@ class ArrayHolder {
140157
use(escape)
141158
}
142159

143-
// CHECK-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray2
144-
// CHECK-NOT: Hoisting make_mutable
160+
// TEST11-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray2
161+
// TEST11-NOT: Hoisting make_mutable
162+
// TEST11: COW Array Opts
145163

146164
func dontHoist2DArray2(){
147165
let b = [0]
@@ -153,9 +171,9 @@ class ArrayHolder {
153171
}
154172
}
155173

156-
// CHECK-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray3
157-
// CHECK-NOT: Hoisting make_mutable
158-
// CHECK: COW Array Opts
174+
// TEST12-LABEL: COW Array Opts in Func {{.*}}dontHoist2DArray3
175+
// TEST12-NOT: Hoisting make_mutable
176+
// TEST12: COW Array Opts
159177

160178
func dontHoist2DArray3() {
161179
for i in 0 ..< A.count {
@@ -167,9 +185,9 @@ class ArrayHolder {
167185
}
168186
}
169187

170-
// CHECK-LABEL: COW Array Opts in Func {{.*}}hoist2DArray
171-
// CHECK: Hoisting make_mutable
172-
// CHECK: COW Array Opts
188+
// TEST13-LABEL: COW Array Opts in Func {{.*}}hoist2DArray
189+
// TEST13: Hoisting make_mutable
190+
// TEST13: COW Array Opts
173191

174192
func hoist2DArray(inout a: [[Int]]) {
175193
for i in 0 ..< a.count {

0 commit comments

Comments
 (0)