Skip to content

Commit 5574fdc

Browse files
authored
Merge pull request #1678 from ahoppen/harder-cancellation
Update cancellation tests to harder type checking example
2 parents 4a2d2d0 + 6211298 commit 5574fdc

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
@@ -1394,8 +1394,24 @@ final class BackgroundIndexingTests: XCTestCase {
13941394
_ = try await SwiftPMTestProject(
13951395
files: [
13961396
"Test.swift": """
1397-
func slow(x: Invalid1, y: Invalid2) {
1398-
x / y / x / y / x / y / x / y
1397+
struct A: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1398+
struct B: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1399+
struct C: ExpressibleByIntegerLiteral { init(integerLiteral value: Int) {} }
1400+
1401+
func + (lhs: A, rhs: B) -> A { fatalError() }
1402+
func + (lhs: B, rhs: C) -> A { fatalError() }
1403+
func + (lhs: C, rhs: A) -> A { fatalError() }
1404+
1405+
func + (lhs: B, rhs: A) -> B { fatalError() }
1406+
func + (lhs: C, rhs: B) -> B { fatalError() }
1407+
func + (lhs: A, rhs: C) -> B { fatalError() }
1408+
1409+
func + (lhs: C, rhs: B) -> C { fatalError() }
1410+
func + (lhs: B, rhs: C) -> C { fatalError() }
1411+
func + (lhs: A, rhs: A) -> C { fatalError() }
1412+
1413+
func slow() {
1414+
let x: C = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
13991415
}
14001416
"""
14011417
],
@@ -1404,10 +1420,10 @@ final class BackgroundIndexingTests: XCTestCase {
14041420
)
14051421
// Creating the `SwiftPMTestProject` implicitly waits for background indexing to finish.
14061422
// Preparation of `Test.swift` should finish instantly because it doesn't type check the function body.
1407-
// Type-checking the body relies on rdar://80582770, which makes the line hard to type check. We should hit the
1408-
// timeout of 1s. Adding another 2s to escalate a SIGINT (to which swift-frontend doesn't respond) to a SIGKILL mean
1409-
// that the initial indexing should be done in ~3s. 30s should be enough to always finish within this time while
1410-
// also testing that we don't wait for type checking of Test.swift to finish.
1423+
// Type-checking of `slow()` should be slow because the expression has exponential complexity in the type checker.
1424+
// We should hit the timeout of 1s. Adding another 2s to escalate a SIGINT (to which swift-frontend doesn't respond)
1425+
// to a SIGKILL mean that the initial indexing should be done in ~3s. 30s should be enough to always finish within
1426+
// this time while also testing that we don't wait for type checking of Test.swift to finish.
14111427
XCTAssert(Date().timeIntervalSince(dateStarted) < 30)
14121428
}
14131429

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)