Skip to content

Add more type checker performance tests. #11506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

// Mixed UInt32 and Double
let x: UInt32 = 1
let _ = x > (33 + 55 + 6 + 55 + 6 + 55 + 6 + 55 + 6 + 27.5)
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

let _ = [0].reduce([Int]()) {
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
return $0.count == 0 && $1 == 0 ? [] : $0 + [$1]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

let a: [Double] = []
_ = a.map { $0 - 1.0 }
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
.map { $0 * $0 }
.reduce(0, +) / Double(a.count)
11 changes: 11 additions & 0 deletions validation-test/Sema/type_checker_perf/slow/rdar23861629.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

struct S { var s: String? }

func rdar23861629(_ a: [S]) {
_ = a.reduce("") {
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
($0 == "") ? ($1.s ?? "") : $0 + "," + ($1.s ?? "")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

func rdar26564101(a: [Double], m: Double) -> Double {
return Double(Array(0...a.count - 1).reduce(0) { $0 + $1 - m })
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

func fun(_ x: Double) -> Double { fatalError() }

func test(l: Double, s: Float) {
_ = fun((l / 2.0) * (l / 2.0) * (l / 2.0) / (1.0 + s * s))
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
}
23 changes: 23 additions & 0 deletions validation-test/Sema/type_checker_perf/slow/rdar30729643.swift.gyb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: not %scale-test --begin 7 --end 9 --step 1 --select incrementScopeCounter %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

enum X : String {
case first
}

enum Y : Int {
case first
}

_ =
[
%for i in range(0, N):
[
X.first : Y.first
],
%end
[
X.first : "literal",
],
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

let a = 1

_ = -a + -a - -a + -a - -a
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

func rdar31742586() -> Double {
return -(1 + 2) + -(3 + 4) + 5
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
}
12 changes: 12 additions & 0 deletions validation-test/Sema/type_checker_perf/slow/rdar32034560.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

struct S {
var A: [[UInt32]]

func rdar32034560(x: UInt32) -> UInt32 {
return ((self.A[0][Int(x >> 24) & 0xFF] &+ self.A[1][Int(x >> 16) & 0xFF]) ^ self.A[2][Int(x >> 8) & 0xFF]) &+ self.A[3][Int(x & 0xFF)] |
((self.A[0][Int(x >> 24) & 0xFF] &+ self.A[1][Int(x >> 16) & 0xFF]) ^ self.A[2][Int(x >> 8) & 0xFF]) &+ self.A[3][Int(x & 0xFF)]
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1 -swift-version 4
// REQUIRES: tools-release,no_asserts

func rdar32998180(value: UInt16) -> UInt16 {
var result = (((value >> 1) ^ (value >> 1) ^ (value >> 1) ^ (value >> 1)) & 1) << 1
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
return result
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

_ = MemoryLayout<Int>.size
%for i in range(0, N):
+ MemoryLayout<Int>.size
%end
10 changes: 10 additions & 0 deletions validation-test/Sema/type_checker_perf/slow/rdar33289839.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

func rdar33289839(s: String) -> String {
return "test" + String(s)
%for i in range(0, N):
+ "test" + String(s)
%end
}
33 changes: 33 additions & 0 deletions validation-test/Sema/type_checker_perf/slow/rdar33292740.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: not %scale-test --begin 2 --end 4 --step 1 --select incrementScopeCounter %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

struct V3 {
init(_ x: Int, _ y: Int, _ z: Int) {
self.x = Float(x)
self.y = Float(y)
self.z = Float(z)
}

init(_ x: Float, _ y: Float, _ z: Float) {
self.x = x
self.y = y
self.z = z
}

init(_ x: Double, _ y: Double, _ z: Double) {
self.x = Float(x)
self.y = Float(y)
self.z = Float(z)
}

var x: Float
var y: Float
var z: Float
}

let a = [
%for i in range(1, N):
V3(0, 0, 0),
%end
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asserts

// Mixed Int/Double slow to emit diagnostics
func rdar33476240(col: Int, row: Int, maxCol: Int, maxRow: Int) {
let _ = (-(maxCol - 1) + (col * 2)) * 0.1
// expected-error@-1 {{expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: not %scale-test --begin 1 --end 3 --step 1 --select incrementScopeCounter %s
// REQUIRES: OS=macosx
// REQUIRES: asserts

let _ = 1
%for i in range(0, N):
| UInt32(${i}) << ${i}
%end