Skip to content

Commit 522c301

Browse files
Davidde94Lukasa
andauthored
Adopt Sendable (#23)
* Make RawStructuredFieldValues sendable * Make StructuredFieldValues Sendable * Rename _Sendable to SHSendable * Fix date checking * Fix warning * Soundness * Update date Co-authored-by: Cory Benfield <lukasa@apple.com> Co-authored-by: Cory Benfield <lukasa@apple.com>
1 parent a3c50a9 commit 522c301

File tree

10 files changed

+39
-14
lines changed

10 files changed

+39
-14
lines changed

Sources/RawStructuredFieldValues/ComponentTypes.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/// `ItemOrInnerList` represents the values in a structured header dictionary, or the
2323
/// entries in a structured header list.
24-
public enum ItemOrInnerList {
24+
public enum ItemOrInnerList: SHSendable {
2525
case item(Item)
2626
case innerList(InnerList)
2727
}
@@ -32,7 +32,7 @@ extension ItemOrInnerList: Hashable {}
3232

3333
/// `BareItem` is a representation of the base data types at the bottom of a structured
3434
/// header field. These types are not parameterised: they are raw data.
35-
public enum BareItem {
35+
public enum BareItem: SHSendable {
3636
/// A boolean item.
3737
case bool(Bool)
3838

@@ -87,7 +87,7 @@ extension BareItem: Hashable {}
8787

8888
/// `Item` represents a structured header field item: a combination of a `bareItem`
8989
/// and some parameters.
90-
public struct Item {
90+
public struct Item: SHSendable {
9191
/// The `BareItem` that this `Item` contains.
9292
public var bareItem: BareItem
9393

@@ -106,7 +106,7 @@ extension Item: Hashable {}
106106

107107
/// A `BareInnerList` represents the items contained within an `InnerList`, without
108108
/// the associated parameters.
109-
public struct BareInnerList: Hashable {
109+
public struct BareInnerList: Hashable, SHSendable {
110110
private var items: [Item]
111111

112112
public init() {
@@ -179,7 +179,7 @@ extension BareInnerList.Index: Comparable {
179179
// MARK: - InnerList
180180

181181
/// An `InnerList` is a list of items, with some associated parameters.
182-
public struct InnerList: Hashable {
182+
public struct InnerList: Hashable, SHSendable {
183183
/// The items contained within this inner list.
184184
public var bareInnerList: BareInnerList
185185

Sources/RawStructuredFieldValues/Errors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// MARK: - StructuredHeaderError
1616

1717
/// Errors that may be encountered when working with structured headers.
18-
public struct StructuredHeaderError: Error {
18+
public struct StructuredHeaderError: Error, SHSendable {
1919
private enum _BaseError: Hashable {
2020
case invalidTrailingBytes
2121
case invalidInnerList

Sources/RawStructuredFieldValues/FieldParser.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public struct StructuredFieldValueParser<BaseData: RandomAccessCollection> where
2525
}
2626
}
2727

28+
extension StructuredFieldValueParser: SHSendable where BaseData: SHSendable, BaseData.SubSequence: SHSendable {}
29+
2830
extension StructuredFieldValueParser {
2931
// Helper typealiases to avoid the explosion of generic parameters
3032
public typealias BareItem = RawStructuredFieldValues.BareItem

Sources/RawStructuredFieldValues/FieldSerializer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
private let validIntegerRange = Int64(-999_999_999_999_999) ... Int64(999_999_999_999_999)
1616

1717
/// A `StructuredFieldValueSerializer` is the basic parsing object for structured header field values.
18-
public struct StructuredFieldValueSerializer {
18+
public struct StructuredFieldValueSerializer: SHSendable {
1919
private var data: [UInt8]
2020

2121
public init() {

Sources/RawStructuredFieldValues/OrderedMap.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ extension OrderedMap {
6767
}
6868
}
6969

70+
extension OrderedMap: SHSendable where Key: SHSendable, Value: SHSendable {}
71+
72+
extension OrderedMap.Entry: SHSendable where Key: SHSendable, Value: SHSendable {}
73+
7074
// MARK: - Collection conformances
7175

7276
extension OrderedMap: RandomAccessCollection, MutableCollection {
73-
public struct Index {
77+
public struct Index: SHSendable {
7478
fileprivate var baseIndex: Array<(Key, Value)>.Index
7579

7680
fileprivate init(_ baseIndex: Array<(Key, Value)>.Index) {

Sources/RawStructuredFieldValues/PseudoDecimal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import Glibc
3434
/// is 999,999,999,999,999. The exponent ranges from -3 to 0. Additionally, there may be no more than 12 decimal digits before
3535
/// the decimal place, so while the maximum value of the significand is 999,999,999,999,999, that is only acceptable if the
3636
/// exponent is -3.
37-
public struct PseudoDecimal: Hashable {
37+
public struct PseudoDecimal: Hashable, SHSendable {
3838
private var _mantissa: Int64
3939

4040
private var _exponent: Int8
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the SwiftNIO open source project
4+
//
5+
// Copyright (c) 2022 Apple Inc. and the SwiftNIO project authors
6+
// Licensed under Apache License v2.0
7+
//
8+
// See LICENSE.txt for license information
9+
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors
10+
//
11+
// SPDX-License-Identifier: Apache-2.0
12+
//
13+
//===----------------------------------------------------------------------===//
14+
15+
#if swift(>=5.5) && canImport(_Concurrency)
16+
public typealias SHSendable = Sendable
17+
#else
18+
public typealias SHSendable = Any
19+
#endif

Sources/StructuredFieldValues/Decoder/StructuredFieldValueDecoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import RawStructuredFieldValues
1616

1717
/// A `StructuredFieldValueDecoder` allows decoding `Decodable` objects from a HTTP
1818
/// structured header field.
19-
public struct StructuredFieldValueDecoder {
19+
public struct StructuredFieldValueDecoder: SHSendable {
2020
/// A strategy that should be used to map coding keys to wire format keys.
2121
public var keyDecodingStrategy: KeyDecodingStrategy?
2222

@@ -25,7 +25,7 @@ public struct StructuredFieldValueDecoder {
2525

2626
extension StructuredFieldValueDecoder {
2727
/// A strategy that should be used to map coding keys to wire format keys.
28-
public struct KeyDecodingStrategy: Hashable {
28+
public struct KeyDecodingStrategy: Hashable, SHSendable {
2929
fileprivate enum Base: Hashable {
3030
case lowercase
3131
}

Sources/StructuredFieldValues/Encoder/StructuredFieldValueEncoder.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import RawStructuredFieldValues
1616

1717
/// A `StructuredFieldValueEncoder` allows encoding `Encodable` objects to the format of a HTTP
1818
/// structured header field.
19-
public struct StructuredFieldValueEncoder {
19+
public struct StructuredFieldValueEncoder: SHSendable {
2020
public var keyEncodingStrategy: KeyEncodingStrategy?
2121

2222
public init() {}
2323
}
2424

2525
extension StructuredFieldValueEncoder {
2626
/// A strategy that should be used to map coding keys to wire format keys.
27-
public struct KeyEncodingStrategy: Hashable {
27+
public struct KeyEncodingStrategy: Hashable, SHSendable {
2828
fileprivate enum Base: Hashable {
2929
case lowercase
3030
}

scripts/soundness.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -eu
1717
here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1818
function replace_acceptable_years() {
1919
# this needs to replace all acceptable forms with 'YEARS'
20-
sed -e 's/2020-2021/YEARS/' -e 's/202[01]/YEARS/'
20+
sed -e 's/202[01]-202[012]/YEARS/' -e 's/202[012]/YEARS/'
2121
}
2222

2323

0 commit comments

Comments
 (0)