Skip to content

Commit 1524989

Browse files
authored
Enable strict concurrency (#686)
### Motivation: Catch potential data races at build time. ### Modifications: - Enabled unconditional strict concurrency complete checking. - Enabled warnings-as-errors on Swift 6 Linux pipelines. - Made a few fixes to be strict concurrency-clean. ### Result: Fewer potential data races can sneak in. ### Test Plan Ran tests locally, did not see any more warnings or errors.
1 parent cdc23b5 commit 1524989

File tree

14 files changed

+18
-29
lines changed

14 files changed

+18
-29
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
with:
1414
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
1515
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
16-
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
16+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
1717
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
1818
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
1919

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
linux_5_9_arguments_override: "--explicit-target-dependency-import-check error"
2121
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
22-
linux_6_0_arguments_override: "--explicit-target-dependency-import-check error"
22+
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
2323
linux_nightly_6_0_arguments_override: "--explicit-target-dependency-import-check error"
2424
linux_nightly_main_enabled: false
2525

Package.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@ import PackageDescription
1919
var swiftSettings: [SwiftSetting] = [
2020
// https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md
2121
// Require `any` for existential types.
22-
.enableUpcomingFeature("ExistentialAny")
22+
.enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"),
2323
]
2424

25-
// Strict concurrency is enabled in CI; use this environment variable to enable it locally.
26-
if ProcessInfo.processInfo.environment["SWIFT_OPENAPI_STRICT_CONCURRENCY"].flatMap(Bool.init) ?? false {
27-
swiftSettings.append(contentsOf: [
28-
.define("SWIFT_OPENAPI_STRICT_CONCURRENCY"), .enableExperimentalFeature("StrictConcurrency"),
29-
])
30-
}
31-
3225
let package = Package(
3326
name: "swift-openapi-generator",
3427
platforms: [

Sources/_OpenAPIGeneratorCore/Diagnostics.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,17 @@ public protocol DiagnosticCollector {
174174
/// It receives diagnostics and forwards them to an upstream `DiagnosticCollector`.
175175
///
176176
/// If a diagnostic with a severity of `.error` is emitted, this collector will throw the diagnostic as an error.
177-
public struct ErrorThrowingDiagnosticCollector: DiagnosticCollector {
178-
let upstream: any DiagnosticCollector
177+
public struct ErrorThrowingDiagnosticCollector: DiagnosticCollector, Sendable {
178+
179+
/// The `DiagnosticCollector` to which this collector will forward diagnostics.
180+
internal let upstream: any DiagnosticCollector & Sendable
179181

180182
/// Initializes a new `ErrorThrowingDiagnosticCollector` with an upstream `DiagnosticCollector`.
181183
///
182184
/// The upstream collector is where this collector will forward all received diagnostics.
183185
///
184186
/// - Parameter upstream: The `DiagnosticCollector` to which this collector will forward diagnostics.
185-
public init(upstream: any DiagnosticCollector) { self.upstream = upstream }
187+
public init(upstream: any DiagnosticCollector & Sendable) { self.upstream = upstream }
186188

187189
/// Emits a diagnostic to the collector.
188190
///

Sources/_OpenAPIGeneratorCore/PlatformChecks.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,3 @@
2121
"_OpenAPIGeneratorCore is only to be used by swift-openapi-generator itself—your target should not link this library or the command line tool directly."
2222
)
2323
#endif
24-
25-
#if SWIFT_OPENAPI_STRICT_CONCURRENCY
26-
#warning("Compiling with Strict Concurrency")
27-
#endif

Sources/_OpenAPIGeneratorCore/Translator/Multipart/MultipartAdditionalProperties.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
// SPDX-License-Identifier: Apache-2.0
1212
//
1313
//===----------------------------------------------------------------------===//
14-
import OpenAPIKit
14+
@preconcurrency import OpenAPIKit
1515

1616
/// The strategy for handling the additional properties key in a multipart schema.
17-
enum MultipartAdditionalPropertiesStrategy: Equatable {
17+
enum MultipartAdditionalPropertiesStrategy: Equatable, Sendable {
1818

1919
/// A strategy where additional properties are explicitly disallowed.
2020
case disallowed

Sources/_OpenAPIGeneratorCore/Translator/Multipart/MultipartContentInspector.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ extension FileTranslator {
305305
return nil
306306
}
307307
let finalContentTypeSource: MultipartPartInfo.ContentTypeSource
308-
if let encoding, let contentType = encoding.contentType {
308+
if let encoding, let contentType = encoding.contentTypes.first, encoding.contentTypes.count == 1 {
309309
finalContentTypeSource = try .explicit(contentType.asGeneratorContentType)
310310
} else {
311311
finalContentTypeSource = candidateSource

Sources/swift-openapi-generator/Extensions.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import Yams
1818

1919
#if $RetroactiveAttribute
2020
extension URL: @retroactive ExpressibleByArgument {}
21-
extension GeneratorMode: @retroactive ExpressibleByArgument {}
22-
extension FeatureFlag: @retroactive ExpressibleByArgument {}
2321
#else
2422
extension URL: ExpressibleByArgument {}
23+
#endif
2524
extension GeneratorMode: ExpressibleByArgument {}
2625
extension FeatureFlag: ExpressibleByArgument {}
27-
#endif
2826

2927
extension URL {
3028

Sources/swift-openapi-generator/FilterCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Yams
1818
import OpenAPIKit
1919

2020
struct _FilterCommand: AsyncParsableCommand {
21-
static var configuration = CommandConfiguration(
21+
static let configuration = CommandConfiguration(
2222
commandName: "filter",
2323
abstract: "Filter an OpenAPI document",
2424
discussion: """

Sources/swift-openapi-generator/GenerateCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Foundation
1616
import _OpenAPIGeneratorCore
1717

1818
struct _GenerateCommand: AsyncParsableCommand {
19-
static var configuration: CommandConfiguration = .init(
19+
static let configuration: CommandConfiguration = .init(
2020
commandName: "generate",
2121
abstract: "Generate Swift files from an OpenAPI document",
2222
discussion: """

0 commit comments

Comments
 (0)