Skip to content

Commit

Permalink
Make the Extension related types Sendable.
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasvl committed Aug 18, 2023
1 parent fdbc3aa commit 194d489
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
4 changes: 1 addition & 3 deletions Sources/SwiftProtobuf/ExtensionFieldValueSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions Sources/SwiftProtobuf/ExtensionFields.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions Sources/SwiftProtobuf/FieldTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -412,7 +410,8 @@ public struct ProtobufString: FieldType, MapKeyType, MapValueType {
///
/// Bytes
///
public struct ProtobufBytes: FieldType, MapValueType {
public struct ProtobufBytes: FieldType, MapValueType, @unchecked Sendable {
// Once swift(>=5.7) the '@unchecked Sendable' can be removed as it is inherrited
public typealias BaseType = Data
public static var proto3DefaultValue: Data {return Data()}
public static func decodeSingular<D: Decoder>(value: inout BaseType?, from decoder: inout D) throws {
Expand Down

0 comments on commit 194d489

Please sign in to comment.