Skip to content

Commit a0d1507

Browse files
committed
Manually order nonisolated(nonsending) relative to @escaping in public interfaces
1 parent 7bf2acf commit a0d1507

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed

Sources/LanguageServerProtocolTransport/JSONRPCConnection.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,11 @@ public final class JSONRPCConnection: Connection {
284284
/// - parameter receiveHandler: The message handler to invoke for requests received on the `inFD`.
285285
///
286286
/// - Important: `start` must be called before sending any data over the `JSONRPCConnection`.
287+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
288+
// swift-format-ignore
287289
public func start(
288290
receiveHandler: MessageHandler,
289-
closeHandler: @escaping @Sendable () async -> Void = {}
291+
closeHandler: nonisolated(nonsending) @escaping @Sendable () async -> Void = {}
290292
) {
291293
queue.sync {
292294
precondition(state == .created)

Sources/ToolsProtocolsSwiftExtensions/AsyncQueue.swift

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ public final class AsyncQueue<TaskMetadata: DependencyTracker>: Sendable {
8989
/// If this is a barrier, all previously scheduled tasks are guaranteed to
9090
/// finish execution before the barrier is executed and all tasks that are
9191
/// added later will wait until the barrier finishes execution.
92+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
93+
// swift-format-ignore
9294
@discardableResult
9395
public func async<Success: Sendable>(
9496
priority: TaskPriority? = nil,
9597
metadata: TaskMetadata,
96-
@_inheritActorContext operation: @escaping @Sendable () async -> Success
98+
@_inheritActorContext operation: nonisolated(nonsending) @escaping @Sendable () async -> Success
9799
) -> Task<Success, Never> {
98100
let throwingTask = asyncThrowing(priority: priority, metadata: metadata, operation: operation)
99101
return Task(priority: priority) {
@@ -111,10 +113,12 @@ public final class AsyncQueue<TaskMetadata: DependencyTracker>: Sendable {
111113
///
112114
/// - Important: The caller is responsible for handling any errors thrown from
113115
/// the operation by awaiting the result of the returned task.
116+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
117+
// swift-format-ignore
114118
public func asyncThrowing<Success: Sendable>(
115119
priority: TaskPriority? = nil,
116120
metadata: TaskMetadata,
117-
@_inheritActorContext operation: @escaping @Sendable () async throws -> Success
121+
@_inheritActorContext operation: nonisolated(nonsending) @escaping @Sendable () async throws -> Success
118122
) -> Task<Success, any Error> {
119123
let id = UUID()
120124

@@ -175,19 +179,23 @@ public final class AsyncQueue<TaskMetadata: DependencyTracker>: Sendable {
175179
extension AsyncQueue where TaskMetadata == Serial {
176180
/// Same as ``async(priority:operation:)`` but specialized for serial queues
177181
/// that don't specify any metadata.
182+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
183+
// swift-format-ignore
178184
@discardableResult
179185
public func async<Success: Sendable>(
180186
priority: TaskPriority? = nil,
181-
@_inheritActorContext operation: @escaping @Sendable () async -> Success
187+
@_inheritActorContext operation: nonisolated(nonsending) @escaping @Sendable () async -> Success
182188
) -> Task<Success, Never> {
183189
return self.async(priority: priority, metadata: Serial(), operation: operation)
184190
}
185191

186192
/// Same as ``asyncThrowing(priority:metadata:operation:)`` but specialized
187193
/// for serial queues that don't specify any metadata.
194+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
195+
// swift-format-ignore
188196
public func asyncThrowing<Success: Sendable>(
189197
priority: TaskPriority? = nil,
190-
@_inheritActorContext operation: @escaping @Sendable () async throws -> Success
198+
@_inheritActorContext operation: nonisolated(nonsending) @escaping @Sendable () async throws -> Success
191199
) -> Task<Success, any Error> {
192200
return self.asyncThrowing(priority: priority, metadata: Serial(), operation: operation)
193201
}

Sources/ToolsProtocolsSwiftExtensions/AsyncUtils.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ extension Task where Failure == Never {
137137

138138
extension Collection where Self: Sendable, Element: Sendable {
139139
/// Transforms all elements in the collection concurrently and returns the transformed collection.
140+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
141+
// swift-format-ignore
140142
@_spi(SourceKitLSP) public func concurrentMap<TransformedElement: Sendable>(
141143
maxConcurrentTasks: Int = ProcessInfo.processInfo.activeProcessorCount,
142-
_ transform: @escaping @Sendable (Element) async -> TransformedElement
144+
_ transform: nonisolated(nonsending) @escaping @Sendable (Element) async -> TransformedElement
143145
) async -> [TransformedElement] {
144146
let indexedResults = await withTaskGroup(of: (index: Int, element: TransformedElement).self) { taskGroup in
145147
var indexedResults: [(index: Int, element: TransformedElement)] = []
@@ -170,7 +172,9 @@ extension Collection where Self: Sendable, Element: Sendable {
170172
}
171173

172174
/// Invoke `body` for every element in the collection and wait for all calls of `body` to finish
173-
@_spi(SourceKitLSP) public func concurrentForEach(_ body: @escaping @Sendable (Element) async -> Void) async {
175+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
176+
// swift-format-ignore
177+
@_spi(SourceKitLSP) public func concurrentForEach(_ body: nonisolated(nonsending) @escaping @Sendable (Element) async -> Void) async {
174178
await withTaskGroup(of: Void.self) { taskGroup in
175179
for element in self {
176180
taskGroup.addTask {

Sources/ToolsProtocolsSwiftExtensions/Task+WithPriorityChangedHandler.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
/// `pollingInterval`.
1717
/// The function assumes that the original priority of the task is `initialPriority`. If the task priority changed
1818
/// compared to `initialPriority`, the `taskPriorityChanged` will be called.
19+
// Workaround formatter issue: https://github.com/swiftlang/swift-format/issues/1081
20+
// swift-format-ignore
1921
@_spi(SourceKitLSP) public func withTaskPriorityChangedHandler<T: Sendable>(
2022
initialPriority: TaskPriority = Task.currentPriority,
2123
pollingInterval: Duration = .seconds(0.1),
22-
@_inheritActorContext operation: @escaping @Sendable () async throws -> T,
24+
@_inheritActorContext operation: nonisolated(nonsending) @escaping @Sendable () async throws -> T,
2325
taskPriorityChanged: @escaping @Sendable () -> Void
2426
) async throws -> T {
2527
let lastPriority = ThreadSafeBox(initialValue: initialPriority)

0 commit comments

Comments
 (0)