Skip to content

Make all non-test modules except for SourceKitLSP build in Swift 6 mode #1276

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 1 commit into from
May 14, 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
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

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

Expand Down
2 changes: 1 addition & 1 deletion 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

@preconcurrency import enum PackageLoading.Platform
import enum PackageLoading.Platform
import struct TSCBasic.AbsolutePath
import protocol TSCBasic.FileSystem
import var TSCBasic.localFileSystem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extension Process {
arguments: [String],
environmentBlock: ProcessEnvironmentBlock = ProcessEnv.block,
workingDirectory: AbsolutePath?,
outputRedirection: OutputRedirection = .collect,
startNewProcessGroup: Bool = true,
loggingHandler: LoggingHandler? = .none
) throws -> Process {
Expand All @@ -36,15 +35,13 @@ extension Process {
arguments: arguments,
environmentBlock: environmentBlock,
workingDirectory: workingDirectory,
outputRedirection: outputRedirection,
startNewProcessGroup: startNewProcessGroup,
loggingHandler: loggingHandler
)
} else {
self.init(
arguments: arguments,
environmentBlock: environmentBlock,
outputRedirection: outputRedirection,
startNewProcessGroup: startNewProcessGroup,
loggingHandler: loggingHandler
)
Expand All @@ -60,7 +57,6 @@ extension Process {
arguments: arguments,
environmentBlock: environmentBlock,
workingDirectory: nil,
outputRedirection: outputRedirection,
startNewProcessGroup: startNewProcessGroup,
loggingHandler: loggingHandler
)
Expand Down
14 changes: 11 additions & 3 deletions Sources/SemanticIndex/CheckedIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//===----------------------------------------------------------------------===//

import Foundation
import IndexStoreDB
@preconcurrency import IndexStoreDB
import LSPLogging
import LanguageServerProtocol

Expand Down Expand Up @@ -47,7 +47,7 @@ public enum IndexCheckLevel {
/// `IndexCheckLevel`.
///
/// - SeeAlso: Comment on `IndexOutOfDateChecker`
public final class CheckedIndex: Sendable {
public final class CheckedIndex {
private var checker: IndexOutOfDateChecker
private let index: IndexStoreDB

Expand All @@ -56,6 +56,10 @@ public final class CheckedIndex: Sendable {
self.checker = IndexOutOfDateChecker(checkLevel: checkLevel)
}

public var unchecked: UncheckedIndex {
return UncheckedIndex(index)
}

@discardableResult
public func forEachSymbolOccurrence(
byUSR usr: String,
Expand Down Expand Up @@ -146,7 +150,7 @@ public final class CheckedIndex: Sendable {
/// access of the underlying `IndexStoreDB`. This makes sure that accesses to the raw `IndexStoreDB` are explicit (by
/// calling `underlyingIndexStoreDB`) and we don't accidentally call into the `IndexStoreDB` when we wanted a
/// `CheckedIndex`.
public struct UncheckedIndex {
public struct UncheckedIndex: Sendable {
public let underlyingIndexStoreDB: IndexStoreDB

public init?(_ index: IndexStoreDB?) {
Expand All @@ -156,6 +160,10 @@ public struct UncheckedIndex {
self.underlyingIndexStoreDB = index
}

public init(_ index: IndexStoreDB) {
self.underlyingIndexStoreDB = index
}

public func checked(for checkLevel: IndexCheckLevel) -> CheckedIndex {
return CheckedIndex(index: underlyingIndexStoreDB, checkLevel: checkLevel)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/SemanticIndex/SemanticIndexManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public final actor SemanticIndexManager {
UpdateIndexStoreTaskDescription(
filesToIndex: Set(files),
buildSystemManager: self.buildSystemManager,
index: self.index,
index: self.index.unchecked,
didFinishCallback: { [weak self] taskDescription in
self?.indexTaskDidFinish?(.updateIndexStore(taskDescription))
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import SKSupport
import struct TSCBasic.AbsolutePath
import class TSCBasic.Process

private var updateIndexStoreIDForLogging = AtomicUInt32(initialValue: 1)
private nonisolated(unsafe) var updateIndexStoreIDForLogging = AtomicUInt32(initialValue: 1)

/// Describes a task to index a set of source files.
///
Expand All @@ -36,7 +36,7 @@ public struct UpdateIndexStoreTaskDescription: TaskDescriptionProtocol {

/// A reference to the underlying index store. Used to check if the index is already up-to-date for a file, in which
/// case we don't need to index it again.
private let index: CheckedIndex
private let index: UncheckedIndex

/// A callback that is called when the index task finishes
private let didFinishCallback: @Sendable (UpdateIndexStoreTaskDescription) -> Void
Expand All @@ -57,7 +57,7 @@ public struct UpdateIndexStoreTaskDescription: TaskDescriptionProtocol {
init(
filesToIndex: Set<DocumentURI>,
buildSystemManager: BuildSystemManager,
index: CheckedIndex,
index: UncheckedIndex,
didFinishCallback: @escaping @Sendable (UpdateIndexStoreTaskDescription) -> Void
) {
self.filesToIndex = filesToIndex
Expand Down Expand Up @@ -122,7 +122,7 @@ public struct UpdateIndexStoreTaskDescription: TaskDescriptionProtocol {
// The URI is not a file, so there's nothing we can index.
return
}
guard !index.hasUpToDateUnit(for: url) else {
guard !index.checked(for: .modifiedFiles).hasUpToDateUnit(for: url) else {
// We consider a file's index up-to-date if we have any up-to-date unit. Changing build settings does not
// invalidate the up-to-date status of the index.
return
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKitD/SKDResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CRT
#endif

public final class SKDResponse: Sendable {
private nonisolated let response: sourcekitd_api_response_t
private nonisolated(unsafe) let response: sourcekitd_api_response_t
let sourcekitd: SourceKitD

/// Creates a new `SKDResponse` that exclusively manages the raw `sourcekitd_api_response_t`.
Expand Down
30 changes: 0 additions & 30 deletions Tests/SKCoreTests/ToolchainRegistryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,6 @@ final class ToolchainRegistryTests: XCTestCase {
await assertTrue(tr.default === tr.toolchain(identifier: "a"))
}

func testDefaultDarwin() async throws {
let prevPlatform = Platform.current
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are no longer supported because Platform.current isn’t mutable anymore. We should still have coverage fro this because we’re running tests on macOS and Linux.

defer { Platform.current = prevPlatform }
Platform.current = .darwin

let tr = ToolchainRegistry(
toolchains: [
Toolchain(identifier: "a", displayName: "a", path: nil),
Toolchain(identifier: ToolchainRegistry.darwinDefaultToolchainIdentifier, displayName: "a", path: nil),
]
)
await assertEqual(tr.default?.identifier, ToolchainRegistry.darwinDefaultToolchainIdentifier)
}

func testUnknownPlatform() throws {
let prevPlatform = Platform.current
defer { Platform.current = prevPlatform }
Platform.current = nil

let fs = InMemoryFileSystem()
let binPath = try AbsolutePath(validating: "/foo/bar/my_toolchain/bin")
try makeToolchain(binPath: binPath, fs, sourcekitdInProc: true)

guard let t = Toolchain(binPath, fs) else {
XCTFail("could not find any tools")
return
}
XCTAssertNotNil(t.sourcekitd)
}

func testFindXcodeDefaultToolchain() async throws {
try SkipUnless.platformIsDarwin("Finding toolchains in Xcode is only supported on macOS")
let fs = InMemoryFileSystem()
Expand Down