Skip to content

Commit 7e861f5

Browse files
authored
Merge pull request #1140 from ahoppen/ahoppen/skcore-strict-concurrency
Make `SKCore` build with strict concurrency
2 parents 591e5ae + f1b34b1 commit 7e861f5

17 files changed

+30
-33
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ let package = Package(
178178
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
179179
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
180180
],
181-
exclude: ["CMakeLists.txt"]
181+
exclude: ["CMakeLists.txt"],
182+
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
182183
),
183184

184185
.testTarget(

Sources/SKCore/BuildSetup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212

1313
import SKSupport
1414

15-
import struct PackageModel.BuildFlags
15+
@preconcurrency import struct PackageModel.BuildFlags
1616
import struct TSCBasic.AbsolutePath
1717

1818
/// Build configuration
19-
public struct BuildSetup {
19+
public struct BuildSetup: Sendable {
2020

2121
/// Default configuration
2222
public static let `default` = BuildSetup(

Sources/SKCore/BuildSystem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import LanguageServerProtocol
1616
import struct TSCBasic.AbsolutePath
1717

1818
/// Defines how well a `BuildSystem` can handle a file with a given URI.
19-
public enum FileHandlingCapability: Comparable {
19+
public enum FileHandlingCapability: Comparable, Sendable {
2020
/// The build system can't handle the file at all
2121
case unhandled
2222

@@ -36,7 +36,7 @@ public enum FileHandlingCapability: Comparable {
3636
///
3737
/// For example, a SwiftPMWorkspace provides compiler arguments for the files
3838
/// contained in a SwiftPM package root directory.
39-
public protocol BuildSystem: AnyObject {
39+
public protocol BuildSystem: AnyObject, Sendable {
4040

4141
/// The root of the project that this build system manages. For example, for SwiftPM packages, this is the folder
4242
/// containing Package.swift. For compilation databases it is the root folder based on which the compilation database

Sources/SKCore/BuildSystemDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import BuildServerProtocol
1313
import LanguageServerProtocol
1414

1515
/// Handles build system events, such as file build settings changes.
16-
public protocol BuildSystemDelegate: AnyObject {
16+
public protocol BuildSystemDelegate: AnyObject, Sendable {
1717
/// Notify the delegate that the build targets have changed.
1818
///
1919
/// The callee should request new sources and outputs for the build targets of

Sources/SKCore/CompilationDatabase.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ extension FixedCompilationDatabase {
141141
var fixedArgs: [String] = ["clang"]
142142
try bytes.withUnsafeData { data in
143143
guard let fileContents = String(data: data, encoding: .utf8) else {
144-
throw CompilationDatabaseDecodingError.fixedDatabaseDecordingError
144+
throw CompilationDatabaseDecodingError.fixedDatabaseDecodingError
145145
}
146146

147147
fileContents.enumerateLines { line, _ in
@@ -238,7 +238,7 @@ extension JSONCompilationDatabase {
238238

239239
enum CompilationDatabaseDecodingError: Error {
240240
case missingCommandOrArguments
241-
case fixedDatabaseDecordingError
241+
case fixedDatabaseDecodingError
242242
}
243243

244244
extension CompilationDatabase.Command: Codable {

Sources/SKCore/FallbackBuildSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
import LanguageServerProtocol
1717
import SKSupport
1818

19-
import enum PackageLoading.Platform
19+
@preconcurrency import enum PackageLoading.Platform
2020
import struct TSCBasic.AbsolutePath
2121
import class TSCBasic.Process
2222

Sources/SKCore/FileBuildSettings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import LanguageServerProtocol
1717
///
1818
/// Encapsulates all the settings needed to compile a single file, including the compiler arguments
1919
/// and working directory. FileBuildSettings are typically the result of a BuildSystem query.
20-
public struct FileBuildSettings: Equatable {
20+
public struct FileBuildSettings: Equatable, Sendable {
2121

2222
/// The compiler arguments to use for this file.
2323
public var compilerArguments: [String]

Sources/SKCore/MainFilesProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import LanguageServerProtocol
1414

1515
/// A type that can provide the set of main files that include a particular file.
16-
public protocol MainFilesProvider: AnyObject {
16+
public protocol MainFilesProvider: AnyObject, Sendable {
1717

1818
/// Returns the set of main files that contain the given file.
1919
///

Sources/SKCore/PathPrefixMapping.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Foundation
22

3-
public struct PathPrefixMapping {
3+
public struct PathPrefixMapping: Sendable {
44
/// Path prefix to be replaced, typically the canonical or hermetic path.
55
public let original: String
66

Sources/SKCore/Toolchain.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import LSPLogging
1414
import LanguageServerProtocol
1515
import SKSupport
1616

17-
import enum PackageLoading.Platform
17+
@preconcurrency import enum PackageLoading.Platform
1818
import struct TSCBasic.AbsolutePath
1919
import protocol TSCBasic.FileSystem
2020
import var TSCBasic.localFileSystem
@@ -114,7 +114,6 @@ public final class Toolchain {
114114
}
115115

116116
extension Toolchain {
117-
118117
/// Create a toolchain for the given path, if it contains at least one tool, otherwise return nil.
119118
///
120119
/// This initializer looks for a toolchain using the following basic layout:

Sources/SKSupport/BuildConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public enum BuildConfiguration: String {
13+
public enum BuildConfiguration: String, Sendable {
1414
case debug
1515
case release
1616
}

Sources/SKSupport/WorkspaceType.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
public enum WorkspaceType: String {
13+
public enum WorkspaceType: String, Sendable {
1414
case buildServer
1515
case compilationDatabase
1616
case swiftPM

Sources/SourceKitD/SKDRequestArray.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ extension SourceKitD {
3131
}
3232
}
3333

34-
public final class SKDRequestArray {
35-
public let array: sourcekitd_api_object_t
36-
public let sourcekitd: SourceKitD
34+
public final class SKDRequestArray: Sendable {
35+
nonisolated(unsafe) let array: sourcekitd_api_object_t
36+
private let sourcekitd: SourceKitD
3737

3838
public init(_ array: sourcekitd_api_object_t? = nil, sourcekitd: SourceKitD) {
3939
self.array = array ?? sourcekitd.api.request_array_create(nil, 0)!

Sources/SourceKitD/SKDRequestDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ extension SourceKitD {
4949
}
5050
}
5151

52-
public final class SKDRequestDictionary {
53-
public let dict: sourcekitd_api_object_t
54-
public let sourcekitd: SourceKitD
52+
public final class SKDRequestDictionary: Sendable {
53+
nonisolated(unsafe) let dict: sourcekitd_api_object_t
54+
private let sourcekitd: SourceKitD
5555

5656
public init(_ dict: sourcekitd_api_object_t? = nil, sourcekitd: SourceKitD) {
5757
self.dict = dict ?? sourcekitd.api.request_dictionary_create(nil, nil, 0)!

Sources/SourceKitD/SKDResponse.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,8 @@ import CRT
2222
#endif
2323

2424
public final class SKDResponse: Sendable {
25-
/// - Note: `sourcekitd_api_response_t` is a typedef for `void *`, so we can't mark it as sendable. But we know that
26-
/// it stays alive until we deinit this `SKDResponse`. We also require that only a single `SKDResponse` may manage
27-
/// the `sourcekitd_api_response_t`, so raw response cannot be modified or disposed in any other way.
28-
private nonisolated(unsafe) let response: sourcekitd_api_response_t
29-
public let sourcekitd: SourceKitD
25+
private nonisolated let response: sourcekitd_api_response_t
26+
let sourcekitd: SourceKitD
3027

3128
/// Creates a new `SKDResponse` that exclusively manages the raw `sourcekitd_api_response_t`.
3229
///

Sources/SourceKitD/SKDResponseArray.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import Musl
2020
import CRT
2121
#endif
2222

23-
public final class SKDResponseArray {
24-
public let array: sourcekitd_api_variant_t
25-
let resp: SKDResponse
23+
public final class SKDResponseArray: Sendable {
24+
private let array: sourcekitd_api_variant_t
25+
private let resp: SKDResponse
2626

2727
public var sourcekitd: SourceKitD { return resp.sourcekitd }
2828

Sources/SourceKitD/SKDResponseDictionary.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import Musl
2020
import CRT
2121
#endif
2222

23-
public final class SKDResponseDictionary {
24-
public let dict: sourcekitd_api_variant_t
25-
let resp: SKDResponse
23+
public final class SKDResponseDictionary: Sendable {
24+
private let dict: sourcekitd_api_variant_t
25+
private let resp: SKDResponse
2626

2727
public var sourcekitd: SourceKitD { return resp.sourcekitd }
2828

0 commit comments

Comments
 (0)