Skip to content

Commit 5302c71

Browse files
committed
Make SourceKitDTests build in Swift 6 mode
1 parent e59219c commit 5302c71

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

Tests/SourceKitDTests/CrashRecoveryTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,20 @@ final class CrashRecoveryTests: XCTestCase {
279279
let clangdRestartedFirstTime = self.expectation(description: "clangd restarted for the first time")
280280
let clangdRestartedSecondTime = self.expectation(description: "clangd restarted for the second time")
281281

282-
var clangdHasRestartedFirstTime = false
282+
let clangdHasRestartedFirstTime = ThreadSafeBox(initialValue: false)
283283

284284
await clangdServer.addStateChangeHandler { (oldState, newState) in
285285
switch newState {
286286
case .connectionInterrupted:
287287
clangdCrashed.fulfill()
288288
case .connected:
289-
if !clangdHasRestartedFirstTime {
290-
clangdRestartedFirstTime.fulfill()
291-
clangdHasRestartedFirstTime = true
292-
} else {
293-
clangdRestartedSecondTime.fulfill()
289+
clangdHasRestartedFirstTime.withLock { clangdHasRestartedFirstTime in
290+
if !clangdHasRestartedFirstTime {
291+
clangdRestartedFirstTime.fulfill()
292+
clangdHasRestartedFirstTime = true
293+
} else {
294+
clangdRestartedSecondTime.fulfill()
295+
}
294296
}
295297
default:
296298
break

Tests/SourceKitDTests/SourceKitDRegistryTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13+
import CAtomics
1314
import LSPTestSupport
1415
import SourceKitD
1516
import TSCBasic
@@ -40,7 +41,7 @@ final class SourceKitDRegistryTests: XCTestCase {
4041
let registry = SourceKitDRegistry()
4142

4243
@inline(never)
43-
func scope(registry: SourceKitDRegistry) async throws -> Int {
44+
func scope(registry: SourceKitDRegistry) async throws -> UInt32 {
4445
let a = await FakeSourceKitD.getOrCreate(try AbsolutePath(validating: "/a"), in: registry)
4546

4647
await assertTrue(a === FakeSourceKitD.getOrCreate(try AbsolutePath(validating: "/a"), in: registry))
@@ -58,19 +59,18 @@ final class SourceKitDRegistryTests: XCTestCase {
5859
}
5960
}
6061

61-
private var nextToken = 0
62+
private nonisolated(unsafe) var nextToken = AtomicUInt32(initialValue: 0)
6263

6364
final class FakeSourceKitD: SourceKitD {
64-
let token: Int
65+
let token: UInt32
6566
var api: sourcekitd_api_functions_t { fatalError() }
6667
var keys: sourcekitd_api_keys { fatalError() }
6768
var requests: sourcekitd_api_requests { fatalError() }
6869
var values: sourcekitd_api_values { fatalError() }
6970
func addNotificationHandler(_ handler: SKDNotificationHandler) { fatalError() }
7071
func removeNotificationHandler(_ handler: SKDNotificationHandler) { fatalError() }
7172
private init() {
72-
token = nextToken
73-
nextToken += 1
73+
token = nextToken.fetchAndIncrement()
7474
}
7575

7676
static func getOrCreate(_ path: AbsolutePath, in registry: SourceKitDRegistry) async -> SourceKitD {

Tests/SourceKitDTests/SourceKitDTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ final class SourceKitDTests: XCTestCase {
3232
let keys = sourcekitd.keys
3333
let path = DocumentURI.for(.swift).pseudoPath
3434

35-
let isExpectedNotification = { (response: SKDResponse) -> Bool in
35+
let isExpectedNotification = { @Sendable (response: SKDResponse) -> Bool in
3636
if let notification: sourcekitd_api_uid_t = response.value?[keys.notification],
3737
let name: String = response.value?[keys.name]
3838
{
@@ -95,10 +95,10 @@ final class SourceKitDTests: XCTestCase {
9595
}
9696
}
9797

98-
private class ClosureNotificationHandler: SKDNotificationHandler {
99-
let f: (SKDResponse) -> Void
98+
private final class ClosureNotificationHandler: SKDNotificationHandler {
99+
let f: @Sendable (SKDResponse) -> Void
100100

101-
init(_ f: @escaping (SKDResponse) -> Void) {
101+
init(_ f: @Sendable @escaping (SKDResponse) -> Void) {
102102
self.f = f
103103
}
104104

0 commit comments

Comments
 (0)