Skip to content

Commit 6211298

Browse files
committed
Update cancellation tests to harder type checking example
swiftlang/swift#63585 will resolve rdar://80582770 and the type checker performance problem that we were relying on. Use a harder example (stolen from https://github.com/swiftlang/swift/blob/main/unittests/SourceKit/SwiftLang/CloseTest.cpp#L131-L151), that’s unlikely to get a significant performance improvement soon.
1 parent 9334bb7 commit 6211298

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

Tests/SourceKitLSPTests/BackgroundIndexingTests.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1398,8 +1398,24 @@ final class BackgroundIndexingTests: XCTestCase {
13981398
_ = try await SwiftPMTestProject(
13991399
files: [
14001400
"Test.swift": """
1401-
func slow(x: Invalid1, y: Invalid2) {
1402-
x / y / x / y / x / y / x / y
1401+
struct A: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1402+
struct B: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1403+
struct C: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1404+
1405+
func + (lhs: A, rhs: B) -> A { fatalError() }
1406+
func + (lhs: B, rhs: C) -> A { fatalError() }
1407+
func + (lhs: C, rhs: A) -> A { fatalError() }
1408+
1409+
func + (lhs: B, rhs: A) -> B { fatalError() }
1410+
func + (lhs: C, rhs: B) -> B { fatalError() }
1411+
func + (lhs: A, rhs: C) -> B { fatalError() }
1412+
1413+
func + (lhs: C, rhs: B) -> C { fatalError() }
1414+
func + (lhs: B, rhs: C) -> C { fatalError() }
1415+
func + (lhs: A, rhs: A) -> C { fatalError() }
1416+
1417+
func slow() {
1418+
let x: C = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
14031419
}
14041420
"""
14051421
],
@@ -1408,10 +1424,10 @@ final class BackgroundIndexingTests: XCTestCase {
14081424
)
14091425
// Creating the `SwiftPMTestProject` implicitly waits for background indexing to finish.
14101426
// Preparation of `Test.swift` should finish instantly because it doesn't type check the function body.
1411-
// Type-checking the body relies on rdar://80582770, which makes the line hard to type check. We should hit the
1412-
// timeout of 1s. Adding another 2s to escalate a SIGINT (to which swift-frontend doesn't respond) to a SIGKILL mean
1413-
// that the initial indexing should be done in ~3s. 30s should be enough to always finish within this time while
1414-
// also testing that we don't wait for type checking of Test.swift to finish.
1427+
// Type-checking of `slow()` should be slow because the expression has exponential complexity in the type checker.
1428+
// We should hit the timeout of 1s. Adding another 2s to escalate a SIGINT (to which swift-frontend doesn't respond)
1429+
// to a SIGKILL mean that the initial indexing should be done in ~3s. 30s should be enough to always finish within
1430+
// this time while also testing that we don't wait for type checking of Test.swift to finish.
14151431
XCTAssert(Date().timeIntervalSince(dateStarted) < 30)
14161432
}
14171433

Tests/SourceKitLSPTests/LifecycleTests.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,26 @@ final class LifecycleTests: XCTestCase {
5252
let uri = DocumentURI(for: .swift)
5353
let positions = testClient.openDocument(
5454
"""
55+
struct A: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
56+
struct B: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
57+
struct C: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
58+
59+
func + (lhs: A, rhs: B) -> A { fatalError() }
60+
func + (lhs: B, rhs: C) -> A { fatalError() }
61+
func + (lhs: C, rhs: A) -> A { fatalError() }
62+
63+
func + (lhs: B, rhs: A) -> B { fatalError() }
64+
func + (lhs: C, rhs: B) -> B { fatalError() }
65+
func + (lhs: A, rhs: C) -> B { fatalError() }
66+
67+
func + (lhs: C, rhs: B) -> C { fatalError() }
68+
func + (lhs: B, rhs: C) -> C { fatalError() }
69+
func + (lhs: A, rhs: A) -> C { fatalError() }
70+
71+
5572
class Foo {
5673
func slow(x: Invalid1, y: Invalid2) {
57-
1️⃣ x / y / x / y / x / y / x / y . 2️⃣
74+
1️⃣ let x: C = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 2️⃣
5875
}
5976
6077
struct Foo {

Tests/SourceKitLSPTests/LocalSwiftTests.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1434,9 +1434,25 @@ final class LocalSwiftTests: XCTestCase {
14341434

14351435
let positions = testClient.openDocument(
14361436
"""
1437+
struct A: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1438+
struct B: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1439+
struct C: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1440+
1441+
func + (lhs: A, rhs: B) -> A { fatalError() }
1442+
func + (lhs: B, rhs: C) -> A { fatalError() }
1443+
func + (lhs: C, rhs: A) -> A { fatalError() }
1444+
1445+
func + (lhs: B, rhs: A) -> B { fatalError() }
1446+
func + (lhs: C, rhs: B) -> B { fatalError() }
1447+
func + (lhs: A, rhs: C) -> B { fatalError() }
1448+
1449+
func + (lhs: C, rhs: B) -> C { fatalError() }
1450+
func + (lhs: B, rhs: C) -> C { fatalError() }
1451+
func + (lhs: A, rhs: A) -> C { fatalError() }
1452+
14371453
1️⃣class Foo {
14381454
func slow(x: Invalid1, y: Invalid2) {
1439-
x / y / x / y / x / y / x / y.
1455+
let x: C = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
14401456
}
14411457
}2️⃣
14421458
""",

0 commit comments

Comments
 (0)