Skip to content

Commit add9e15

Browse files
authored
more Sendable conformances & Sendable Context (#381)
1 parent f0e80d1 commit add9e15

18 files changed

+244
-29
lines changed

Sources/TSCBasic/CodableResult.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public struct CodableResult<Success, Failure>: Codable where Success: Codable, F
4949
}
5050
}
5151

52+
extension CodableResult: Sendable where Success: Sendable, Failure: Sendable {}
53+
5254
extension CodableResult where Failure == StringError {
5355
public init(body: () throws -> Success) {
5456
do {

Sources/TSCBasic/Condition.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,7 @@ public struct Condition {
5050
return try body()
5151
}
5252
}
53+
54+
#if compiler(>=5.7)
55+
extension Condition: Sendable {}
56+
#endif

Sources/TSCBasic/DeltaAlgorithm.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/// It is not an error to provide a predicate that does not satisfy these
2828
/// requirements, and the algorithm will generally produce reasonable results.
2929
/// However, it may run substantially more tests than with a good predicate.
30-
public struct DeltaAlgorithm<Change: Hashable> {
30+
public struct DeltaAlgorithm<Change: Hashable>: Sendable {
3131

3232
public init() {}
3333

Sources/TSCBasic/DiagnosticsEngine.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ extension DiagnosticData {
2121
public protocol DiagnosticLocation: Sendable, CustomStringConvertible {
2222
}
2323

24-
public struct Diagnostic: CustomStringConvertible {
24+
public struct Diagnostic: CustomStringConvertible, Sendable {
2525
/// The behavior associated with this diagnostic.
26-
public enum Behavior {
26+
public enum Behavior: Sendable {
2727
/// An error which will halt the operation.
2828
case error
2929

@@ -38,7 +38,7 @@ public struct Diagnostic: CustomStringConvertible {
3838
case ignored
3939
}
4040

41-
public struct Message {
41+
public struct Message: Sendable {
4242
/// The diagnostic's behavior.
4343
public let behavior: Behavior
4444

@@ -191,7 +191,7 @@ extension Diagnostic.Message {
191191
}
192192
}
193193

194-
public struct StringDiagnostic: DiagnosticData {
194+
public struct StringDiagnostic: DiagnosticData, Sendable {
195195
/// The diagnostic description.
196196
public let description: String
197197

Sources/TSCBasic/FileSystem.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import Foundation
1313
import Dispatch
1414
import SystemPackage
1515

16-
public struct FileSystemError: Error, Equatable {
17-
public enum Kind: Equatable {
16+
public struct FileSystemError: Error, Equatable, Sendable {
17+
public enum Kind: Equatable, Sendable {
1818
/// Access to the path is denied.
1919
///
2020
/// This is used when an operation cannot be completed because a component of

Sources/TSCBasic/HashAlgorithms.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import CryptoKit
1313
#endif
1414

15-
public protocol HashAlgorithm {
15+
public protocol HashAlgorithm: Sendable {
1616

1717
/// Hashes the input bytes, returning the digest.
1818
///
@@ -31,7 +31,7 @@ extension HashAlgorithm {
3131
/// SHA-256 implementation from Secure Hash Algorithm 2 (SHA-2) set of
3232
/// cryptographic hash functions (FIPS PUB 180-2).
3333
/// Uses CryptoKit where available
34-
public struct SHA256: HashAlgorithm {
34+
public struct SHA256: HashAlgorithm, Sendable {
3535
private let underlying: HashAlgorithm
3636

3737
public init() {
@@ -197,7 +197,7 @@ struct InternalSHA256: HashAlgorithm {
197197
#if canImport(CryptoKit)
198198
@available(*, deprecated, message: "use SHA256 which abstract over platform differences")
199199
@available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
200-
public struct CryptoKitSHA256: HashAlgorithm {
200+
public struct CryptoKitSHA256: HashAlgorithm, Sendable {
201201
let underlying = _CryptoKitSHA256()
202202
public init() {}
203203
public func hash(_ bytes: ByteString) -> ByteString {

Sources/TSCBasic/KeyedPair.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ public struct KeyedPair<T, K: Hashable>: Hashable {
5050
return lhs.key == rhs.key
5151
}
5252
}
53+
54+
extension KeyedPair: Sendable where T: Sendable, K: Sendable {}

Sources/TSCBasic/LazyCache.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import class Foundation.NSLock
3030
/// ```
3131
///
3232
/// See: https://bugs.swift.org/browse/SR-1042
33+
@available(*, deprecated, message: "This implementation does not work -- https://github.com/apple/swift-tools-support-core/issues/385")
3334
public struct LazyCache<Class, T> {
3435
// FIXME: It would be nice to avoid a per-instance lock, but this type isn't
3536
// intended for creating large numbers of instances of. We also really want
@@ -57,3 +58,8 @@ public struct LazyCache<Class, T> {
5758
}
5859
}
5960
}
61+
62+
#if swift(>=5.6)
63+
@available(*, unavailable) // until https://github.com/apple/swift-tools-support-core/issues/385 is fixed
64+
extension LazyCache: Sendable {}
65+
#endif

Sources/TSCBasic/OrderedDictionary.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,5 @@ extension OrderedDictionary: RandomAccessCollection {
123123
return (key, value)
124124
}
125125
}
126+
127+
extension OrderedDictionary: Sendable where Key: Sendable, Value: Sendable {}

Sources/TSCBasic/OrderedSet.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,5 @@ public func == <T>(lhs: OrderedSet<T>, rhs: OrderedSet<T>) -> Bool {
128128
}
129129

130130
extension OrderedSet: Hashable where Element: Hashable { }
131+
132+
extension OrderedSet: Sendable where Element: Sendable { }

0 commit comments

Comments
 (0)