From 052cdc6ee8076b6e7a8c2885511252e64c80b26c Mon Sep 17 00:00:00 2001 From: Anthony Latsis Date: Mon, 23 Jun 2025 19:47:25 +0100 Subject: [PATCH 1/2] .swift-format: Enable `ReturnVoidInsteadOfEmptyTuple` --- .swift-format | 3 ++- .../CompletionScoring/Text/CandidateBatch.swift | 14 +++++++------- Sources/CompletionScoring/Text/Pattern.swift | 2 +- .../Utilities/Serialization/BinaryEncoder.swift | 2 +- .../Utilities/SwiftExtensions.swift | 8 ++++---- .../TestExtensions.swift | 6 +++--- Sources/CompletionScoringTestSupport/Timings.swift | 2 +- .../DocCReferenceResolutionService.swift | 2 +- .../SourceKitLSP/Swift/SwiftLanguageService.swift | 2 +- Sources/SwiftSourceKitPlugin/Plugin.swift | 2 +- .../CompilationDatabaseTests.swift | 2 +- Tests/CompletionScoringTests/TopKTests.swift | 2 +- .../XCTestCaseScoringAdditions.swift | 2 +- 13 files changed, 25 insertions(+), 24 deletions(-) diff --git a/.swift-format b/.swift-format index 41a022f26..c258291d3 100644 --- a/.swift-format +++ b/.swift-format @@ -13,6 +13,7 @@ "NoBlockComments": false, "OrderedImports": true, "UseLetInEveryBoundCaseVariable": false, - "UseSynthesizedInitializer": false + "UseSynthesizedInitializer": false, + "ReturnVoidInsteadOfEmptyTuple": true, } } diff --git a/Sources/CompletionScoring/Text/CandidateBatch.swift b/Sources/CompletionScoring/Text/CandidateBatch.swift index 4e846d05b..87c6f7309 100644 --- a/Sources/CompletionScoring/Text/CandidateBatch.swift +++ b/Sources/CompletionScoring/Text/CandidateBatch.swift @@ -99,13 +99,13 @@ package struct CandidateBatch: Sendable { /// Don't add a method that returns a candidate, the candidates have unsafe pointers back into the batch, and /// must not outlive it. @inline(__always) - func enumerate(body: (Candidate) throws -> ()) rethrows { + func enumerate(body: (Candidate) throws -> Void) rethrows { for idx in 0.., body: (Int, Candidate) throws -> ()) rethrows { + func enumerate(_ range: Range, body: (Int, Candidate) throws -> Void) rethrows { precondition(range.lowerBound >= 0) precondition(range.upperBound <= count) for idx in range { @@ -224,15 +224,15 @@ package struct CandidateBatch: Sendable { append(contentsOf: candidates, contentType: contentType) } - package func enumerate(body: (Candidate) throws -> ()) rethrows { + package func enumerate(body: (Candidate) throws -> Void) rethrows { try readonlyStorage.enumerate(body: body) } - package func enumerate(body: (Int, Candidate) throws -> ()) rethrows { + package func enumerate(body: (Int, Candidate) throws -> Void) rethrows { try readonlyStorage.enumerate(0.., body: (Int, Candidate) throws -> ()) rethrows { + internal func enumerate(_ range: Range, body: (Int, Candidate) throws -> Void) rethrows { try readonlyStorage.enumerate(range, body: body) } @@ -283,7 +283,7 @@ package struct CandidateBatch: Sendable { count > 0 } - private mutating func mutate(body: (inout UnsafeStorage) -> ()) { + private mutating func mutate(body: (inout UnsafeStorage) -> Void) { if !isKnownUniquelyReferenced(&__storageBox_useAccessor) { __storageBox_useAccessor = __storageBox_useAccessor.copy() } @@ -524,7 +524,7 @@ package struct Candidate { // Creates a buffer of `capacity` elements of type `T?`, each initially set to nil. /// /// After running `initialize`, returns all elements that were set to non-`nil` values. -private func compactScratchArea(capacity: Int, initialize: (UnsafeMutablePointer) -> ()) -> [T] { +private func compactScratchArea(capacity: Int, initialize: (UnsafeMutablePointer) -> Void) -> [T] { let scratchArea = UnsafeMutablePointer.allocate(capacity: capacity) scratchArea.initialize(repeating: nil, count: capacity) defer { diff --git a/Sources/CompletionScoring/Text/Pattern.swift b/Sources/CompletionScoring/Text/Pattern.swift index c0c3df73a..016661e81 100644 --- a/Sources/CompletionScoring/Text/Pattern.swift +++ b/Sources/CompletionScoring/Text/Pattern.swift @@ -752,7 +752,7 @@ extension Pattern { self.baseNameLength = baseNameLength ?? byteCount } - func enumerate(body: (Range) -> ()) { + func enumerate(body: (Range) -> Void) { var position = 0 for token in tokens { body(position ..+ token.length) diff --git a/Sources/CompletionScoring/Utilities/Serialization/BinaryEncoder.swift b/Sources/CompletionScoring/Utilities/Serialization/BinaryEncoder.swift index 81f37c32e..7fa78cc49 100644 --- a/Sources/CompletionScoring/Utilities/Serialization/BinaryEncoder.swift +++ b/Sources/CompletionScoring/Utilities/Serialization/BinaryEncoder.swift @@ -29,7 +29,7 @@ package struct BinaryEncoder { /// - body: a closure accepting a `BinaryEncoder` that you can make `write(_:)` calls against to populate the /// archive. /// - Returns: a byte array that can be used with `BinaryDecoder` - static func encode(contentVersion: Int, _ body: (inout Self) -> ()) -> [UInt8] { + static func encode(contentVersion: Int, _ body: (inout Self) -> Void) -> [UInt8] { var encoder = BinaryEncoder(contentVersion: contentVersion) body(&encoder) return encoder.stream diff --git a/Sources/CompletionScoring/Utilities/SwiftExtensions.swift b/Sources/CompletionScoring/Utilities/SwiftExtensions.swift index 1a71d9701..42eeb8cf4 100644 --- a/Sources/CompletionScoring/Utilities/SwiftExtensions.swift +++ b/Sources/CompletionScoring/Utilities/SwiftExtensions.swift @@ -290,7 +290,7 @@ protocol ContiguousZeroBasedIndexedCollection: Collection where Index == Int { } extension ContiguousZeroBasedIndexedCollection { - func slicedConcurrentForEachSliceRange(body: @Sendable (Range) -> ()) { + func slicedConcurrentForEachSliceRange(body: @Sendable (Range) -> Void) { // We want to use `DispatchQueue.concurrentPerform`, but we want to be called only a few times. So that we // can amortize per-callback work. We also want to oversubscribe so that we can efficiently use // heterogeneous CPUs. If we had 4 efficiency cores, and 4 performance cores, and we dispatched 8 work items @@ -336,7 +336,7 @@ extension Array { /// } /// ``` package func unsafeSlicedConcurrentMap( - writer: @Sendable (ArraySlice, _ destination: UnsafeMutablePointer) -> () + writer: @Sendable (ArraySlice, _ destination: UnsafeMutablePointer) -> Void ) -> [T] where Self: Sendable { return Array(unsafeUninitializedCapacity: count) { buffer, initializedCount in if let bufferBase = buffer.baseAddress { @@ -353,13 +353,13 @@ extension Array { } /// Concurrent for-each on self, but slice based to allow the body to amortize work across callbacks - func slicedConcurrentForEach(body: @Sendable (ArraySlice) -> ()) where Self: Sendable { + func slicedConcurrentForEach(body: @Sendable (ArraySlice) -> Void) where Self: Sendable { slicedConcurrentForEachSliceRange { sliceRange in body(self[sliceRange]) } } - func concurrentForEach(body: @Sendable (Element) -> ()) where Self: Sendable { + func concurrentForEach(body: @Sendable (Element) -> Void) where Self: Sendable { DispatchQueue.concurrentPerform(iterations: count) { index in body(self[index]) } diff --git a/Sources/CompletionScoringTestSupport/TestExtensions.swift b/Sources/CompletionScoringTestSupport/TestExtensions.swift index aff451eed..f24c3fcfc 100644 --- a/Sources/CompletionScoringTestSupport/TestExtensions.swift +++ b/Sources/CompletionScoringTestSupport/TestExtensions.swift @@ -18,7 +18,7 @@ import XCTest @inline(never) package func drain(_ value: T) {} -func duration(of body: () -> ()) -> TimeInterval { +func duration(of body: () -> Void) -> TimeInterval { let start = ProcessInfo.processInfo.systemUptime body() return ProcessInfo.processInfo.systemUptime - start @@ -30,7 +30,7 @@ extension RandomNumberGenerator { } } -package func withEachPermutation(_ a: T, _ b: T, body: (T, T) -> ()) { +package func withEachPermutation(_ a: T, _ b: T, body: (T, T) -> Void) { body(a, b) body(b, a) } @@ -134,7 +134,7 @@ extension XCTestCase { /// Run `body()` `iterations`, gathering timing stats, and print them. /// In between runs, coax for the machine into an arbitrary but consistent thermal state by either sleeping or doing /// pointless work so that results are more comparable run to run, no matter else is happening on the machine. - package func gaugeTiming(iterations: Int = 1, testName: String = #function, _ body: () -> ()) { + package func gaugeTiming(iterations: Int = 1, testName: String = #function, _ body: () -> Void) { let logFD = tryOrFailTest(try Self.openPerformanceLog(), message: "Failed to open performance log") var timings = Timings() for iteration in 0.. ()) { + mutating func mutateWrappedValue(mutator: (inout Wrapped) -> Void) { if var wrapped = self { self = nil // Avoid COW for clients. mutator(&wrapped) diff --git a/Sources/DocCDocumentation/DocCReferenceResolutionService.swift b/Sources/DocCDocumentation/DocCReferenceResolutionService.swift index dd1f1468e..220056084 100644 --- a/Sources/DocCDocumentation/DocCReferenceResolutionService.swift +++ b/Sources/DocCDocumentation/DocCReferenceResolutionService.swift @@ -45,7 +45,7 @@ final class DocCReferenceResolutionService: DocumentationService, Sendable { func process( _ message: DocumentationServer.Message, - completion: @escaping (DocumentationServer.Message) -> () + completion: @escaping (DocumentationServer.Message) -> Void ) { do { let response = try process(message) diff --git a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift index 54b2d7a97..f0c4ca7ed 100644 --- a/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift +++ b/Sources/SourceKitLSP/Swift/SwiftLanguageService.swift @@ -272,7 +272,7 @@ package actor SwiftLanguageService: LanguageService, Sendable { } /// - Important: For testing only - package func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> ())?) async { + package func setReusedNodeCallback(_ callback: (@Sendable (_ node: Syntax) -> Void)?) async { await self.syntaxTreeManager.setReusedNodeCallback(callback) } diff --git a/Sources/SwiftSourceKitPlugin/Plugin.swift b/Sources/SwiftSourceKitPlugin/Plugin.swift index 145637717..9372fda9e 100644 --- a/Sources/SwiftSourceKitPlugin/Plugin.swift +++ b/Sources/SwiftSourceKitPlugin/Plugin.swift @@ -85,7 +85,7 @@ final class RequestHandler: Sendable { } } - func sourcekitdProducesResult(body: @escaping @Sendable () async -> ()) -> HandleRequestResult { + func sourcekitdProducesResult(body: @escaping @Sendable () async -> Void) -> HandleRequestResult { requestHandlingQueue.async { await body() } diff --git a/Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift b/Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift index 11ef11698..79ceae540 100644 --- a/Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift +++ b/Tests/BuildSystemIntegrationTests/CompilationDatabaseTests.swift @@ -433,7 +433,7 @@ fileprivate var pathSeparator: String { private func checkCompilationDatabaseBuildSystem( _ compdb: String, - block: @Sendable (JSONCompilationDatabaseBuildSystem) async throws -> () + block: @Sendable (JSONCompilationDatabaseBuildSystem) async throws -> Void ) async throws { try await withTestScratchDir { tempDir in let configPath = tempDir.appendingPathComponent(JSONCompilationDatabaseBuildSystem.dbName) diff --git a/Tests/CompletionScoringTests/TopKTests.swift b/Tests/CompletionScoringTests/TopKTests.swift index 45f5694b3..0df84f2f9 100644 --- a/Tests/CompletionScoringTests/TopKTests.swift +++ b/Tests/CompletionScoringTests/TopKTests.swift @@ -36,7 +36,7 @@ class TopKTests: XCTestCase { } func testSelectTopKExhaustively() throws { - func allCombinations(count: Int, body: ([Int]) -> ()) { + func allCombinations(count: Int, body: ([Int]) -> Void) { var array = [Int](repeating: 0, count: count) func enumerate(slot: Int) { if slot == array.count { diff --git a/Tests/CompletionScoringTests/XCTestCaseScoringAdditions.swift b/Tests/CompletionScoringTests/XCTestCaseScoringAdditions.swift index a64cf0022..bab93cf57 100644 --- a/Tests/CompletionScoringTests/XCTestCaseScoringAdditions.swift +++ b/Tests/CompletionScoringTests/XCTestCaseScoringAdditions.swift @@ -92,7 +92,7 @@ extension XCTestCase { } extension String { - func enumeratePrefixes(includeLowercased: Bool, body: (String) -> ()) { + func enumeratePrefixes(includeLowercased: Bool, body: (String) -> Void) { for length in 1.. Date: Mon, 23 Jun 2025 19:48:20 +0100 Subject: [PATCH 2/2] .swift-format: Enable `NoVoidReturnOnFunctionSignature` --- .swift-format | 1 + Sources/SourceKitD/SourceKitD.swift | 2 +- Tests/SourceKitLSPTests/ExpectedIndexTaskTracker.swift | 8 ++++---- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.swift-format b/.swift-format index c258291d3..176687e28 100644 --- a/.swift-format +++ b/.swift-format @@ -15,5 +15,6 @@ "UseLetInEveryBoundCaseVariable": false, "UseSynthesizedInitializer": false, "ReturnVoidInsteadOfEmptyTuple": true, + "NoVoidReturnOnFunctionSignature": true, } } diff --git a/Sources/SourceKitD/SourceKitD.swift b/Sources/SourceKitD/SourceKitD.swift index ac1bfaff0..7ac6a80f6 100644 --- a/Sources/SourceKitD/SourceKitD.swift +++ b/Sources/SourceKitD/SourceKitD.swift @@ -482,7 +482,7 @@ package actor SourceKitD { /// A sourcekitd notification handler in a class to allow it to be uniquely referenced. package protocol SKDNotificationHandler: AnyObject, Sendable { - func notification(_: SKDResponse) -> Void + func notification(_: SKDResponse) } struct WeakSKDNotificationHandler: Sendable { diff --git a/Tests/SourceKitLSPTests/ExpectedIndexTaskTracker.swift b/Tests/SourceKitLSPTests/ExpectedIndexTaskTracker.swift index 37a1b598e..13ddaeba6 100644 --- a/Tests/SourceKitLSPTests/ExpectedIndexTaskTracker.swift +++ b/Tests/SourceKitLSPTests/ExpectedIndexTaskTracker.swift @@ -142,7 +142,7 @@ actor ExpectedIndexTaskTracker { ) } - func preparationTaskDidStart(taskDescription: PreparationTaskDescription) -> Void { + func preparationTaskDidStart(taskDescription: PreparationTaskDescription) { guard let expectedPreparations else { return } @@ -160,7 +160,7 @@ actor ExpectedIndexTaskTracker { } } - func preparationTaskDidFinish(taskDescription: PreparationTaskDescription) -> Void { + func preparationTaskDidFinish(taskDescription: PreparationTaskDescription) { guard let expectedPreparations else { return } @@ -191,7 +191,7 @@ actor ExpectedIndexTaskTracker { } } - func updateIndexStoreTaskDidStart(taskDescription: UpdateIndexStoreTaskDescription) -> Void { + func updateIndexStoreTaskDidStart(taskDescription: UpdateIndexStoreTaskDescription) { if Task.isCancelled { logger.debug( """ @@ -212,7 +212,7 @@ actor ExpectedIndexTaskTracker { } } - func updateIndexStoreTaskDidFinish(taskDescription: UpdateIndexStoreTaskDescription) -> Void { + func updateIndexStoreTaskDidFinish(taskDescription: UpdateIndexStoreTaskDescription) { guard let expectedIndexStoreUpdates else { return }