From 262a7e266637e07ebde5417d931c9ef3d645b314 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Fri, 18 Aug 2023 10:18:20 -0400 Subject: [PATCH] Make the Extension related types Sendable. --- Sources/SwiftProtobuf/ExtensionFieldValueSet.swift | 4 +--- Sources/SwiftProtobuf/ExtensionFields.swift | 6 ++---- Sources/SwiftProtobuf/FieldTypes.swift | 6 ++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift b/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift index 28fdacc18..7d428416c 100644 --- a/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift +++ b/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift @@ -14,9 +14,7 @@ /// // ----------------------------------------------------------------------------- -// TODO: `ExtensionFieldValueSet` should be `Sendable` but we cannot do so yet without possibly breaking compatibility. - -public struct ExtensionFieldValueSet: Hashable { +public struct ExtensionFieldValueSet: Hashable, Sendable { fileprivate var values = [Int : AnyExtensionField]() public static func ==(lhs: ExtensionFieldValueSet, diff --git a/Sources/SwiftProtobuf/ExtensionFields.swift b/Sources/SwiftProtobuf/ExtensionFields.swift index 3fb8aa456..07bddf152 100644 --- a/Sources/SwiftProtobuf/ExtensionFields.swift +++ b/Sources/SwiftProtobuf/ExtensionFields.swift @@ -12,8 +12,6 @@ /// // ----------------------------------------------------------------------------- -// TODO: `AnyExtensionField` should require `Sendable` but we cannot do so yet without possibly breaking compatibility. - // // Type-erased Extension field implementation. // Note that it has no "self or associated type" references, so can @@ -24,7 +22,7 @@ // equality with some other extension field; but it's type-sealed // so you can't actually access the contained value itself. // -public protocol AnyExtensionField { +public protocol AnyExtensionField: Sendable { func hash(into hasher: inout Hasher) var protobufExtension: AnyMessageExtension { get } func isEqual(other: AnyExtensionField) -> Bool @@ -48,7 +46,7 @@ extension AnyExtensionField { /// /// The regular ExtensionField type exposes the value directly. /// -public protocol ExtensionField: AnyExtensionField, Hashable { +public protocol ExtensionField: AnyExtensionField, Hashable, Sendable { associatedtype ValueType var value: ValueType { get set } init(protobufExtension: AnyMessageExtension, value: ValueType) diff --git a/Sources/SwiftProtobuf/FieldTypes.swift b/Sources/SwiftProtobuf/FieldTypes.swift index 2a40d8d39..669af47aa 100644 --- a/Sources/SwiftProtobuf/FieldTypes.swift +++ b/Sources/SwiftProtobuf/FieldTypes.swift @@ -24,14 +24,12 @@ import Foundation -// TODO: `FieldType` and `FieldType.BaseType` should require `Sendable` but we cannot do so yet without possibly breaking compatibility. - // Note: The protobuf- and JSON-specific methods here are defined // in ProtobufTypeAdditions.swift and JSONTypeAdditions.swift -public protocol FieldType { +public protocol FieldType: Sendable { // The Swift type used to store data for this field. For example, // proto "sint32" fields use Swift "Int32" type. - associatedtype BaseType: Hashable + associatedtype BaseType: Hashable, Sendable // The default value for this field type before it has been set. // This is also used, for example, when JSON decodes a "null"