Skip to content

Commit c43cffd

Browse files
committed
Change all variables that are Atomic* types to not be nonisolated(unsafe)
Since the `Atomic*` types can not be marked as `Sendable` (because they aren’t C structs), we can change the variables to constants and can remove `nonisolated(unsafe)`.
1 parent 76a0db7 commit c43cffd

File tree

9 files changed

+18
-23
lines changed

9 files changed

+18
-23
lines changed

Sources/InProcessClient/InProcessSourceKitLSPClient.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ import SourceKitLSP
1919
public final class InProcessSourceKitLSPClient: Sendable {
2020
private let server: SourceKitLSPServer
2121

22-
/// `nonisolated(unsafe)` if fine because `nextRequestID` is atomic.
23-
private nonisolated(unsafe) var nextRequestID = AtomicUInt32(initialValue: 0)
22+
private let nextRequestID = AtomicUInt32(initialValue: 0)
2423

2524
/// Create a new `SourceKitLSPServer`. An `InitializeRequest` is automatically sent to the server.
2625
///

Sources/SKCore/TaskScheduler.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
126126
/// Every time `execute` gets called, a new task is placed in this continuation. See comment on `executionTask`.
127127
private let executionTaskCreatedContinuation: AsyncStream<Task<ExecutionTaskFinishStatus, Never>>.Continuation
128128

129-
nonisolated(unsafe) private var _priority: AtomicUInt8
129+
private let _priority: AtomicUInt8
130130

131131
/// The latest known priority of the task.
132132
///
@@ -147,9 +147,9 @@ public actor QueuedTask<TaskDescription: TaskDescriptionProtocol> {
147147
private var cancelledToBeRescheduled: Bool = false
148148

149149
/// Whether `resultTask` has been cancelled.
150-
private nonisolated(unsafe) var resultTaskCancelled: AtomicBool = .init(initialValue: false)
150+
private let resultTaskCancelled: AtomicBool = .init(initialValue: false)
151151

152-
private nonisolated(unsafe) var _isExecuting: AtomicBool = .init(initialValue: false)
152+
private let _isExecuting: AtomicBool = .init(initialValue: false)
153153

154154
/// Whether the task is currently executing or still queued to be executed later.
155155
public nonisolated var isExecuting: Bool {

Sources/SKSupport/Atomics.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import CAtomics
1616
#warning("We should be able to use atomics in the stdlib when we raise the deployment target to require Swift 6")
1717
#endif
1818

19-
public class AtomicBool {
20-
private let atomic: UnsafeMutablePointer<CAtomicUInt32>
19+
public final class AtomicBool: Sendable {
20+
private nonisolated(unsafe) let atomic: UnsafeMutablePointer<CAtomicUInt32>
2121

2222
public init(initialValue: Bool) {
2323
self.atomic = atomic_uint32_create(initialValue ? 1 : 0)
@@ -37,8 +37,8 @@ public class AtomicBool {
3737
}
3838
}
3939

40-
public class AtomicUInt8 {
41-
private let atomic: UnsafeMutablePointer<CAtomicUInt32>
40+
public final class AtomicUInt8: Sendable {
41+
private nonisolated(unsafe) let atomic: UnsafeMutablePointer<CAtomicUInt32>
4242

4343
public init(initialValue: UInt8) {
4444
self.atomic = atomic_uint32_create(UInt32(initialValue))
@@ -58,8 +58,8 @@ public class AtomicUInt8 {
5858
}
5959
}
6060

61-
public class AtomicUInt32 {
62-
private let atomic: UnsafeMutablePointer<CAtomicUInt32>
61+
public final class AtomicUInt32: Sendable {
62+
private nonisolated(unsafe) let atomic: UnsafeMutablePointer<CAtomicUInt32>
6363

6464
public init(initialValue: UInt32) {
6565
self.atomic = atomic_uint32_create(initialValue)

Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ fileprivate extension ConfiguredTarget {
8787
static let forPackageManifest = ConfiguredTarget(targetID: "", runDestinationID: "")
8888
}
8989

90-
/// `nonisolated(unsafe)` is fine because `preparationTaskID` is atomic.
91-
fileprivate nonisolated(unsafe) var preparationTaskID: AtomicUInt32 = AtomicUInt32(initialValue: 0)
90+
fileprivate let preparationTaskID: AtomicUInt32 = AtomicUInt32(initialValue: 0)
9291

9392
/// Swift Package Manager build system and workspace support.
9493
///

Sources/SKTestSupport/TestSourceKitLSPClient.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public final class TestSourceKitLSPClient: MessageHandler {
4141
public typealias RequestHandler<Request: RequestType> = @Sendable (Request) -> Request.Response
4242

4343
/// The ID that should be assigned to the next request sent to the `server`.
44-
/// `nonisolated(unsafe)` is fine because `nextRequestID` is atomic.
45-
private nonisolated(unsafe) var nextRequestID = AtomicUInt32(initialValue: 0)
44+
private let nextRequestID = AtomicUInt32(initialValue: 0)
4645

4746
/// The server that handles the requests.
4847
public let server: SourceKitLSPServer
@@ -70,7 +69,7 @@ public final class TestSourceKitLSPClient: MessageHandler {
7069
///
7170
/// `isOneShort` if the request handler should only serve a single request and should be removed from
7271
/// `requestHandlers` after it has been called.
73-
private nonisolated(unsafe) var requestHandlers: ThreadSafeBox<[(requestHandler: Sendable, isOneShot: Bool)]> =
72+
private let requestHandlers: ThreadSafeBox<[(requestHandler: Sendable, isOneShot: Bool)]> =
7473
ThreadSafeBox(initialValue: [])
7574

7675
/// A closure that is called when the `TestSourceKitLSPClient` is destructed.

Sources/SemanticIndex/UpdateIndexStoreTaskDescription.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftExtensions
2020
import struct TSCBasic.AbsolutePath
2121
import class TSCBasic.Process
2222

23-
private nonisolated(unsafe) var updateIndexStoreIDForLogging = AtomicUInt32(initialValue: 1)
23+
private let updateIndexStoreIDForLogging = AtomicUInt32(initialValue: 1)
2424

2525
public enum FileToIndex: CustomLogStringConvertible {
2626
/// A non-header file

Sources/SourceKitLSP/SourceKitLSPServer.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ fileprivate final class RequestAndReply<Params: RequestType>: Sendable {
4040
private let replyBlock: @Sendable (LSPResult<Params.Response>) -> Void
4141

4242
/// Whether a reply has been made. Every request must reply exactly once.
43-
/// `nonisolated(unsafe)` is fine because `replied` is atomic.
44-
private nonisolated(unsafe) var replied: AtomicBool = AtomicBool(initialValue: false)
43+
private let replied: AtomicBool = AtomicBool(initialValue: false)
4544

4645
public init(_ request: Params, reply: @escaping @Sendable (LSPResult<Params.Response>) -> Void) {
4746
self.params = request
@@ -539,8 +538,7 @@ public actor SourceKitLSPServer {
539538

540539
// MARK: - MessageHandler
541540

542-
// nonisolated(unsafe) is fine because `notificationIDForLogging` is atomic.
543-
private nonisolated(unsafe) var notificationIDForLogging = AtomicUInt32(initialValue: 1)
541+
private let notificationIDForLogging = AtomicUInt32(initialValue: 1)
544542

545543
extension SourceKitLSPServer: MessageHandler {
546544
public nonisolated func handle(_ params: some NotificationType) {

Tests/SourceKitDTests/SourceKitDRegistryTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final class SourceKitDRegistryTests: XCTestCase {
5959
}
6060
}
6161

62-
private nonisolated(unsafe) var nextToken = AtomicUInt32(initialValue: 0)
62+
private let nextToken = AtomicUInt32(initialValue: 0)
6363

6464
final class FakeSourceKitD: SourceKitD {
6565
let token: UInt32

Tests/SourceKitLSPTests/PullDiagnosticsTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ final class PullDiagnosticsTests: XCTestCase {
253253
}
254254

255255
func testDiagnosticsWaitForDocumentToBePrepared() async throws {
256-
nonisolated(unsafe) var diagnosticRequestSent = AtomicBool(initialValue: false)
256+
let diagnosticRequestSent = AtomicBool(initialValue: false)
257257
var serverOptions = SourceKitLSPServer.Options.testDefault
258258
serverOptions.indexTestHooks.preparationTaskDidStart = { @Sendable taskDescription in
259259
// Only start preparation after we sent the diagnostic request. In almost all cases, this should not give

0 commit comments

Comments
 (0)