Skip to content

Commit e62473b

Browse files
authored
Merge pull request #1492 from ahoppen/fix-concurrency-warnings
Fix a few Swift concurrency warnings
2 parents ed4eea3 + 8642768 commit e62473b

20 files changed

+144
-96
lines changed

Package.swift

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
// swift-tools-version:5.8
1+
// swift-tools-version: 5.8
22

33
import Foundation
44
import PackageDescription
55

6+
let strictConcurrencySettings: [SwiftSetting] = [
7+
.enableUpcomingFeature("StrictConcurrency"),
8+
.enableUpcomingFeature("RegionBasedIsolation"),
9+
.enableUpcomingFeature("InferSendableFromCaptures"),
10+
]
11+
612
let package = Package(
713
name: "SourceKitLSP",
814
platforms: [.macOS(.v13)],
@@ -34,6 +40,7 @@ let package = Package(
3440
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
3541
],
3642
exclude: ["CMakeLists.txt"],
43+
swiftSettings: strictConcurrencySettings,
3744
linkerSettings: sourcekitLSPLinkSettings
3845
),
3946

@@ -46,7 +53,7 @@ let package = Package(
4653
"LanguageServerProtocol"
4754
],
4855
exclude: ["CMakeLists.txt"],
49-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
56+
swiftSettings: strictConcurrencySettings
5057
),
5158

5259
// MARK: CAtomics
@@ -87,7 +94,8 @@ let package = Package(
8794
.product(name: "SwiftParser", package: "swift-syntax"),
8895
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
8996
],
90-
exclude: ["CMakeLists.txt"]
97+
exclude: ["CMakeLists.txt"],
98+
swiftSettings: strictConcurrencySettings
9199
),
92100

93101
.testTarget(
@@ -100,7 +108,8 @@ let package = Package(
100108
"SKCore",
101109
"SKTestSupport",
102110
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
103-
]
111+
],
112+
swiftSettings: strictConcurrencySettings
104113
),
105114

106115
// MARK: InProcessClient
@@ -113,7 +122,8 @@ let package = Package(
113122
"SKCore",
114123
"SourceKitLSP",
115124
],
116-
exclude: ["CMakeLists.txt"]
125+
exclude: ["CMakeLists.txt"],
126+
swiftSettings: strictConcurrencySettings
117127
),
118128

119129
// MARK: LanguageServerProtocol
@@ -122,15 +132,16 @@ let package = Package(
122132
name: "LanguageServerProtocol",
123133
dependencies: [],
124134
exclude: ["CMakeLists.txt"],
125-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
135+
swiftSettings: strictConcurrencySettings
126136
),
127137

128138
.testTarget(
129139
name: "LanguageServerProtocolTests",
130140
dependencies: [
131141
"LanguageServerProtocol",
132142
"LSPTestSupport",
133-
]
143+
],
144+
swiftSettings: strictConcurrencySettings
134145
),
135146

136147
// MARK: LanguageServerProtocolJSONRPC
@@ -143,15 +154,16 @@ let package = Package(
143154
"LSPLogging",
144155
],
145156
exclude: ["CMakeLists.txt"],
146-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
157+
swiftSettings: strictConcurrencySettings
147158
),
148159

149160
.testTarget(
150161
name: "LanguageServerProtocolJSONRPCTests",
151162
dependencies: [
152163
"LanguageServerProtocolJSONRPC",
153164
"LSPTestSupport",
154-
]
165+
],
166+
swiftSettings: strictConcurrencySettings
155167
),
156168

157169
// MARK: LSPLogging
@@ -164,15 +176,16 @@ let package = Package(
164176
.product(name: "Crypto", package: "swift-crypto"),
165177
],
166178
exclude: ["CMakeLists.txt"],
167-
swiftSettings: lspLoggingSwiftSettings + [.enableExperimentalFeature("StrictConcurrency")]
179+
swiftSettings: lspLoggingSwiftSettings + strictConcurrencySettings
168180
),
169181

170182
.testTarget(
171183
name: "LSPLoggingTests",
172184
dependencies: [
173185
"LSPLogging",
174186
"SKTestSupport",
175-
]
187+
],
188+
swiftSettings: strictConcurrencySettings
176189
),
177190

178191
// MARK: LSPTestSupport
@@ -185,7 +198,8 @@ let package = Package(
185198
"LanguageServerProtocolJSONRPC",
186199
"SKSupport",
187200
"SwiftExtensions",
188-
]
201+
],
202+
swiftSettings: strictConcurrencySettings
189203
),
190204

191205
// MARK: SemanticIndex
@@ -199,14 +213,16 @@ let package = Package(
199213
"SwiftExtensions",
200214
.product(name: "IndexStoreDB", package: "indexstore-db"),
201215
],
202-
exclude: ["CMakeLists.txt"]
216+
exclude: ["CMakeLists.txt"],
217+
swiftSettings: strictConcurrencySettings
203218
),
204219

205220
.testTarget(
206221
name: "SemanticIndexTests",
207222
dependencies: [
208223
"SemanticIndex"
209-
]
224+
],
225+
swiftSettings: strictConcurrencySettings
210226
),
211227

212228
// MARK: SKCore
@@ -227,15 +243,16 @@ let package = Package(
227243
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
228244
],
229245
exclude: ["CMakeLists.txt"],
230-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
246+
swiftSettings: strictConcurrencySettings
231247
),
232248

233249
.testTarget(
234250
name: "SKCoreTests",
235251
dependencies: [
236252
"SKCore",
237253
"SKTestSupport",
238-
]
254+
],
255+
swiftSettings: strictConcurrencySettings
239256
),
240257

241258
// MARK: SKSupport
@@ -252,7 +269,7 @@ let package = Package(
252269
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
253270
],
254271
exclude: ["CMakeLists.txt"],
255-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
272+
swiftSettings: strictConcurrencySettings
256273
),
257274

258275
.testTarget(
@@ -262,7 +279,8 @@ let package = Package(
262279
"SKSupport",
263280
"SKTestSupport",
264281
"SwiftExtensions",
265-
]
282+
],
283+
swiftSettings: strictConcurrencySettings
266284
),
267285

268286
// MARK: SKSwiftPMWorkspace
@@ -279,7 +297,7 @@ let package = Package(
279297
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
280298
],
281299
exclude: ["CMakeLists.txt"],
282-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
300+
swiftSettings: strictConcurrencySettings
283301
),
284302

285303
.testTarget(
@@ -293,7 +311,8 @@ let package = Package(
293311
"SourceKitLSP",
294312
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
295313
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
296-
]
314+
],
315+
swiftSettings: strictConcurrencySettings
297316
),
298317

299318
// MARK: SKTestSupport
@@ -312,9 +331,8 @@ let package = Package(
312331
.product(name: "ISDBTestSupport", package: "indexstore-db"),
313332
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
314333
],
315-
resources: [
316-
.copy("INPUTS")
317-
]
334+
resources: [.copy("INPUTS")],
335+
swiftSettings: strictConcurrencySettings
318336
),
319337

320338
// MARK: SourceKitD
@@ -330,7 +348,7 @@ let package = Package(
330348
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
331349
],
332350
exclude: ["CMakeLists.txt", "sourcekitd_uids.swift.gyb"],
333-
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
351+
swiftSettings: strictConcurrencySettings
334352
),
335353

336354
.testTarget(
@@ -340,7 +358,8 @@ let package = Package(
340358
"SKCore",
341359
"SKTestSupport",
342360
"SwiftExtensions",
343-
]
361+
],
362+
swiftSettings: strictConcurrencySettings
344363
),
345364

346365
// MARK: SourceKitLSP
@@ -369,7 +388,8 @@ let package = Package(
369388
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
370389
.product(name: "SwiftPM-auto", package: "swift-package-manager"),
371390
],
372-
exclude: ["CMakeLists.txt"]
391+
exclude: ["CMakeLists.txt"],
392+
swiftSettings: strictConcurrencySettings
373393
),
374394

375395
.testTarget(
@@ -393,14 +413,16 @@ let package = Package(
393413
// be used by test cases that test macros (see `SwiftPMTestProject.macroPackageManifest`).
394414
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
395415
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
396-
]
416+
],
417+
swiftSettings: strictConcurrencySettings
397418
),
398419

399420
// MARK: SwiftExtensions
400421

401422
.target(
402423
name: "SwiftExtensions",
403-
exclude: ["CMakeLists.txt"]
424+
exclude: ["CMakeLists.txt"],
425+
swiftSettings: strictConcurrencySettings
404426
),
405427
]
406428
)

Sources/Diagnose/CommandLineArgumentsReducer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ fileprivate class CommandLineArgumentReducer {
6262
///
6363
/// If `simultaneousRemove` is set, the reducer will try to remove that many arguments at once. This is useful to
6464
/// quickly remove multiple arguments from the request.
65+
@MainActor
6566
private func reduce(initialRequestInfo: RequestInfo, simultaneousRemove: Int) async throws -> RequestInfo {
6667
guard initialRequestInfo.compilerArgs.count > simultaneousRemove else {
6768
// Trying to remove more command line arguments than we have. This isn't going to work.

Sources/Diagnose/IndexCommand.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import SwiftExtensions
2121

2222
import struct TSCBasic.AbsolutePath
2323
import class TSCBasic.Process
24-
import var TSCBasic.stderrStream
2524
import class TSCUtility.PercentProgressAnimation
2625

2726
private actor IndexLogMessageHandler: MessageHandler {

Sources/Diagnose/ReduceCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SKCore
1616

1717
import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
19-
import var TSCBasic.stderrStream
2019
import class TSCUtility.PercentProgressAnimation
2120

2221
public struct ReduceCommand: AsyncParsableCommand {
@@ -77,7 +76,7 @@ public struct ReduceCommand: AsyncParsableCommand {
7776
throw ReductionError("Unable to find sourcekitd.framework")
7877
}
7978

80-
let progressBar = PercentProgressAnimation(stream: stderrStream, header: "Reducing sourcekitd issue")
79+
let progressBar = PercentProgressAnimation(stream: stderrStreamConcurrencySafe, header: "Reducing sourcekitd issue")
8180

8281
let request = try String(contentsOfFile: sourcekitdRequestPath)
8382
let requestInfo = try RequestInfo(request: request)

Sources/Diagnose/ReduceFrontendCommand.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import SKCore
1616

1717
import struct TSCBasic.AbsolutePath
1818
import class TSCBasic.Process
19-
import var TSCBasic.stderrStream
2019
import class TSCUtility.PercentProgressAnimation
2120

2221
public struct ReduceFrontendCommand: AsyncParsableCommand {
@@ -86,7 +85,7 @@ public struct ReduceFrontendCommand: AsyncParsableCommand {
8685
}
8786

8887
let progressBar = PercentProgressAnimation(
89-
stream: stderrStream,
88+
stream: stderrStreamConcurrencySafe,
9089
header: "Reducing swift-frontend crash"
9190
)
9291

Sources/LSPLogging/LoggingScope.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public final class LoggingScope {
3939
public func withLoggingSubsystemAndScope<Result>(
4040
subsystem: String,
4141
scope: String?,
42-
_ operation: () throws -> Result
42+
@_inheritActorContext _ operation: @Sendable () throws -> Result
4343
) rethrows -> Result {
4444
return try LoggingScope.$_subsystem.withValue(subsystem) {
4545
return try LoggingScope.$_scope.withValue(scope, operation: operation)
@@ -50,7 +50,7 @@ public func withLoggingSubsystemAndScope<Result>(
5050
public func withLoggingSubsystemAndScope<Result>(
5151
subsystem: String,
5252
scope: String?,
53-
_ operation: () async throws -> Result
53+
@_inheritActorContext _ operation: @Sendable () async throws -> Result
5454
) async rethrows -> Result {
5555
return try await LoggingScope.$_subsystem.withValue(subsystem) {
5656
return try await LoggingScope.$_scope.withValue(scope, operation: operation)

Sources/SKSupport/Process+Run.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ extension Process {
4343
arguments: [String],
4444
environmentBlock: ProcessEnvironmentBlock = ProcessEnv.block,
4545
workingDirectory: AbsolutePath?,
46-
outputRedirection: OutputRedirection = .collect,
46+
outputRedirection: OutputRedirection = .collect(redirectStderr: false),
4747
startNewProcessGroup: Bool = true,
4848
loggingHandler: LoggingHandler? = .none
4949
) throws -> Process {
@@ -93,7 +93,7 @@ extension Process {
9393
arguments: [String],
9494
environmentBlock: ProcessEnvironmentBlock = ProcessEnv.block,
9595
workingDirectory: AbsolutePath?,
96-
outputRedirection: OutputRedirection = .collect,
96+
outputRedirection: OutputRedirection = .collect(redirectStderr: false),
9797
startNewProcessGroup: Bool = true,
9898
loggingHandler: LoggingHandler? = .none
9999
) async throws -> ProcessResult {

Sources/SKSwiftPMWorkspace/SwiftPMBuildSystem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ extension SwiftPMBuildSystem {
328328
)
329329

330330
let plan = try BuildPlan(
331-
productsBuildParameters: destinationBuildParameters,
331+
destinationBuildParameters: destinationBuildParameters,
332332
toolsBuildParameters: toolsBuildParameters,
333333
graph: modulesGraph,
334334
fileSystem: fileSystem,

Sources/SKTestSupport/MultiFileTestProject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class MultiFileTestProject {
8585
enableBackgroundIndexing: Bool = false,
8686
usePullDiagnostics: Bool = true,
8787
preInitialization: ((TestSourceKitLSPClient) -> Void)? = nil,
88-
cleanUp: (() -> Void)? = nil,
88+
cleanUp: (@Sendable () -> Void)? = nil,
8989
testName: String = #function
9090
) async throws {
9191
scratchDirectory = try testScratchDir(testName: testName)

Sources/SKTestSupport/SwiftPMTestProject.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public class SwiftPMTestProject: MultiFileTestProject {
156156
usePullDiagnostics: Bool = true,
157157
pollIndex: Bool = true,
158158
preInitialization: ((TestSourceKitLSPClient) -> Void)? = nil,
159-
cleanUp: (() -> Void)? = nil,
159+
cleanUp: (@Sendable () -> Void)? = nil,
160160
testName: String = #function
161161
) async throws {
162162
var filesByPath: [RelativeFileLocation: String] = [:]

0 commit comments

Comments
 (0)