Skip to content

Commit a133807

Browse files
committed
Add type checker performance tests.
Add type checker performance tests under validation-test/Sema/type_checker_perf. Under ./fast/ we have tests that compile reasonably quickly now but at one point did not. Under ./slow/ we have tests that are still very slow to compile. Some tests use %scale-test and others -solver-expression-time-threshold to determine if they are scaling well or compiling fast enough. I've got several more tests gathered that have not yet been set up to run in our test system. Those are forthcoming! Further contributions welcome. Thanks go to @xedin who helped collect most of the test cases.
1 parent b2efaab commit a133807

26 files changed

+370
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
func memoize<A: Hashable, R>(
5+
f: @escaping ((A) -> R, A) -> R
6+
) -> ((A) -> R) {
7+
var memo = Dictionary<A,R>()
8+
9+
var recur: ((A) -> R)!
10+
recur = { (a: A) -> R in
11+
if let r = memo[a] { return r }
12+
let r = f(recur, a)
13+
memo[a] = r
14+
return r
15+
}
16+
17+
return recur
18+
}
19+
20+
let fibonacci = memoize {
21+
(fibonacci, n) in
22+
n < 2 ? n as Int : fibonacci(n - 1) + fibonacci(n - 2)
23+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
infix operator <*> : AdditionPrecedence
5+
func <*><A, B>(lhs: ((A) -> B)?, rhs: A?) -> B? {
6+
if let lhs1 = lhs, let rhs1 = rhs {
7+
return lhs1(rhs1)
8+
}
9+
return nil
10+
}
11+
12+
func cons<T, U>(lhs: T) -> (U) -> (T, U) {
13+
return { rhs in (lhs, rhs) }
14+
}
15+
16+
var str: String? = "x"
17+
if let f = cons <*> str <*> (cons <*> str <*> (cons <*> str <*> (cons <*> str <*> (cons <*> str <*> (cons <*> str <*> (cons <*> str <*> str)))))) {
18+
print("\(f)")
19+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
2...100.reversed().filter({ $0 % 11 == 0 }).map {
5+
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
6+
"\($0) bottles of beer on the wall, \($0) bottles of beer;\n"
7+
+ " take eleven down, pass 'em around, \($0-11) bottles of beer on the wall!"
8+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
let i: Int? = 1
5+
let j: Int?
6+
let k: Int? = 2
7+
8+
let _ = [i, j, k].reduce(0 as Int?) {
9+
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
10+
$0 != nil && $1 != nil ? $0! + $1! : ($0 != nil ? $0! : ($1 != nil ? $1! : nil))
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
let empty: [Int] = []
6+
let _ = empty +
7+
%for i in range(0, N):
8+
empty +
9+
%end
10+
empty
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
public enum E
5+
{
6+
case First,
7+
%for i in range(0, N):
8+
C${i},
9+
%end
10+
End
11+
12+
static let toRawValues = [
13+
%for i in range(0, N):
14+
C${i}: String("hi"),
15+
%end
16+
]
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
typealias X = (Range<Int>, [Range<Int>])
6+
7+
let samples: ContiguousArray<X> = [
8+
(0..<1, [ 1..<1, 2..<3 ]),
9+
%for i in range(0, N):
10+
(0..<1, [ 1..<1, 2..<3 ]),
11+
%end
12+
]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
// Mixed Float and Double arithmetic
5+
func rdar18800950(v: Float) -> Double {
6+
let c1: Float = 1.0
7+
let c2 = 2.0
8+
let r = v / c1
9+
let _ = (c2 * 2 * (3 * (1 - c1 / v) - 4) * r + 5) * (c2 * 2 * (3 * (1 - c1 / v) - 4) * r + 5)
10+
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: not %scale-test --begin 1 --end 4 --step 1 --select incrementScopeCounter %s
2+
// REQUIRES: OS=macosx
3+
// REQUIRES: asserts
4+
5+
public func test(_ fn: @escaping () -> Void) {}
6+
7+
test {
8+
let _: Set<Set<Int>> = Set([
9+
Set([1]),
10+
%for i in range(0, N):
11+
Set([1]),
12+
%end
13+
])
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
2+
// REQUIRES: tools-release,no_asserts
3+
4+
// Missing force of optional result of dictionary lookup.
5+
func rdar19368383(d: [String : String]) -> [String] {
6+
var r = [String]()
7+
r += [ // expected-error {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
8+
"1" + d["2"] + "3",
9+
"1" + d["2"] + "3",
10+
"1" + d["2"] + "3",
11+
"1" + d["2"] + "3",
12+
"1" + d["2"] + "3",
13+
"1" + d["2"] + "3",
14+
]
15+
return r
16+
}

0 commit comments

Comments
 (0)