Skip to content

Commit 65a3402

Browse files
authored
Merge pull request #2253 from ahoppen/fix-warnings
2 parents 3555675 + 3762e7a commit 65a3402

File tree

15 files changed

+65
-43
lines changed

15 files changed

+65
-43
lines changed

Package.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,6 @@ var targets: [Target] = [
244244
"BuildServerIntegration",
245245
"BuildServerProtocol",
246246
"LanguageServerProtocol",
247-
248-
"SemanticIndex",
249247
"SemanticIndex",
250248
"SKLogging",
251249
"SKUtilities",

Sources/CompletionScoringTestSupport/TestExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ extension XCTestCase {
110110
at: URL(fileURLWithPath: path).deletingLastPathComponent(),
111111
withIntermediateDirectories: true
112112
)
113-
FileManager.default.createFile(atPath: path, contents: Data())
113+
try FileManager.default.createFile(at: URL(fileURLWithPath: path), contents: Data())
114114
}
115115
let logFD = try FileHandle(forWritingAtPath: path).unwrap(orThrow: "Opening \(path) failed")
116116
try logFD.seekToEnd()

Sources/Csourcekitd/include/plugin.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,23 @@ typedef struct {
233233
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
234234
);
235235

236-
_Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_from_cstr_t (*_Nonnull plugin_initialize_uid_get_from_cstr)(
236+
// The following would be more idiomatically written as follows but marking `sourcekitd_api_uid_get_from_cstr_t` as
237+
// `Sendable` hits https://github.com/swiftlang/swift/issues/83892.
238+
// _Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_from_cstr_t (*_Nonnull plugin_initialize_uid_get_from_cstr)(
239+
// _Null_unspecified sourcekitd_api_plugin_initialize_params_t
240+
// );
241+
_Null_unspecified sourcekitd_api_uid_t (*_Null_unspecified SWIFT_SENDABLE (*_Nonnull plugin_initialize_uid_get_from_cstr)(
237242
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
238-
);
239-
240-
_Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_string_ptr_t (*_Nonnull plugin_initialize_uid_get_string_ptr)(
243+
))(const char *_Null_unspecified string);
244+
245+
// The following would be more idiomatically written as follows but marking `sourcekitd_api_uid_get_string_ptr_t` as
246+
// `Sendable` hits https://github.com/swiftlang/swift/issues/83892.
247+
// _Null_unspecified SWIFT_SENDABLE sourcekitd_api_uid_get_string_ptr_t (*_Nonnull plugin_initialize_uid_get_string_ptr)(
248+
// _Null_unspecified sourcekitd_api_plugin_initialize_params_t
249+
// );
250+
const char *_Null_unspecified (*_Null_unspecified SWIFT_SENDABLE (*_Nonnull plugin_initialize_uid_get_string_ptr)(
241251
_Null_unspecified sourcekitd_api_plugin_initialize_params_t
242-
);
252+
))(_Null_unspecified sourcekitd_api_uid_t);
243253

244254
void (*_Nonnull plugin_initialize_register_custom_buffer)(
245255
_Nonnull sourcekitd_api_plugin_initialize_params_t,

Sources/Diagnose/DiagnoseCommand.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
219219
#if os(macOS)
220220
reportProgress(.collectingLogMessages(progress: 0), message: "Collecting log messages")
221221
let outputFileUrl = bundlePath.appendingPathComponent("log.txt")
222-
guard FileManager.default.createFile(atPath: try outputFileUrl.filePath, contents: nil) else {
223-
throw GenericError("Failed to create log.txt")
224-
}
222+
try FileManager.default.createFile(at: outputFileUrl, contents: nil)
225223
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
226224
let bytesCollected = AtomicInt32(initialValue: 0)
227225
let processExited = AtomicBool(initialValue: false)
@@ -320,9 +318,7 @@ package struct DiagnoseCommand: AsyncParsableCommand {
320318
@MainActor
321319
private func addSwiftVersion(toBundle bundlePath: URL) async throws {
322320
let outputFileUrl = bundlePath.appendingPathComponent("swift-versions.txt")
323-
guard FileManager.default.createFile(atPath: try outputFileUrl.filePath, contents: nil) else {
324-
throw GenericError("Failed to create file at \(outputFileUrl)")
325-
}
321+
try FileManager.default.createFile(at: outputFileUrl, contents: nil)
326322
let fileHandle = try FileHandle(forWritingTo: outputFileUrl)
327323

328324
let toolchains = try await toolchainRegistry.toolchains

Sources/SKLogging/CustomLogStringConvertible.swift

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

13-
package import Foundation
13+
public import Foundation
1414

1515
#if !NO_CRYPTO_DEPENDENCY
1616
import Crypto
@@ -33,14 +33,21 @@ package protocol CustomLogStringConvertible: CustomStringConvertible, Sendable {
3333
/// There currently is no way to get equivalent functionality in pure Swift. We
3434
/// thus pass this object to OSLog, which just forwards to `description` or
3535
/// `redactedDescription` of an object that implements `CustomLogStringConvertible`.
36-
package final class CustomLogStringConvertibleWrapper: NSObject, Sendable {
36+
public final class CustomLogStringConvertibleWrapper: NSObject, Sendable {
37+
// `CustomLogStringConvertibleWrapper` is marked as `public` to work around
38+
// https://github.com/swiftlang/swift/issues/83893
3739
private let underlyingObject: any CustomLogStringConvertible
40+
#if compiler(>=6.4)
41+
#warning(
42+
"Mark CustomLogStringConvertibleWrapper as `package` if https://github.com/swiftlang/swift/issues/83893 is fixed"
43+
)
44+
#endif
3845

3946
fileprivate init(_ underlyingObject: any CustomLogStringConvertible) {
4047
self.underlyingObject = underlyingObject
4148
}
4249

43-
package override var description: String {
50+
public override var description: String {
4451
return underlyingObject.description
4552
}
4653

Sources/SKLogging/Logging.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ package typealias LogLevel = os.OSLogType
1919
package typealias Logger = os.Logger
2020
package typealias Signposter = OSSignposter
2121

22-
extension OSSignposter: @retroactive @unchecked Sendable {}
23-
extension OSSignpostID: @retroactive @unchecked Sendable {}
22+
// -user-module-version of the 'os' module is 1062.100.1 in Xcode 16.3, which added the conformance of
23+
// `OSSignpostIntervalState` to `Sendable`
24+
#if !canImport(os, _version: 1062.100)
2425
extension OSSignpostIntervalState: @retroactive @unchecked Sendable {}
26+
#endif
27+
28+
#if compiler(>=6.4)
29+
#warning(
30+
"Remove retroactive conformance of OSSignpostIntervalState to Sendable if we no longer need to support building SourceKit-LSP with SDKs from Xcode <16.3"
31+
)
32+
#endif
2533

2634
extension os.Logger {
2735
package func makeSignposter() -> Signposter {

Sources/SKLogging/SetGlobalLogFileHandler.swift

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ import WinSDK
2525
#endif
2626

2727
#if !canImport(os) || SOURCEKIT_LSP_FORCE_NON_DARWIN_LOGGER
28-
private struct FailedToCreateFileError: Error, CustomStringConvertible {
29-
let logFile: URL
30-
31-
var description: String {
32-
return "Failed to create log file at \(logFile)"
33-
}
34-
}
35-
3628
/// The number of log file handles that have been created by this process.
3729
///
3830
/// See comment on `logFileHandle`.
@@ -59,9 +51,7 @@ func getOrCreateLogFileHandle(logDirectory: URL, logRotateCount: Int) -> FileHan
5951
do {
6052
try FileManager.default.createDirectory(at: logDirectory, withIntermediateDirectories: true)
6153
if !FileManager.default.fileExists(at: logFileUrl) {
62-
guard FileManager.default.createFile(atPath: try logFileUrl.filePath, contents: nil) else {
63-
throw FailedToCreateFileError(logFile: logFileUrl)
64-
}
54+
try FileManager.default.createFile(at: logFileUrl, contents: nil)
6555
}
6656
let newFileHandle = try FileHandle(forWritingTo: logFileUrl)
6757
logFileHandle = newFileHandle

Sources/SKTestSupport/SkipUnless.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,7 @@ package actor SkipUnless {
219219
.appendingPathComponent("swift-frontend")
220220
return try await withTestScratchDir { scratchDirectory in
221221
let input = scratchDirectory.appendingPathComponent("Input.swift")
222-
guard FileManager.default.createFile(atPath: input.path, contents: nil) else {
223-
throw GenericError("Failed to create input file")
224-
}
222+
try FileManager.default.createFile(at: input, contents: nil)
225223
// If we can't compile for wasm, this fails complaining that it can't find the stdlib for wasm.
226224
let result = try await withTimeout(defaultTimeoutDuration) {
227225
try await Process.run(

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ fileprivate extension Process {
537537
try FileManager.default.removeItem(at: responseFile)
538538
}
539539
}
540-
FileManager.default.createFile(atPath: try responseFile.filePath, contents: nil)
540+
try FileManager.default.createFile(at: responseFile, contents: nil)
541541
let handle = try FileHandle(forWritingTo: responseFile)
542542
for argument in arguments.dropFirst() {
543543
handle.write(Data((argument.spm_shellEscaped() + "\n").utf8))

Sources/SwiftExtensions/FileManagerExtensions.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,19 @@ extension FileManager {
3333
var isDirectory: ObjCBool = false
3434
return self.fileExists(atPath: url.path, isDirectory: &isDirectory) && !isDirectory.boolValue
3535
}
36+
37+
/// Same as `createFile(atPath:data:attributes)` but throws an error when file creation fails instead of returning
38+
/// `false`.
39+
package func createFile(at url: URL, contents data: Data?, attributes: [FileAttributeKey: Any]? = nil) throws {
40+
struct FileCreationFailed: Error, CustomStringConvertible {
41+
let url: URL
42+
var description: String {
43+
"Failed to create file at '\(url)'"
44+
}
45+
}
46+
let successful = createFile(atPath: try url.filePath, contents: data, attributes: attributes)
47+
guard successful else {
48+
throw FileCreationFailed(url: url)
49+
}
50+
}
3651
}

0 commit comments

Comments
 (0)