Skip to content

Make SKCore build with strict concurrency #1140

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 2 commits into from
Mar 21, 2024
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
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ let package = Package(
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
],
exclude: ["CMakeLists.txt"]
exclude: ["CMakeLists.txt"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
),

.testTarget(
Expand Down
4 changes: 2 additions & 2 deletions Sources/SKCore/BuildSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

import SKSupport

import struct PackageModel.BuildFlags
@preconcurrency import struct PackageModel.BuildFlags
import struct TSCBasic.AbsolutePath

/// Build configuration
public struct BuildSetup {
public struct BuildSetup: Sendable {

/// Default configuration
public static let `default` = BuildSetup(
Expand Down
4 changes: 2 additions & 2 deletions Sources/SKCore/BuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import LanguageServerProtocol
import struct TSCBasic.AbsolutePath

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

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

/// The root of the project that this build system manages. For example, for SwiftPM packages, this is the folder
/// containing Package.swift. For compilation databases it is the root folder based on which the compilation database
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKCore/BuildSystemDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import BuildServerProtocol
import LanguageServerProtocol

/// Handles build system events, such as file build settings changes.
public protocol BuildSystemDelegate: AnyObject {
public protocol BuildSystemDelegate: AnyObject, Sendable {
/// Notify the delegate that the build targets have changed.
///
/// The callee should request new sources and outputs for the build targets of
Expand Down
4 changes: 2 additions & 2 deletions Sources/SKCore/CompilationDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ extension FixedCompilationDatabase {
var fixedArgs: [String] = ["clang"]
try bytes.withUnsafeData { data in
guard let fileContents = String(data: data, encoding: .utf8) else {
throw CompilationDatabaseDecodingError.fixedDatabaseDecordingError
throw CompilationDatabaseDecodingError.fixedDatabaseDecodingError
}

fileContents.enumerateLines { line, _ in
Expand Down Expand Up @@ -238,7 +238,7 @@ extension JSONCompilationDatabase {

enum CompilationDatabaseDecodingError: Error {
case missingCommandOrArguments
case fixedDatabaseDecordingError
case fixedDatabaseDecodingError
}

extension CompilationDatabase.Command: Codable {
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKCore/FallbackBuildSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
import LanguageServerProtocol
import SKSupport

import enum PackageLoading.Platform
@preconcurrency import enum PackageLoading.Platform
import struct TSCBasic.AbsolutePath
import class TSCBasic.Process

Expand Down
2 changes: 1 addition & 1 deletion Sources/SKCore/FileBuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import LanguageServerProtocol
///
/// Encapsulates all the settings needed to compile a single file, including the compiler arguments
/// and working directory. FileBuildSettings are typically the result of a BuildSystem query.
public struct FileBuildSettings: Equatable {
public struct FileBuildSettings: Equatable, Sendable {

/// The compiler arguments to use for this file.
public var compilerArguments: [String]
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKCore/MainFilesProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import LanguageServerProtocol

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

/// Returns the set of main files that contain the given file.
///
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKCore/PathPrefixMapping.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct PathPrefixMapping {
public struct PathPrefixMapping: Sendable {
/// Path prefix to be replaced, typically the canonical or hermetic path.
public let original: String

Expand Down
3 changes: 1 addition & 2 deletions Sources/SKCore/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import LSPLogging
import LanguageServerProtocol
import SKSupport

import enum PackageLoading.Platform
@preconcurrency import enum PackageLoading.Platform
import struct TSCBasic.AbsolutePath
import protocol TSCBasic.FileSystem
import var TSCBasic.localFileSystem
Expand Down Expand Up @@ -114,7 +114,6 @@ public final class Toolchain {
}

extension Toolchain {

/// Create a toolchain for the given path, if it contains at least one tool, otherwise return nil.
///
/// This initializer looks for a toolchain using the following basic layout:
Expand Down
2 changes: 1 addition & 1 deletion Sources/SKSupport/BuildConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

public enum BuildConfiguration: String {
public enum BuildConfiguration: String, Sendable {
case debug
case release
}
2 changes: 1 addition & 1 deletion Sources/SKSupport/WorkspaceType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//
//===----------------------------------------------------------------------===//

public enum WorkspaceType: String {
public enum WorkspaceType: String, Sendable {
case buildServer
case compilationDatabase
case swiftPM
Expand Down
6 changes: 3 additions & 3 deletions Sources/SourceKitD/SKDRequestArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ extension SourceKitD {
}
}

public final class SKDRequestArray {
public let array: sourcekitd_api_object_t
public let sourcekitd: SourceKitD
public final class SKDRequestArray: Sendable {
nonisolated(unsafe) let array: sourcekitd_api_object_t
private let sourcekitd: SourceKitD

public init(_ array: sourcekitd_api_object_t? = nil, sourcekitd: SourceKitD) {
self.array = array ?? sourcekitd.api.request_array_create(nil, 0)!
Expand Down
6 changes: 3 additions & 3 deletions Sources/SourceKitD/SKDRequestDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ extension SourceKitD {
}
}

public final class SKDRequestDictionary {
public let dict: sourcekitd_api_object_t
public let sourcekitd: SourceKitD
public final class SKDRequestDictionary: Sendable {
nonisolated(unsafe) let dict: sourcekitd_api_object_t
private let sourcekitd: SourceKitD

public init(_ dict: sourcekitd_api_object_t? = nil, sourcekitd: SourceKitD) {
self.dict = dict ?? sourcekitd.api.request_dictionary_create(nil, nil, 0)!
Expand Down
7 changes: 2 additions & 5 deletions Sources/SourceKitD/SKDResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ import CRT
#endif

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

/// Creates a new `SKDResponse` that exclusively manages the raw `sourcekitd_api_response_t`.
///
Expand Down
6 changes: 3 additions & 3 deletions Sources/SourceKitD/SKDResponseArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import Musl
import CRT
#endif

public final class SKDResponseArray {
public let array: sourcekitd_api_variant_t
let resp: SKDResponse
public final class SKDResponseArray: Sendable {
private let array: sourcekitd_api_variant_t
private let resp: SKDResponse

public var sourcekitd: SourceKitD { return resp.sourcekitd }

Expand Down
6 changes: 3 additions & 3 deletions Sources/SourceKitD/SKDResponseDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import Musl
import CRT
#endif

public final class SKDResponseDictionary {
public let dict: sourcekitd_api_variant_t
let resp: SKDResponse
public final class SKDResponseDictionary: Sendable {
private let dict: sourcekitd_api_variant_t
private let resp: SKDResponse

public var sourcekitd: SourceKitD { return resp.sourcekitd }

Expand Down