Skip to content

Commit

Permalink
Adopt strict concurrency in _NIOBase64 (#2838)
Browse files Browse the repository at this point in the history
Motivation:

Another brick in the wall.

Modifications:

- Make Base64 an enum, not a struct, as it's a namespace.
- Make Base64 Sendable, which it trivially is.

Result:

Another pass, another success
  • Loading branch information
Lukasa authored Aug 12, 2024
1 parent ce524be commit 1f3dc9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
32 changes: 22 additions & 10 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@

import PackageDescription

// Used only for environment variables, does not make its way
// into the product code.
import class Foundation.ProcessInfo

let swiftAtomics: PackageDescription.Target.Dependency = .product(name: "Atomics", package: "swift-atomics")
let swiftCollections: PackageDescription.Target.Dependency = .product(name: "DequeModule", package: "swift-collections")
let swiftSystem: PackageDescription.Target.Dependency = .product(
Expand All @@ -23,16 +27,23 @@ let swiftSystem: PackageDescription.Target.Dependency = .product(
condition: .when(platforms: [.macOS, .iOS, .tvOS, .watchOS, .linux, .android])
)

let strictConcurrencySettings: [SwiftSetting] = [
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("InferSendableFromCaptures"),
]
let strictConcurrencyDevelopment = false

let strictConcurrencySettings: [SwiftSetting] = {
var initialSettings: [SwiftSetting] = []
initialSettings.append(contentsOf: [
.enableUpcomingFeature("StrictConcurrency"),
.enableUpcomingFeature("InferSendableFromCaptures"),
])

// Add these Swift settings to targets that need to be validated
// for strict concurrency.
let diagnosticSettings: [SwiftSetting] = [
.unsafeFlags(["-require-explicit-sendable", "-warnings-as-errors"])
]
if strictConcurrencyDevelopment {
// -warnings-as-errors here is a workaround so that IDE-based development can
// get tripped up on -require-explicit-sendable.
initialSettings.append(.unsafeFlags(["-require-explicit-sendable", "-warnings-as-errors"]))
}

return initialSettings
}()

// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and
// Foundation will be linked. This is, however, strictly better than unconditionally adding the
Expand Down Expand Up @@ -81,7 +92,8 @@ let package = Package(
swiftSettings: strictConcurrencySettings
),
.target(
name: "_NIOBase64"
name: "_NIOBase64",
swiftSettings: strictConcurrencySettings
),
.target(
name: "NIOEmbedded",
Expand Down
2 changes: 1 addition & 1 deletion Sources/_NIOBase64/Base64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public enum Base64Error: Error {
}

@usableFromInline
internal struct Base64 {
internal enum Base64: Sendable {

@inlinable
static func encode<Buffer: Collection>(bytes: Buffer) -> String where Buffer.Element == UInt8 {
Expand Down

0 comments on commit 1f3dc9c

Please sign in to comment.