Skip to content

Commit a7a0a9a

Browse files
authored
Strict concurrency for NIOHPACK (#502)
Motivation: To increase concurrency safety the NIOPHACK module should compile without warning under strict concurrency checking. Modifications: - Add explicit Sendable annotations Result: No concurrency warnings.
1 parent b46cdf0 commit a7a0a9a

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Package.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,31 @@
1515

1616
import PackageDescription
1717

18+
let strictConcurrencyDevelopment = false
19+
20+
let strictConcurrencySettings: [SwiftSetting] = {
21+
var initialSettings: [SwiftSetting] = []
22+
initialSettings.append(contentsOf: [
23+
.enableUpcomingFeature("StrictConcurrency"),
24+
.enableUpcomingFeature("InferSendableFromCaptures"),
25+
])
26+
27+
if strictConcurrencyDevelopment {
28+
// -warnings-as-errors here is a workaround so that IDE-based development can
29+
// get tripped up on -require-explicit-sendable.
30+
initialSettings.append(.unsafeFlags(["-require-explicit-sendable", "-warnings-as-errors"]))
31+
}
32+
33+
return initialSettings
34+
}()
35+
1836
let package = Package(
1937
name: "swift-nio-http2",
2038
products: [
2139
.library(name: "NIOHTTP2", targets: ["NIOHTTP2"])
2240
],
2341
dependencies: [
24-
.package(url: "https://github.com/apple/swift-nio.git", from: "2.60.0"),
42+
.package(url: "https://github.com/apple/swift-nio.git", from: "2.81.0"),
2543
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.0.2"),
2644
],
2745
targets: [
@@ -74,7 +92,8 @@ let package = Package(
7492
.product(name: "NIOHTTP1", package: "swift-nio"),
7593
.product(name: "NIOFoundationCompat", package: "swift-nio"),
7694
.product(name: "Atomics", package: "swift-atomics"),
77-
]
95+
],
96+
swiftSettings: strictConcurrencySettings
7897
),
7998
.testTarget(
8099
name: "NIOHPACKTests",
@@ -86,7 +105,8 @@ let package = Package(
86105
resources: [
87106
.copy("Fixtures/large_complex_huffman_b64.txt"),
88107
.copy("Fixtures/large_huffman_b64.txt"),
89-
]
108+
],
109+
swiftSettings: strictConcurrencySettings
90110
),
91111
]
92112
)

Sources/NIOHPACK/HPACKErrors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import NIOCore
1717
public protocol NIOHPACKError: Error, Equatable {}
1818

1919
/// Errors raised by NIOHPACK while encoding/decoding data.
20-
public enum NIOHPACKErrors {
20+
public enum NIOHPACKErrors: Sendable {
2121
/// An indexed header referenced an index that doesn't exist in our
2222
/// header tables.
2323
public struct InvalidHeaderIndex: NIOHPACKError {

0 commit comments

Comments
 (0)