diff --git a/Package.swift b/Package.swift index 49c8b2099..eb9bd297d 100644 --- a/Package.swift +++ b/Package.swift @@ -39,30 +39,41 @@ let package = Package( name: "SwiftProtobuf", exclude: ["CMakeLists.txt"], swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"), ] ), .target( name: "SwiftProtobufPluginLibrary", dependencies: ["SwiftProtobuf"], - exclude: ["CMakeLists.txt"] + exclude: ["CMakeLists.txt"], + swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), + ] ), .target( name: "SwiftProtobufTestHelpers", dependencies: ["SwiftProtobuf"], swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"), ] ), .executableTarget( name: "protoc-gen-swift", dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobuf"], - exclude: ["CMakeLists.txt"] + exclude: ["CMakeLists.txt"], + swiftSettings: [ + .enableUpcomingFeature("ExistentialAny") + ] ), .executableTarget( name: "Conformance", dependencies: ["SwiftProtobuf"], - exclude: ["failure_list_swift.txt", "text_format_failure_list_swift.txt"] + exclude: ["failure_list_swift.txt", "text_format_failure_list_swift.txt"], + swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), + ] ), .plugin( name: "SwiftProtobufPlugin", @@ -75,16 +86,25 @@ let package = Package( name: "SwiftProtobufTests", dependencies: ["SwiftProtobuf"], swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), .enableExperimentalFeature("StrictConcurrency=complete"), ] ), .testTarget( name: "SwiftProtobufPluginLibraryTests", - dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobufTestHelpers"] + dependencies: ["SwiftProtobufPluginLibrary", "SwiftProtobufTestHelpers"], + swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), + .enableExperimentalFeature("StrictConcurrency=complete"), + ] ), .testTarget( name: "protoc-gen-swiftTests", - dependencies: ["protoc-gen-swift", "SwiftProtobufTestHelpers"] + dependencies: ["protoc-gen-swift", "SwiftProtobufTestHelpers"], + swiftSettings: [ + .enableUpcomingFeature("ExistentialAny"), + .enableExperimentalFeature("StrictConcurrency=complete"), + ] ), ], swiftLanguageVersions: [.v5] diff --git a/Sources/Conformance/main.swift b/Sources/Conformance/main.swift index 9b157c175..45c118a62 100644 --- a/Sources/Conformance/main.swift +++ b/Sources/Conformance/main.swift @@ -84,8 +84,8 @@ func buildResponse(serializedBytes: [UInt8]) -> Conformance_ConformanceResponse return response } - let msgType: SwiftProtobuf.Message.Type - let extensions: SwiftProtobuf.ExtensionMap + let msgType: any SwiftProtobuf.Message.Type + let extensions: any SwiftProtobuf.ExtensionMap switch request.messageType { case "": // Note: This case is here to cover using a old version of the conformance test @@ -102,7 +102,7 @@ func buildResponse(serializedBytes: [UInt8]) -> Conformance_ConformanceResponse return response } - let testMessage: SwiftProtobuf.Message + let testMessage: any SwiftProtobuf.Message switch request.payload { case .protobufPayload(let data)?: do { diff --git a/Sources/SwiftProtobuf/AnyMessageStorage.swift b/Sources/SwiftProtobuf/AnyMessageStorage.swift index 0bcc30e49..a0d0586a0 100644 --- a/Sources/SwiftProtobuf/AnyMessageStorage.swift +++ b/Sources/SwiftProtobuf/AnyMessageStorage.swift @@ -16,14 +16,14 @@ import Foundation fileprivate func serializeAnyJSON( - for message: Message, + for message: any Message, typeURL: String, options: JSONEncodingOptions ) throws -> String { var visitor = try JSONEncodingVisitor(type: type(of: message), options: options) visitor.startObject(message: message) visitor.encodeField(name: "@type", stringValue: typeURL) - if let m = message as? _CustomJSONCodable { + if let m = message as? (any _CustomJSONCodable) { let value = try m.encodedJSONString(options: options) visitor.encodeField(name: "value", jsonText: value) } else { @@ -33,7 +33,7 @@ fileprivate func serializeAnyJSON( return visitor.stringResult } -fileprivate func emitVerboseTextForm(visitor: inout TextFormatEncodingVisitor, message: Message, typeURL: String) { +fileprivate func emitVerboseTextForm(visitor: inout TextFormatEncodingVisitor, message: any Message, typeURL: String) { let url: String if typeURL.isEmpty { url = buildTypeURL(forMessage: message, typePrefix: defaultAnyTypeURLPrefix) @@ -53,10 +53,10 @@ fileprivate func asJSONObject(body: [UInt8]) -> Data { } fileprivate func unpack(contentJSON: [UInt8], - extensions: ExtensionMap, + extensions: any ExtensionMap, options: JSONDecodingOptions, - as messageType: Message.Type) throws -> Message { - guard messageType is _CustomJSONCodable.Type else { + as messageType: any Message.Type) throws -> any Message { + guard messageType is any _CustomJSONCodable.Type else { let contentJSONAsObject = asJSONObject(body: contentJSON) return try messageType.init(jsonUTF8Bytes: contentJSONAsObject, extensions: extensions, options: options) } @@ -135,7 +135,7 @@ internal class AnyMessageStorage { // unpacking that takes new options when a developer decides to decode it. case binary(Data) // a message - case message(Message) + case message(any Message) // parsed JSON with the @type removed and the decoding options. case contentJSON([UInt8], JSONDecodingOptions) } @@ -162,7 +162,7 @@ internal class AnyMessageStorage { // replaced during the unpacking and never as a merge. func unpackTo( target: inout M, - extensions: ExtensionMap?, + extensions: (any ExtensionMap)?, options: BinaryDecodingOptions ) throws { guard isA(M.self) else { diff --git a/Sources/SwiftProtobuf/AsyncMessageSequence.swift b/Sources/SwiftProtobuf/AsyncMessageSequence.swift index 3c88aae75..cd7a743c1 100644 --- a/Sources/SwiftProtobuf/AsyncMessageSequence.swift +++ b/Sources/SwiftProtobuf/AsyncMessageSequence.swift @@ -34,7 +34,7 @@ extension AsyncSequence where Element == UInt8 { @inlinable public func binaryProtobufDelimitedMessages( of messageType: M.Type = M.self, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) -> AsyncMessageSequence { @@ -58,7 +58,7 @@ public struct AsyncMessageSequence< public typealias Element = M private let base: Base - private let extensions: ExtensionMap? + private let extensions: (any ExtensionMap)? private let partial: Bool private let options: BinaryDecodingOptions @@ -80,7 +80,7 @@ public struct AsyncMessageSequence< /// messages. public init( base: Base, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) { @@ -95,7 +95,7 @@ public struct AsyncMessageSequence< @usableFromInline var iterator: Base.AsyncIterator? @usableFromInline - let extensions: ExtensionMap? + let extensions: (any ExtensionMap)? @usableFromInline let partial: Bool @usableFromInline @@ -103,7 +103,7 @@ public struct AsyncMessageSequence< init( iterator: Base.AsyncIterator, - extensions: ExtensionMap?, + extensions: (any ExtensionMap)?, partial: Bool, options: BinaryDecodingOptions ) { diff --git a/Sources/SwiftProtobuf/BinaryDecoder.swift b/Sources/SwiftProtobuf/BinaryDecoder.swift index 5377c00d1..849ad70de 100644 --- a/Sources/SwiftProtobuf/BinaryDecoder.swift +++ b/Sources/SwiftProtobuf/BinaryDecoder.swift @@ -33,7 +33,7 @@ internal struct BinaryDecoder: Decoder { // Field number for last-parsed field tag private var fieldNumber: Int = 0 // Collection of extension fields for this decode - private var extensions: ExtensionMap? + private var extensions: (any ExtensionMap)? // The current group number. See decodeFullGroup(group:fieldNumber:) for how // this is used. private var groupFieldNumber: Int? @@ -54,7 +54,7 @@ internal struct BinaryDecoder: Decoder { forReadingFrom pointer: UnsafeRawPointer, count: Int, options: BinaryDecodingOptions, - extensions: ExtensionMap? = nil + extensions: (any ExtensionMap)? = nil ) { // Assuming baseAddress is not nil. p = pointer @@ -1088,7 +1088,7 @@ internal struct BinaryDecoder: Decoder { internal mutating func decodeExtensionField( values: inout ExtensionFieldValueSet, - messageType: Message.Type, + messageType: any Message.Type, fieldNumber: Int ) throws { if let ext = extensions?[messageType, fieldNumber] { @@ -1102,9 +1102,9 @@ internal struct BinaryDecoder: Decoder { /// Helper to reuse between Extension decoding and MessageSet Extension decoding. private mutating func decodeExtensionField( values: inout ExtensionFieldValueSet, - messageType: Message.Type, + messageType: any Message.Type, fieldNumber: Int, - messageExtension ext: AnyMessageExtension + messageExtension ext: any AnyMessageExtension ) throws { assert(!consumed) assert(fieldNumber == ext.fieldNumber) @@ -1129,7 +1129,7 @@ internal struct BinaryDecoder: Decoder { internal mutating func decodeExtensionFieldsAsMessageSet( values: inout ExtensionFieldValueSet, - messageType: Message.Type + messageType: any Message.Type ) throws { // Spin looking for the Item group, everything else will end up in unknown fields. while let fieldNumber = try self.nextFieldNumber() { @@ -1173,14 +1173,14 @@ internal struct BinaryDecoder: Decoder { private mutating func decodeMessageSetItem( values: inout ExtensionFieldValueSet, - messageType: Message.Type + messageType: any Message.Type ) throws -> DecodeMessageSetItemResult { // This is loosely based on the C++: // ExtensionSet::ParseMessageSetItem() // WireFormat::ParseAndMergeMessageSetItem() // (yes, there have two versions that are almost the same) - var msgExtension: AnyMessageExtension? + var msgExtension: (any AnyMessageExtension)? var fieldData: Data? // In this loop, if wire types are wrong, things don't decode, diff --git a/Sources/SwiftProtobuf/BinaryDelimited.swift b/Sources/SwiftProtobuf/BinaryDelimited.swift index c8c83ab21..3edbae447 100644 --- a/Sources/SwiftProtobuf/BinaryDelimited.swift +++ b/Sources/SwiftProtobuf/BinaryDelimited.swift @@ -65,7 +65,7 @@ public enum BinaryDelimited { /// `BinaryDelimited.Error` for some writing errors, or the /// underlying `OutputStream.streamError` for a stream error. public static func serialize( - message: Message, + message: any Message, to stream: OutputStream, partial: Bool = false ) throws { @@ -125,7 +125,7 @@ public enum BinaryDelimited { public static func parse( messageType: M.Type, from stream: InputStream, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws -> M { @@ -166,7 +166,7 @@ public enum BinaryDelimited { public static func merge( into message: inout M, from stream: InputStream, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { diff --git a/Sources/SwiftProtobuf/Decoder.swift b/Sources/SwiftProtobuf/Decoder.swift index 9291dd4a9..9fee303e0 100644 --- a/Sources/SwiftProtobuf/Decoder.swift +++ b/Sources/SwiftProtobuf/Decoder.swift @@ -204,11 +204,11 @@ public protocol Decoder { // Decode extension fields /// Decode an extension field - mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws + mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: any Message.Type, fieldNumber: Int) throws // Run a decode loop decoding the MessageSet format for Extensions. mutating func decodeExtensionFieldsAsMessageSet(values: inout ExtensionFieldValueSet, - messageType: Message.Type) throws + messageType: any Message.Type) throws } /// Most Decoders won't care about Extension handing as in MessageSet @@ -217,7 +217,7 @@ public protocol Decoder { extension Decoder { public mutating func decodeExtensionFieldsAsMessageSet( values: inout ExtensionFieldValueSet, - messageType: Message.Type + messageType: any Message.Type ) throws { while let fieldNumber = try self.nextFieldNumber() { try self.decodeExtensionField(values: &values, diff --git a/Sources/SwiftProtobuf/Enum.swift b/Sources/SwiftProtobuf/Enum.swift index e5ed92bd1..fea4a7261 100644 --- a/Sources/SwiftProtobuf/Enum.swift +++ b/Sources/SwiftProtobuf/Enum.swift @@ -49,7 +49,7 @@ extension Enum { /// Since the text format and JSON names are always identical, we don't need /// to distinguish them. internal var name: _NameMap.Name? { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type else { + guard let nameProviding = Self.self as? any _ProtoNameProviding.Type else { return nil } return nameProviding._protobuf_nameMap.names(for: rawValue)?.proto @@ -63,7 +63,7 @@ extension Enum { /// /// - Parameter name: The name of the enum case. internal init?(name: String) { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type, + guard let nameProviding = Self.self as? any _ProtoNameProviding.Type, let number = nameProviding._protobuf_nameMap.number(forJSONName: name) else { return nil } @@ -78,7 +78,7 @@ extension Enum { /// /// - Parameter name: Buffer holding the UTF-8 bytes of the desired name. internal init?(rawUTF8: UnsafeRawBufferPointer) { - guard let nameProviding = Self.self as? _ProtoNameProviding.Type, + guard let nameProviding = Self.self as? any _ProtoNameProviding.Type, let number = nameProviding._protobuf_nameMap.number(forJSONName: rawUTF8) else { return nil } diff --git a/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift b/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift index 7d428416c..f429da4b4 100644 --- a/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift +++ b/Sources/SwiftProtobuf/ExtensionFieldValueSet.swift @@ -15,7 +15,7 @@ // ----------------------------------------------------------------------------- public struct ExtensionFieldValueSet: Hashable, Sendable { - fileprivate var values = [Int : AnyExtensionField]() + fileprivate var values = [Int : any AnyExtensionField]() public static func ==(lhs: ExtensionFieldValueSet, rhs: ExtensionFieldValueSet) -> Bool { @@ -62,12 +62,12 @@ public struct ExtensionFieldValueSet: Hashable, Sendable { } } - public subscript(index: Int) -> AnyExtensionField? { + public subscript(index: Int) -> (any AnyExtensionField)? { get { return values[index] } set { values[index] = newValue } } - mutating func modify(index: Int, _ modifier: (inout AnyExtensionField?) throws -> ReturnType) rethrows -> ReturnType { + mutating func modify(index: Int, _ modifier: (inout (any AnyExtensionField)?) throws -> ReturnType) rethrows -> ReturnType { // This internal helper exists to invoke the _modify accessor on Dictionary for the given operation, which can avoid CoWs // during the modification operation. return try modifier(&values[index]) diff --git a/Sources/SwiftProtobuf/ExtensionFields.swift b/Sources/SwiftProtobuf/ExtensionFields.swift index 07bddf152..f5c12c03a 100644 --- a/Sources/SwiftProtobuf/ExtensionFields.swift +++ b/Sources/SwiftProtobuf/ExtensionFields.swift @@ -24,8 +24,8 @@ // public protocol AnyExtensionField: Sendable { func hash(into hasher: inout Hasher) - var protobufExtension: AnyMessageExtension { get } - func isEqual(other: AnyExtensionField) -> Bool + var protobufExtension: any AnyMessageExtension { get } + func isEqual(other: any AnyExtensionField) -> Bool /// Merging field decoding mutating func decodeExtensionField(decoder: inout T) throws @@ -49,8 +49,8 @@ extension AnyExtensionField { public protocol ExtensionField: AnyExtensionField, Hashable, Sendable { associatedtype ValueType var value: ValueType { get set } - init(protobufExtension: AnyMessageExtension, value: ValueType) - init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws + init(protobufExtension: any AnyMessageExtension, value: ValueType) + init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws } /// @@ -60,14 +60,14 @@ public struct OptionalExtensionField: ExtensionField { public typealias BaseType = T.BaseType public typealias ValueType = BaseType public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: OptionalExtensionField, rhs: OptionalExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -76,7 +76,7 @@ public struct OptionalExtensionField: ExtensionField { hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! OptionalExtensionField return self == o } @@ -89,7 +89,7 @@ public struct OptionalExtensionField: ExtensionField { } } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType? try T.decodeSingular(value: &v, from: &decoder) if let v = v { @@ -121,14 +121,14 @@ public struct RepeatedExtensionField: ExtensionField { public typealias BaseType = T.BaseType public typealias ValueType = [BaseType] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: RepeatedExtensionField, rhs: RepeatedExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -137,7 +137,7 @@ public struct RepeatedExtensionField: ExtensionField { hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! RepeatedExtensionField return self == o } @@ -146,7 +146,7 @@ public struct RepeatedExtensionField: ExtensionField { try T.decodeRepeated(value: &value, from: &decoder) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try T.decodeRepeated(value: &v, from: &decoder) self.init(protobufExtension: protobufExtension, value: v) @@ -177,14 +177,14 @@ public struct PackedExtensionField: ExtensionField { public typealias BaseType = T.BaseType public typealias ValueType = [BaseType] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: PackedExtensionField, rhs: PackedExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -193,7 +193,7 @@ public struct PackedExtensionField: ExtensionField { hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! PackedExtensionField return self == o } @@ -202,7 +202,7 @@ public struct PackedExtensionField: ExtensionField { try T.decodeRepeated(value: &value, from: &decoder) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try T.decodeRepeated(value: &v, from: &decoder) self.init(protobufExtension: protobufExtension, value: v) @@ -230,14 +230,14 @@ public struct OptionalEnumExtensionField: ExtensionField where E.RawVal public typealias BaseType = E public typealias ValueType = E public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: OptionalEnumExtensionField, rhs: OptionalEnumExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -246,7 +246,7 @@ public struct OptionalEnumExtensionField: ExtensionField where E.RawVal hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! OptionalEnumExtensionField return self == o } @@ -259,7 +259,7 @@ public struct OptionalEnumExtensionField: ExtensionField where E.RawVal } } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType? try decoder.decodeSingularEnumField(value: &v) if let v = v { @@ -293,14 +293,14 @@ public struct RepeatedEnumExtensionField: ExtensionField where E.RawVal public typealias BaseType = E public typealias ValueType = [E] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: RepeatedEnumExtensionField, rhs: RepeatedEnumExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -309,7 +309,7 @@ public struct RepeatedEnumExtensionField: ExtensionField where E.RawVal hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! RepeatedEnumExtensionField return self == o } @@ -318,7 +318,7 @@ public struct RepeatedEnumExtensionField: ExtensionField where E.RawVal try decoder.decodeRepeatedEnumField(value: &value) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try decoder.decodeRepeatedEnumField(value: &v) self.init(protobufExtension: protobufExtension, value: v) @@ -351,14 +351,14 @@ public struct PackedEnumExtensionField: ExtensionField where E.RawValue public typealias BaseType = E public typealias ValueType = [E] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: PackedEnumExtensionField, rhs: PackedEnumExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -367,7 +367,7 @@ public struct PackedEnumExtensionField: ExtensionField where E.RawValue hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! PackedEnumExtensionField return self == o } @@ -376,7 +376,7 @@ public struct PackedEnumExtensionField: ExtensionField where E.RawValue try decoder.decodeRepeatedEnumField(value: &value) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try decoder.decodeRepeatedEnumField(value: &v) self.init(protobufExtension: protobufExtension, value: v) @@ -407,14 +407,14 @@ public struct OptionalMessageExtensionField: public typealias BaseType = M public typealias ValueType = BaseType public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: OptionalMessageExtensionField, rhs: OptionalMessageExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -423,7 +423,7 @@ public struct OptionalMessageExtensionField: value.hash(into: &hasher) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! OptionalMessageExtensionField return self == o } @@ -436,7 +436,7 @@ public struct OptionalMessageExtensionField: } } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType? try decoder.decodeSingularMessageField(value: &v) if let v = v { @@ -471,14 +471,14 @@ public struct RepeatedMessageExtensionField: public typealias BaseType = M public typealias ValueType = [BaseType] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: RepeatedMessageExtensionField, rhs: RepeatedMessageExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -489,7 +489,7 @@ public struct RepeatedMessageExtensionField: } } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! RepeatedMessageExtensionField return self == o } @@ -498,7 +498,7 @@ public struct RepeatedMessageExtensionField: try decoder.decodeRepeatedMessageField(value: &value) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try decoder.decodeRepeatedMessageField(value: &v) self.init(protobufExtension: protobufExtension, value: v) @@ -535,14 +535,14 @@ public struct OptionalGroupExtensionField: public typealias BaseType = G public typealias ValueType = BaseType public var value: G - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: OptionalGroupExtensionField, rhs: OptionalGroupExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -551,7 +551,7 @@ public struct OptionalGroupExtensionField: hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! OptionalGroupExtensionField return self == o } @@ -564,7 +564,7 @@ public struct OptionalGroupExtensionField: } } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType? try decoder.decodeSingularGroupField(value: &v) if let v = v { @@ -599,14 +599,14 @@ public struct RepeatedGroupExtensionField: public typealias BaseType = G public typealias ValueType = [BaseType] public var value: ValueType - public var protobufExtension: AnyMessageExtension + public var protobufExtension: any AnyMessageExtension public static func ==(lhs: RepeatedGroupExtensionField, rhs: RepeatedGroupExtensionField) -> Bool { return lhs.value == rhs.value } - public init(protobufExtension: AnyMessageExtension, value: ValueType) { + public init(protobufExtension: any AnyMessageExtension, value: ValueType) { self.protobufExtension = protobufExtension self.value = value } @@ -615,7 +615,7 @@ public struct RepeatedGroupExtensionField: hasher.combine(value) } - public func isEqual(other: AnyExtensionField) -> Bool { + public func isEqual(other: any AnyExtensionField) -> Bool { let o = other as! RepeatedGroupExtensionField return self == o } @@ -624,7 +624,7 @@ public struct RepeatedGroupExtensionField: try decoder.decodeRepeatedGroupField(value: &value) } - public init?(protobufExtension: AnyMessageExtension, decoder: inout D) throws { + public init?(protobufExtension: any AnyMessageExtension, decoder: inout D) throws { var v: ValueType = [] try decoder.decodeRepeatedGroupField(value: &v) self.init(protobufExtension: protobufExtension, value: v) diff --git a/Sources/SwiftProtobuf/ExtensionMap.swift b/Sources/SwiftProtobuf/ExtensionMap.swift index bb98a5a02..ead2c1e67 100644 --- a/Sources/SwiftProtobuf/ExtensionMap.swift +++ b/Sources/SwiftProtobuf/ExtensionMap.swift @@ -24,7 +24,7 @@ /// standard `SimpleExtensionMap` implementation. public protocol ExtensionMap: Sendable { /// Returns the extension object describing an extension or nil - subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { get } + subscript(messageType: any Message.Type, fieldNumber: Int) -> (any AnyMessageExtension)? { get } /// Returns the field number for a message with a specific field name /// @@ -34,5 +34,5 @@ public protocol ExtensionMap: Sendable { /// for the proto file and `message` is the name of the message in /// which the extension was defined. (This is different from the /// message that is being extended!) - func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? + func fieldNumberForProto(messageType: any Message.Type, protoFieldName: String) -> Int? } diff --git a/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift b/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift index 2557140dd..7459934b8 100644 --- a/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift +++ b/Sources/SwiftProtobuf/Google_Protobuf_Any+Extensions.swift @@ -38,7 +38,7 @@ extension Google_Protobuf_Any { /// - Throws: `BinaryEncodingError.missingRequiredFields` if `partial` is /// false and `message` wasn't fully initialized. public init( - message: Message, + message: any Message, partial: Bool = false, typePrefix: String = defaultAnyTypeURLPrefix ) throws { @@ -63,7 +63,7 @@ extension Google_Protobuf_Any { public init( textFormatString: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), - extensions: ExtensionMap? = nil + extensions: (any ExtensionMap)? = nil ) throws { self.init() if !textFormatString.isEmpty { diff --git a/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift b/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift index 83e38d5f7..32eb1e84e 100644 --- a/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift +++ b/Sources/SwiftProtobuf/Google_Protobuf_Any+Registry.swift @@ -26,7 +26,7 @@ fileprivate let knownTypesQueue = // TODO: Should these first four be exposed as methods to go with // the general registry support? -internal func buildTypeURL(forMessage message: Message, typePrefix: String) -> String { +internal func buildTypeURL(forMessage message: any Message, typePrefix: String) -> String { var url = typePrefix let needsSlash = typePrefix.isEmpty || typePrefix.last != "/" if needsSlash { @@ -35,7 +35,7 @@ internal func buildTypeURL(forMessage message: Message, typePrefix: String) -> S return url + typeName(fromMessage: message) } -internal func typeName(fromMessage message: Message) -> String { +internal func typeName(fromMessage message: any Message) -> String { let messageType = type(of: message) return messageType.protoMessageName } @@ -67,7 +67,7 @@ fileprivate final class UnsafeMutableTransferBox { extension UnsafeMutableTransferBox: @unchecked Sendable {} // All access to this should be done on `knownTypesQueue`. -fileprivate let knownTypes: UnsafeMutableTransferBox<[String:Message.Type]> = .init([ +fileprivate let knownTypes: UnsafeMutableTransferBox<[String:any Message.Type]> = .init([ // Seeded with the Well Known Types. "google.protobuf.Any": Google_Protobuf_Any.self, "google.protobuf.BoolValue": Google_Protobuf_BoolValue.self, @@ -117,7 +117,7 @@ extension Google_Protobuf_Any { /// /// Returns: true if the type was registered, false if something /// else was already registered for the messageName. - @discardableResult public static func register(messageType: Message.Type) -> Bool { + @discardableResult public static func register(messageType: any Message.Type) -> Bool { let messageTypeName = messageType.protoMessageName var result: Bool = false execute(flags: .barrier) { @@ -136,14 +136,14 @@ extension Google_Protobuf_Any { } /// Returns the Message.Type expected for the given type URL. - public static func messageType(forTypeURL url: String) -> Message.Type? { + public static func messageType(forTypeURL url: String) -> (any Message.Type)? { let messageTypeName = typeName(fromURL: url) return messageType(forMessageName: messageTypeName) } /// Returns the Message.Type expected for the given proto message name. - public static func messageType(forMessageName name: String) -> Message.Type? { - var result: Message.Type? + public static func messageType(forMessageName name: String) -> (any Message.Type)? { + var result: (any Message.Type)? execute(flags: .none) { result = knownTypes.wrappedValue[name] } diff --git a/Sources/SwiftProtobuf/Internal.swift b/Sources/SwiftProtobuf/Internal.swift index 156dc062c..ec1c41c69 100644 --- a/Sources/SwiftProtobuf/Internal.swift +++ b/Sources/SwiftProtobuf/Internal.swift @@ -22,7 +22,7 @@ public enum Internal { /// Helper to loop over a list of Messages to see if they are all /// initialized (see Message.isInitialized for what that means). - public static func areAllInitialized(_ listOfMessages: [Message]) -> Bool { + public static func areAllInitialized(_ listOfMessages: [any Message]) -> Bool { for msg in listOfMessages { if !msg.isInitialized { return false @@ -33,7 +33,7 @@ public enum Internal { /// Helper to loop over dictionary with values that are Messages to see if /// they are all initialized (see Message.isInitialized for what that means). - public static func areAllInitialized(_ mapToMessages: [K: Message]) -> Bool { + public static func areAllInitialized(_ mapToMessages: [K: any Message]) -> Bool { for (_, msg) in mapToMessages { if !msg.isInitialized { return false diff --git a/Sources/SwiftProtobuf/JSONDecoder.swift b/Sources/SwiftProtobuf/JSONDecoder.swift index 65bf0747a..0cd5274fd 100644 --- a/Sources/SwiftProtobuf/JSONDecoder.swift +++ b/Sources/SwiftProtobuf/JSONDecoder.swift @@ -16,7 +16,7 @@ import Foundation internal struct JSONDecoder: Decoder { internal var scanner: JSONScanner - internal var messageType: Message.Type + internal var messageType: any Message.Type private var fieldCount = 0 private var isMapKey = false private var fieldNameMap: _NameMap? @@ -30,14 +30,14 @@ internal struct JSONDecoder: Decoder { } internal init(source: UnsafeRawBufferPointer, options: JSONDecodingOptions, - messageType: Message.Type, extensions: ExtensionMap?) { + messageType: any Message.Type, extensions: (any ExtensionMap)?) { let scanner = JSONScanner(source: source, options: options, extensions: extensions) self.init(scanner: scanner, messageType: messageType) } - private init(scanner: JSONScanner, messageType: Message.Type) { + private init(scanner: JSONScanner, messageType: any Message.Type) { self.scanner = scanner self.messageType = messageType } @@ -469,7 +469,7 @@ internal struct JSONDecoder: Decoder { mutating func decodeSingularEnumField(value: inout E?) throws where E.RawValue == Int { if scanner.skipOptionalNull() { - if let customDecodable = E.self as? _CustomJSONCodable.Type { + if let customDecodable = E.self as? any _CustomJSONCodable.Type { value = try customDecodable.decodedFromJSONNull() as? E return } @@ -485,7 +485,7 @@ internal struct JSONDecoder: Decoder { mutating func decodeSingularEnumField(value: inout E) throws where E.RawValue == Int { if scanner.skipOptionalNull() { - if let customDecodable = E.self as? _CustomJSONCodable.Type { + if let customDecodable = E.self as? any _CustomJSONCodable.Type { value = try customDecodable.decodedFromJSONNull() as! E return } @@ -507,7 +507,7 @@ internal struct JSONDecoder: Decoder { if scanner.skipOptionalArrayEnd() { return } - let maybeCustomDecodable = E.self as? _CustomJSONCodable.Type + let maybeCustomDecodable = E.self as? any _CustomJSONCodable.Type while true { if scanner.skipOptionalNull() { if let customDecodable = maybeCustomDecodable { @@ -529,11 +529,11 @@ internal struct JSONDecoder: Decoder { } internal mutating func decodeFullObject(message: inout M) throws { - guard let nameProviding = (M.self as? _ProtoNameProviding.Type) else { + guard let nameProviding = (M.self as? any _ProtoNameProviding.Type) else { throw JSONDecodingError.missingFieldNames } fieldNameMap = nameProviding._protobuf_nameMap - if let m = message as? _CustomJSONCodable { + if let m = message as? (any _CustomJSONCodable) { var customCodable = m try customCodable.decodeJSON(from: &self) message = customCodable as! M @@ -548,9 +548,9 @@ internal struct JSONDecoder: Decoder { mutating func decodeSingularMessageField(value: inout M?) throws { if scanner.skipOptionalNull() { - if M.self is _CustomJSONCodable.Type { + if M.self is any _CustomJSONCodable.Type { value = - try (M.self as! _CustomJSONCodable.Type).decodedFromJSONNull() as? M + try (M.self as! any _CustomJSONCodable.Type).decodedFromJSONNull() as? M return } // All other message field types treat 'null' as an unset @@ -579,8 +579,8 @@ internal struct JSONDecoder: Decoder { while true { if scanner.skipOptionalNull() { var appended = false - if M.self is _CustomJSONCodable.Type { - if let message = try (M.self as! _CustomJSONCodable.Type) + if M.self is any _CustomJSONCodable.Type { + if let message = try (M.self as! any _CustomJSONCodable.Type) .decodedFromJSONNull() as? M { value.append(message) appended = true @@ -730,7 +730,7 @@ internal struct JSONDecoder: Decoder { mutating func decodeExtensionField( values: inout ExtensionFieldValueSet, - messageType: Message.Type, + messageType: any Message.Type, fieldNumber: Int ) throws { // Force-unwrap: we can only get here if the extension exists. diff --git a/Sources/SwiftProtobuf/JSONEncodingVisitor.swift b/Sources/SwiftProtobuf/JSONEncodingVisitor.swift index db51d22e7..e1f06d8eb 100644 --- a/Sources/SwiftProtobuf/JSONEncodingVisitor.swift +++ b/Sources/SwiftProtobuf/JSONEncodingVisitor.swift @@ -34,8 +34,8 @@ internal struct JSONEncodingVisitor: Visitor { /// Creates a new visitor for serializing a message of the given type to JSON /// format. - init(type: Message.Type, options: JSONEncodingOptions) throws { - if let nameProviding = type as? _ProtoNameProviding.Type { + init(type: any Message.Type, options: JSONEncodingOptions) throws { + if let nameProviding = type as? any _ProtoNameProviding.Type { self.nameMap = nameProviding._protobuf_nameMap } else { throw JSONEncodingError.missingFieldNames @@ -51,13 +51,13 @@ internal struct JSONEncodingVisitor: Visitor { encoder.endArray() } - mutating func startObject(message: Message) { - self.extensions = (message as? ExtensibleMessage)?._protobuf_extensionFieldValues + mutating func startObject(message: any Message) { + self.extensions = (message as? (any ExtensibleMessage))?._protobuf_extensionFieldValues encoder.startObject() } - mutating func startArrayObject(message: Message) { - self.extensions = (message as? ExtensibleMessage)?._protobuf_extensionFieldValues + mutating func startArrayObject(message: any Message) { + self.extensions = (message as? (any ExtensibleMessage))?._protobuf_extensionFieldValues encoder.startArrayObject() } @@ -159,7 +159,7 @@ internal struct JSONEncodingVisitor: Visitor { mutating func visitSingularEnumField(value: E, fieldNumber: Int) throws { try startField(for: fieldNumber) - if let e = value as? _CustomJSONCodable { + if let e = value as? (any _CustomJSONCodable) { let json = try e.encodedJSONString(options: options) encoder.append(text: json) } else if !options.alwaysPrintEnumsAsInts, let n = value.name { @@ -171,10 +171,10 @@ internal struct JSONEncodingVisitor: Visitor { mutating func visitSingularMessageField(value: M, fieldNumber: Int) throws { try startField(for: fieldNumber) - if let m = value as? _CustomJSONCodable { + if let m = value as? (any _CustomJSONCodable) { let json = try m.encodedJSONString(options: options) encoder.append(text: json) - } else if let newNameMap = (M.self as? _ProtoNameProviding.Type)?._protobuf_nameMap { + } else if let newNameMap = (M.self as? any _ProtoNameProviding.Type)?._protobuf_nameMap { // Preserve outer object's name and extension maps; restore them before returning let oldNameMap = self.nameMap let oldExtensions = self.extensions @@ -296,11 +296,11 @@ internal struct JSONEncodingVisitor: Visitor { } mutating func visitRepeatedEnumField(value: [E], fieldNumber: Int) throws { - if let _ = E.self as? _CustomJSONCodable.Type { + if let _ = E.self as? any _CustomJSONCodable.Type { let options = self.options try _visitRepeated(value: value, fieldNumber: fieldNumber) { (encoder: inout JSONEncoder, v: E) throws in - let e = v as! _CustomJSONCodable + let e = v as! (any _CustomJSONCodable) let json = try e.encodedJSONString(options: options) encoder.append(text: json) } @@ -322,7 +322,7 @@ internal struct JSONEncodingVisitor: Visitor { try startField(for: fieldNumber) var comma = false encoder.startArray() - if let _ = M.self as? _CustomJSONCodable.Type { + if let _ = M.self as? any _CustomJSONCodable.Type { for v in value { if comma { encoder.comma() @@ -331,7 +331,7 @@ internal struct JSONEncodingVisitor: Visitor { let json = try v.jsonString(options: options) encoder.append(text: json) } - } else if let newNameMap = (M.self as? _ProtoNameProviding.Type)?._protobuf_nameMap { + } else if let newNameMap = (M.self as? any _ProtoNameProviding.Type)?._protobuf_nameMap { // Preserve name and extension maps for outer object let oldNameMap = self.nameMap let oldExtensions = self.extensions diff --git a/Sources/SwiftProtobuf/JSONScanner.swift b/Sources/SwiftProtobuf/JSONScanner.swift index 6e444481b..98c8c317b 100644 --- a/Sources/SwiftProtobuf/JSONScanner.swift +++ b/Sources/SwiftProtobuf/JSONScanner.swift @@ -374,7 +374,7 @@ internal struct JSONScanner { private var index: UnsafeRawBufferPointer.Index private var numberParser = DoubleParser() internal let options: JSONDecodingOptions - internal let extensions: ExtensionMap + internal let extensions: any ExtensionMap internal var recursionBudget: Int /// True if the scanner has read all of the data from the source, with the @@ -400,7 +400,7 @@ internal struct JSONScanner { internal init( source: UnsafeRawBufferPointer, options: JSONDecodingOptions, - extensions: ExtensionMap? + extensions: (any ExtensionMap)? ) { self.source = source self.index = source.startIndex @@ -1252,7 +1252,7 @@ internal struct JSONScanner { /// it silently skips it. internal mutating func nextFieldNumber( names: _NameMap, - messageType: Message.Type + messageType: any Message.Type ) throws -> Int? { while true { var fieldName: String diff --git a/Sources/SwiftProtobuf/Message+AnyAdditions.swift b/Sources/SwiftProtobuf/Message+AnyAdditions.swift index 67d317820..e8c31b3d6 100644 --- a/Sources/SwiftProtobuf/Message+AnyAdditions.swift +++ b/Sources/SwiftProtobuf/Message+AnyAdditions.swift @@ -36,7 +36,7 @@ extension Message { /// `BinaryDecodingError` on failure. public init( unpackingAny: Google_Protobuf_Any, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { self.init() diff --git a/Sources/SwiftProtobuf/Message+BinaryAdditions.swift b/Sources/SwiftProtobuf/Message+BinaryAdditions.swift index 0e4128ec9..2580ed450 100644 --- a/Sources/SwiftProtobuf/Message+BinaryAdditions.swift +++ b/Sources/SwiftProtobuf/Message+BinaryAdditions.swift @@ -91,7 +91,7 @@ extension Message { @inlinable public init( serializedBytes bytes: Bytes, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { @@ -121,7 +121,7 @@ extension Message { @inlinable public mutating func merge( serializedBytes bytes: Bytes, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { @@ -137,7 +137,7 @@ extension Message { @usableFromInline internal mutating func _merge( rawBuffer body: UnsafeRawBufferPointer, - extensions: ExtensionMap?, + extensions: (any ExtensionMap)?, partial: Bool, options: BinaryDecodingOptions ) throws { diff --git a/Sources/SwiftProtobuf/Message+BinaryAdditions_Data.swift b/Sources/SwiftProtobuf/Message+BinaryAdditions_Data.swift index 247272f44..93cb1f3f2 100644 --- a/Sources/SwiftProtobuf/Message+BinaryAdditions_Data.swift +++ b/Sources/SwiftProtobuf/Message+BinaryAdditions_Data.swift @@ -33,7 +33,7 @@ extension Message { @inlinable public init( serializedData data: Data, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { @@ -63,7 +63,7 @@ extension Message { @inlinable public mutating func merge( serializedData data: Data, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, partial: Bool = false, options: BinaryDecodingOptions = BinaryDecodingOptions() ) throws { diff --git a/Sources/SwiftProtobuf/Message+JSONAdditions.swift b/Sources/SwiftProtobuf/Message+JSONAdditions.swift index dc8127c97..8cc822696 100644 --- a/Sources/SwiftProtobuf/Message+JSONAdditions.swift +++ b/Sources/SwiftProtobuf/Message+JSONAdditions.swift @@ -28,7 +28,7 @@ extension Message { public func jsonString( options: JSONEncodingOptions = JSONEncodingOptions() ) throws -> String { - if let m = self as? _CustomJSONCodable { + if let m = self as? (any _CustomJSONCodable) { return try m.encodedJSONString(options: options) } let data: [UInt8] = try jsonUTF8Bytes(options: options) @@ -47,7 +47,7 @@ extension Message { public func jsonUTF8Bytes( options: JSONEncodingOptions = JSONEncodingOptions() ) throws -> Bytes { - if let m = self as? _CustomJSONCodable { + if let m = self as? (any _CustomJSONCodable) { let string = try m.encodedJSONString(options: options) return Bytes(string.utf8) } @@ -80,7 +80,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public init( jsonString: String, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, options: JSONDecodingOptions = JSONDecodingOptions() ) throws { if jsonString.isEmpty { @@ -119,7 +119,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public init( jsonUTF8Bytes: Bytes, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, options: JSONDecodingOptions = JSONDecodingOptions() ) throws { self.init() @@ -131,7 +131,7 @@ extension Message { var decoder = JSONDecoder(source: body, options: options, messageType: Self.self, extensions: extensions) if decoder.scanner.skipOptionalNull() { - if let customCodable = Self.self as? _CustomJSONCodable.Type, + if let customCodable = Self.self as? any _CustomJSONCodable.Type, let message = try customCodable.decodedFromJSONNull() { self = message as! Self } else { diff --git a/Sources/SwiftProtobuf/Message+JSONAdditions_Data.swift b/Sources/SwiftProtobuf/Message+JSONAdditions_Data.swift index a3d4b3bae..f12ef527b 100644 --- a/Sources/SwiftProtobuf/Message+JSONAdditions_Data.swift +++ b/Sources/SwiftProtobuf/Message+JSONAdditions_Data.swift @@ -40,7 +40,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public init( jsonUTF8Data: Data, - extensions: ExtensionMap? = nil, + extensions: (any ExtensionMap)? = nil, options: JSONDecodingOptions = JSONDecodingOptions() ) throws { try self.init(jsonUTF8Bytes: jsonUTF8Data, extensions: extensions, options: options) diff --git a/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift b/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift index b18faa3a4..4c858649b 100644 --- a/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift +++ b/Sources/SwiftProtobuf/Message+JSONArrayAdditions.swift @@ -83,7 +83,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public static func array( fromJSONString jsonString: String, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), options: JSONDecodingOptions = JSONDecodingOptions() ) throws -> [Self] { if jsonString.isEmpty { @@ -124,7 +124,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public static func array( fromJSONUTF8Bytes jsonUTF8Bytes: Bytes, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), options: JSONDecodingOptions = JSONDecodingOptions() ) throws -> [Self] { return try jsonUTF8Bytes.withUnsafeBytes { (body: UnsafeRawBufferPointer) in diff --git a/Sources/SwiftProtobuf/Message+JSONArrayAdditions_Data.swift b/Sources/SwiftProtobuf/Message+JSONArrayAdditions_Data.swift index f9f1fcfe2..2f770a2cc 100644 --- a/Sources/SwiftProtobuf/Message+JSONArrayAdditions_Data.swift +++ b/Sources/SwiftProtobuf/Message+JSONArrayAdditions_Data.swift @@ -44,7 +44,7 @@ extension Message { /// - Throws: `JSONDecodingError` if decoding fails. public static func array( fromJSONUTF8Data jsonUTF8Data: Data, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), options: JSONDecodingOptions = JSONDecodingOptions() ) throws -> [Self] { return try array(fromJSONUTF8Bytes: jsonUTF8Data, diff --git a/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift b/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift index 926df2fa8..9ec430c85 100644 --- a/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift +++ b/Sources/SwiftProtobuf/Message+TextFormatAdditions.swift @@ -67,7 +67,7 @@ extension Message { public init( textFormatString: String, options: TextFormatDecodingOptions = TextFormatDecodingOptions(), - extensions: ExtensionMap? = nil + extensions: (any ExtensionMap)? = nil ) throws { self.init() if !textFormatString.isEmpty { diff --git a/Sources/SwiftProtobuf/Message.swift b/Sources/SwiftProtobuf/Message.swift index b78f5d4bb..b619acfd3 100644 --- a/Sources/SwiftProtobuf/Message.swift +++ b/Sources/SwiftProtobuf/Message.swift @@ -109,7 +109,7 @@ public protocol Message: _CommonMessageConformances { /// Helper to compare `Message`s when not having a specific type to use /// normal `Equatable`. `Equatable` is provided with specific generated /// types. - func isEqualTo(message: Message) -> Bool + func isEqualTo(message: any Message) -> Bool } #if DEBUG @@ -189,7 +189,7 @@ public protocol _MessageImplementationBase: Message, Hashable { } extension _MessageImplementationBase { - public func isEqualTo(message: Message) -> Bool { + public func isEqualTo(message: any Message) -> Bool { guard let other = message as? Self else { return false } diff --git a/Sources/SwiftProtobuf/MessageExtension.swift b/Sources/SwiftProtobuf/MessageExtension.swift index 300765414..80b5ac383 100644 --- a/Sources/SwiftProtobuf/MessageExtension.swift +++ b/Sources/SwiftProtobuf/MessageExtension.swift @@ -19,8 +19,8 @@ public protocol AnyMessageExtension: Sendable { var fieldNumber: Int { get } var fieldName: String { get } - var messageType: Message.Type { get } - func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? + var messageType: any Message.Type { get } + func _protobuf_newField(decoder: inout D) throws -> (any AnyExtensionField)? } /// A "Message Extension" relates a particular extension field to @@ -29,13 +29,13 @@ public protocol AnyMessageExtension: Sendable { public final class MessageExtension: AnyMessageExtension { public let fieldNumber: Int public let fieldName: String - public let messageType: Message.Type + public let messageType: any Message.Type public init(_protobuf_fieldNumber: Int, fieldName: String) { self.fieldNumber = _protobuf_fieldNumber self.fieldName = fieldName self.messageType = MessageType.self } - public func _protobuf_newField(decoder: inout D) throws -> AnyExtensionField? { + public func _protobuf_newField(decoder: inout D) throws -> (any AnyExtensionField)? { return try FieldType(protobufExtension: self, decoder: &decoder) } } diff --git a/Sources/SwiftProtobuf/SimpleExtensionMap.swift b/Sources/SwiftProtobuf/SimpleExtensionMap.swift index c41bee8fd..5c7da6015 100644 --- a/Sources/SwiftProtobuf/SimpleExtensionMap.swift +++ b/Sources/SwiftProtobuf/SimpleExtensionMap.swift @@ -18,11 +18,11 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral { public typealias Element = AnyMessageExtension // Since type objects aren't Hashable, we can't do much better than this... - internal var fields = [Int: Array]() + internal var fields = [Int: Array]() public init() {} - public init(arrayLiteral: Element...) { + public init(arrayLiteral: any Element...) { insert(contentsOf: arrayLiteral) } @@ -32,7 +32,7 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral { } } - public subscript(messageType: Message.Type, fieldNumber: Int) -> AnyMessageExtension? { + public subscript(messageType: any Message.Type, fieldNumber: Int) -> (any AnyMessageExtension)? { get { if let l = fields[fieldNumber] { for e in l { @@ -45,7 +45,7 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral { } } - public func fieldNumberForProto(messageType: Message.Type, protoFieldName: String) -> Int? { + public func fieldNumberForProto(messageType: any Message.Type, protoFieldName: String) -> Int? { // TODO: Make this faster... for (_, list) in fields { for e in list { @@ -57,7 +57,7 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral { return nil } - public mutating func insert(_ newValue: Element) { + public mutating func insert(_ newValue: any Element) { let fieldNumber = newValue.fieldNumber if let l = fields[fieldNumber] { let messageType = newValue.messageType @@ -69,7 +69,7 @@ public struct SimpleExtensionMap: ExtensionMap, ExpressibleByArrayLiteral { } } - public mutating func insert(contentsOf: [Element]) { + public mutating func insert(contentsOf: [any Element]) { for e in contentsOf { insert(e) } diff --git a/Sources/SwiftProtobuf/TextFormatDecoder.swift b/Sources/SwiftProtobuf/TextFormatDecoder.swift index 1c99cf4e7..a51c95581 100644 --- a/Sources/SwiftProtobuf/TextFormatDecoder.swift +++ b/Sources/SwiftProtobuf/TextFormatDecoder.swift @@ -25,7 +25,7 @@ internal struct TextFormatDecoder: Decoder { private var fieldCount = 0 private var terminator: UInt8? private var fieldNameMap: _NameMap? - private var messageType: Message.Type? + private var messageType: (any Message.Type)? internal var complete: Bool { mutating get { @@ -34,24 +34,24 @@ internal struct TextFormatDecoder: Decoder { } internal init( - messageType: Message.Type, + messageType: any Message.Type, utf8Pointer: UnsafeRawPointer, count: Int, options: TextFormatDecodingOptions, - extensions: ExtensionMap? + extensions: (any ExtensionMap)? ) throws { scanner = TextFormatScanner(utf8Pointer: utf8Pointer, count: count, options: options, extensions: extensions) - guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { + guard let nameProviding = (messageType as? any _ProtoNameProviding.Type) else { throw TextFormatDecodingError.missingFieldNames } fieldNameMap = nameProviding._protobuf_nameMap self.messageType = messageType } - internal init(messageType: Message.Type, scanner: TextFormatScanner, terminator: UInt8?) throws { + internal init(messageType: any Message.Type, scanner: TextFormatScanner, terminator: UInt8?) throws { self.scanner = scanner self.terminator = terminator - guard let nameProviding = (messageType as? _ProtoNameProviding.Type) else { + guard let nameProviding = (messageType as? any _ProtoNameProviding.Type) else { throw TextFormatDecodingError.missingFieldNames } fieldNameMap = nameProviding._protobuf_nameMap @@ -706,7 +706,7 @@ internal struct TextFormatDecoder: Decoder { } } - mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: Message.Type, fieldNumber: Int) throws { + mutating func decodeExtensionField(values: inout ExtensionFieldValueSet, messageType: any Message.Type, fieldNumber: Int) throws { if let ext = scanner.extensions?[messageType, fieldNumber] { try values.modify(index: fieldNumber) { fieldValue in if fieldValue != nil { diff --git a/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift b/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift index a82580727..a67953522 100644 --- a/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift +++ b/Sources/SwiftProtobuf/TextFormatEncodingVisitor.swift @@ -32,14 +32,14 @@ internal struct TextFormatEncodingVisitor: Visitor { /// Creates a new visitor that serializes the given message to protobuf text /// format. - init(message: Message, options: TextFormatEncodingOptions) { + init(message: any Message, options: TextFormatEncodingOptions) { let nameMap: _NameMap? - if let nameProviding = message as? _ProtoNameProviding { + if let nameProviding = message as? (any _ProtoNameProviding) { nameMap = type(of: nameProviding)._protobuf_nameMap } else { nameMap = nil } - let extensions = (message as? ExtensibleMessage)?._protobuf_extensionFieldValues + let extensions = (message as? (any ExtensibleMessage))?._protobuf_extensionFieldValues self.nameMap = nameMap self.nameResolver = [:] @@ -270,9 +270,9 @@ internal struct TextFormatEncodingVisitor: Visitor { let oldNameResolver = self.nameResolver let oldExtensions = self.extensions // Update configuration for new message - self.nameMap = (M.self as? _ProtoNameProviding.Type)?._protobuf_nameMap + self.nameMap = (M.self as? any _ProtoNameProviding.Type)?._protobuf_nameMap self.nameResolver = [:] - self.extensions = (value as? ExtensibleMessage)?._protobuf_extensionFieldValues + self.extensions = (value as? (any ExtensibleMessage))?._protobuf_extensionFieldValues // Encode submessage encoder.startMessageField() if let any = value as? Google_Protobuf_Any { @@ -290,7 +290,7 @@ internal struct TextFormatEncodingVisitor: Visitor { // Emit the full "verbose" form of an Any. This writes the typeURL // as a field name in `[...]` followed by the fields of the // contained message. - internal mutating func visitAnyVerbose(value: Message, typeURL: String) { + internal mutating func visitAnyVerbose(value: any Message, typeURL: String) { encoder.emitExtensionFieldName(name: typeURL) encoder.startMessageField() @@ -299,9 +299,9 @@ internal struct TextFormatEncodingVisitor: Visitor { let oldNameResolver = self.nameResolver let oldExtensions = self.extensions // Update configuration for new message - self.nameMap = (type(of: value) as? _ProtoNameProviding.Type)?._protobuf_nameMap + self.nameMap = (type(of: value) as? any _ProtoNameProviding.Type)?._protobuf_nameMap self.nameResolver = [:] - self.extensions = (value as? ExtensibleMessage)?._protobuf_extensionFieldValues + self.extensions = (value as? (any ExtensibleMessage))?._protobuf_extensionFieldValues if let any = value as? Google_Protobuf_Any { any.textTraverse(visitor: &self) @@ -470,9 +470,9 @@ internal struct TextFormatEncodingVisitor: Visitor { let oldNameResolver = self.nameResolver let oldExtensions = self.extensions // Update encoding state for new message type - self.nameMap = (M.self as? _ProtoNameProviding.Type)?._protobuf_nameMap + self.nameMap = (M.self as? any _ProtoNameProviding.Type)?._protobuf_nameMap self.nameResolver = [:] - self.extensions = (value as? ExtensibleMessage)?._protobuf_extensionFieldValues + self.extensions = (value as? (any ExtensibleMessage))?._protobuf_extensionFieldValues // Iterate and encode each message for v in value { encoder.emitFieldName(name: fieldName) diff --git a/Sources/SwiftProtobuf/TextFormatScanner.swift b/Sources/SwiftProtobuf/TextFormatScanner.swift index e2bbbf6e8..f635087e3 100644 --- a/Sources/SwiftProtobuf/TextFormatScanner.swift +++ b/Sources/SwiftProtobuf/TextFormatScanner.swift @@ -232,7 +232,7 @@ private func decodeString(_ s: String) -> String? { /// TextFormatScanner has no public members. /// internal struct TextFormatScanner { - internal var extensions: ExtensionMap? + internal var extensions: (any ExtensionMap)? private var p: UnsafeRawPointer private var end: UnsafeRawPointer private var doubleParser = DoubleParser() @@ -250,7 +250,7 @@ internal struct TextFormatScanner { utf8Pointer: UnsafeRawPointer, count: Int, options: TextFormatDecodingOptions, - extensions: ExtensionMap? = nil + extensions: (any ExtensionMap)? = nil ) { p = utf8Pointer end = p + count diff --git a/Sources/SwiftProtobufPluginLibrary/CodeGenerator.swift b/Sources/SwiftProtobufPluginLibrary/CodeGenerator.swift index c6fd4a00e..540bed519 100644 --- a/Sources/SwiftProtobufPluginLibrary/CodeGenerator.swift +++ b/Sources/SwiftProtobufPluginLibrary/CodeGenerator.swift @@ -37,9 +37,9 @@ public protocol CodeGenerator { /// to the user attempting to generate sources. func generate( files: [FileDescriptor], - parameter: CodeGeneratorParameter, - protoCompilerContext: ProtoCompilerContext, - generatorOutputs: GeneratorOutputs) throws + parameter: any CodeGeneratorParameter, + protoCompilerContext: any ProtoCompilerContext, + generatorOutputs: any GeneratorOutputs) throws /// The list of features this CodeGenerator support to be reported back to /// the protocol buffer compiler. @@ -161,7 +161,7 @@ extension CodeGenerator { /// generation. public func generateCode( request: Google_Protobuf_Compiler_CodeGeneratorRequest, - generator: CodeGenerator + generator: any CodeGenerator ) -> Google_Protobuf_Compiler_CodeGeneratorResponse { // TODO: This will need update to support editions and language specific features. diff --git a/Sources/protoc-gen-swift/GenerationError.swift b/Sources/protoc-gen-swift/GenerationError.swift index eb67bf1a5..fbfedfcc0 100644 --- a/Sources/protoc-gen-swift/GenerationError.swift +++ b/Sources/protoc-gen-swift/GenerationError.swift @@ -14,7 +14,7 @@ enum GenerationError: Error { /// Raised when a parameter was given an invalid value. case invalidParameterValue(name: String, value: String) /// Raised to wrap another error but provide a context message. - case wrappedError(message: String, error: Error) + case wrappedError(message: String, error: any Error) /// Raised with an specific message case message(message: String) diff --git a/Sources/protoc-gen-swift/GeneratorOptions.swift b/Sources/protoc-gen-swift/GeneratorOptions.swift index 7b7b4bad7..6d875e2a6 100644 --- a/Sources/protoc-gen-swift/GeneratorOptions.swift +++ b/Sources/protoc-gen-swift/GeneratorOptions.swift @@ -57,7 +57,7 @@ class GeneratorOptions { /// A string snippet to insert for the visibility let visibilitySourceSnippet: String - init(parameter: CodeGeneratorParameter) throws { + init(parameter: any CodeGeneratorParameter) throws { var outputNaming: OutputNaming = .fullPath var moduleMapPath: String? var visibility: Visibility = .internal diff --git a/Sources/protoc-gen-swift/MessageGenerator.swift b/Sources/protoc-gen-swift/MessageGenerator.swift index f2dd6f0bf..9ef1a9729 100644 --- a/Sources/protoc-gen-swift/MessageGenerator.swift +++ b/Sources/protoc-gen-swift/MessageGenerator.swift @@ -25,8 +25,8 @@ class MessageGenerator { private let visibility: String private let swiftFullName: String private let swiftRelativeName: String - private let fields: [FieldGenerator] - private let fieldsSortedByNumber: [FieldGenerator] + private let fields: [any FieldGenerator] + private let fieldsSortedByNumber: [any FieldGenerator] private let oneofs: [OneofGenerator] private let storage: MessageStorageClassGenerator? private let enums: [EnumGenerator] @@ -529,7 +529,7 @@ fileprivate struct MessageFieldFactory { oneofs = oneofGenerators } - func make(forFieldDescriptor field: FieldDescriptor) -> FieldGenerator { + func make(forFieldDescriptor field: FieldDescriptor) -> any FieldGenerator { guard field.realContainingOneof == nil else { return oneofs[Int(field.oneofIndex!)].fieldGenerator(forFieldNumber: Int(field.number)) } diff --git a/Sources/protoc-gen-swift/MessageStorageClassGenerator.swift b/Sources/protoc-gen-swift/MessageStorageClassGenerator.swift index 5b3d22715..4a2e9cece 100644 --- a/Sources/protoc-gen-swift/MessageStorageClassGenerator.swift +++ b/Sources/protoc-gen-swift/MessageStorageClassGenerator.swift @@ -20,10 +20,10 @@ import SwiftProtobuf /// Generates the `_StorageClass` used for messages that employ copy-on-write /// logic for some of their fields. class MessageStorageClassGenerator { - private let fields: [FieldGenerator] + private let fields: [any FieldGenerator] /// Creates a new `MessageStorageClassGenerator`. - init(fields: [FieldGenerator]) { + init(fields: [any FieldGenerator]) { self.fields = fields } diff --git a/Sources/protoc-gen-swift/OneofGenerator.swift b/Sources/protoc-gen-swift/OneofGenerator.swift index da9db37aa..5c78b5bcd 100644 --- a/Sources/protoc-gen-swift/OneofGenerator.swift +++ b/Sources/protoc-gen-swift/OneofGenerator.swift @@ -188,7 +188,7 @@ class OneofGenerator { } } - func fieldGenerator(forFieldNumber fieldNumber: Int) -> FieldGenerator { + func fieldGenerator(forFieldNumber fieldNumber: Int) -> any FieldGenerator { for f in fields { if f.number == fieldNumber { return f diff --git a/Sources/protoc-gen-swift/SwiftGeneratorPlugin.swift b/Sources/protoc-gen-swift/SwiftGeneratorPlugin.swift index c0f4e268e..942f1043e 100644 --- a/Sources/protoc-gen-swift/SwiftGeneratorPlugin.swift +++ b/Sources/protoc-gen-swift/SwiftGeneratorPlugin.swift @@ -25,9 +25,9 @@ struct SwiftGeneratorPlugin: CodeGenerator { func generate( files: [SwiftProtobufPluginLibrary.FileDescriptor], - parameter: CodeGeneratorParameter, - protoCompilerContext: SwiftProtobufPluginLibrary.ProtoCompilerContext, - generatorOutputs: SwiftProtobufPluginLibrary.GeneratorOutputs + parameter: any CodeGeneratorParameter, + protoCompilerContext: any SwiftProtobufPluginLibrary.ProtoCompilerContext, + generatorOutputs: any SwiftProtobufPluginLibrary.GeneratorOutputs ) throws { let options = try GeneratorOptions(parameter: parameter) @@ -54,7 +54,7 @@ struct SwiftGeneratorPlugin: CodeGenerator { var copyrightLine: String? { return "\(Version.copyright)" } var projectURL: String? { return "https://github.com/apple/swift-protobuf" } - private func auditProtoCVersion(context: SwiftProtobufPluginLibrary.ProtoCompilerContext) { + private func auditProtoCVersion(context: any SwiftProtobufPluginLibrary.ProtoCompilerContext) { guard context.version != nil else { Stderr.print("WARNING: unknown version of protoc, use 3.2.x or later to ensure JSON support is correct.") return diff --git a/Tests/SwiftProtobufTests/TestHelpers.swift b/Tests/SwiftProtobufTests/TestHelpers.swift index 4eedd1027..12f795ff6 100644 --- a/Tests/SwiftProtobufTests/TestHelpers.swift +++ b/Tests/SwiftProtobufTests/TestHelpers.swift @@ -134,7 +134,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable } - func assertJSONEncode(_ expected: String, extensions: ExtensionMap = SimpleExtensionMap(), encodingOptions: JSONEncodingOptions = .init(), file: XCTestFileArgType = #file, line: UInt = #line, configure: (inout MessageTestType) -> Void) { + func assertJSONEncode(_ expected: String, extensions: any ExtensionMap = SimpleExtensionMap(), encodingOptions: JSONEncodingOptions = .init(), file: XCTestFileArgType = #file, line: UInt = #line, configure: (inout MessageTestType) -> Void) { let empty = MessageTestType() var configured = empty configure(&configured) @@ -173,7 +173,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable /// This uses the provided block to initialize the object, then: /// * Encodes the object and checks that the result is the expected result /// * Decodes it again and verifies that the round-trip gives an equal object - func assertTextFormatEncode(_ expected: String, extensions: ExtensionMap? = nil, file: XCTestFileArgType = #file, line: UInt = #line, configure: (inout MessageTestType) -> Void) { + func assertTextFormatEncode(_ expected: String, extensions: (any ExtensionMap)? = nil, file: XCTestFileArgType = #file, line: UInt = #line, configure: (inout MessageTestType) -> Void) { let empty = MessageTestType() var configured = empty configure(&configured) @@ -191,7 +191,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable func assertJSONArrayEncode( _ expected: String, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), file: XCTestFileArgType = #file, line: UInt = #line, configure: (inout [MessageTestType]) -> Void @@ -218,7 +218,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable func assertJSONDecodeSucceeds( _ json: String, options: JSONDecodingOptions = JSONDecodingOptions(), - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), file: XCTestFileArgType = #file, line: UInt = #line, check: (MessageTestType) -> Bool @@ -326,7 +326,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable func assertJSONDecodeFails( _ json: String, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), options: JSONDecodingOptions = JSONDecodingOptions(), file: XCTestFileArgType = #file, line: UInt = #line @@ -358,7 +358,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable func assertJSONArrayDecodeFails( _ json: String, - extensions: ExtensionMap = SimpleExtensionMap(), + extensions: any ExtensionMap = SimpleExtensionMap(), file: XCTestFileArgType = #file, line: UInt = #line ) { @@ -382,7 +382,7 @@ extension PBTestHelpers where MessageTestType: SwiftProtobuf.Message & Equatable } extension XCTestCase { - func assertDebugDescription(_ expected: String, _ m: SwiftProtobuf.Message, fmt: String? = nil, file: XCTestFileArgType = #file, line: UInt = #line) { + func assertDebugDescription(_ expected: String, _ m: any SwiftProtobuf.Message, fmt: String? = nil, file: XCTestFileArgType = #file, line: UInt = #line) { // `assertDebugDescription` is a no-op in release as `debugDescription` is unavailable. #if DEBUG let actual = m.debugDescription @@ -392,7 +392,7 @@ extension XCTestCase { /// Like ``assertDebugDescription``, but only checks the the ``debugDescription`` ends with /// ``expectedSuffix``, mainly useful where you want to be agnotics to some preable like /// the module name. - func assertDebugDescriptionSuffix(_ expectedSuffix: String, _ m: SwiftProtobuf.Message, fmt: String? = nil, file: XCTestFileArgType = #file, line: UInt = #line) { + func assertDebugDescriptionSuffix(_ expectedSuffix: String, _ m: any SwiftProtobuf.Message, fmt: String? = nil, file: XCTestFileArgType = #file, line: UInt = #line) { // `assertDebugDescriptionSuffix` is a no-op in release as `debugDescription` is unavailable. #if DEBUG let actual = m.debugDescription diff --git a/Tests/SwiftProtobufTests/Test_Any.swift b/Tests/SwiftProtobufTests/Test_Any.swift index bd1bdda6f..602c81ac5 100644 --- a/Tests/SwiftProtobufTests/Test_Any.swift +++ b/Tests/SwiftProtobufTests/Test_Any.swift @@ -795,7 +795,7 @@ final class Test_Any: XCTestCase { XCTAssertNil(Google_Protobuf_Any.messageType(forMessageName: SwiftProtoTesting_TestMap.protoMessageName)) // All the WKTs should be registered. - let wkts: [Message.Type] = [ + let wkts: [any Message.Type] = [ Google_Protobuf_Any.self, Google_Protobuf_BoolValue.self, Google_Protobuf_BytesValue.self, diff --git a/Tests/SwiftProtobufTests/Test_AsyncMessageSequence.swift b/Tests/SwiftProtobufTests/Test_AsyncMessageSequence.swift index 9304ab310..4c86dc22a 100644 --- a/Tests/SwiftProtobufTests/Test_AsyncMessageSequence.swift +++ b/Tests/SwiftProtobufTests/Test_AsyncMessageSequence.swift @@ -229,7 +229,7 @@ final class Test_AsyncMessageSequence: XCTestCase { } } - fileprivate func serializedMessageData(messages: [Message]) throws -> [UInt8] { + fileprivate func serializedMessageData(messages: [any Message]) throws -> [UInt8] { let memoryOutputStream = OutputStream.toMemory() memoryOutputStream.open() for message in messages { diff --git a/Tests/SwiftProtobufTests/Test_BinaryDecodingOptions.swift b/Tests/SwiftProtobufTests/Test_BinaryDecodingOptions.swift index 207cd4522..cebfbb8a3 100644 --- a/Tests/SwiftProtobufTests/Test_BinaryDecodingOptions.swift +++ b/Tests/SwiftProtobufTests/Test_BinaryDecodingOptions.swift @@ -20,7 +20,7 @@ final class Test_BinaryDecodingOptions: XCTestCase { func testMessageDepthLimit() throws { - let tests: [([UInt8], Message.Type, ExtensionMap?, [(Int, Bool)])] = [ + let tests: [([UInt8], any Message.Type, (any ExtensionMap)?, [(Int, Bool)])] = [ // Input, (Limit, success/failure) // Messages within messages: // outer is msg 1 diff --git a/Tests/SwiftProtobufTests/Test_SimpleExtensionMap.swift b/Tests/SwiftProtobufTests/Test_SimpleExtensionMap.swift index 606ce1663..50f2c2650 100644 --- a/Tests/SwiftProtobufTests/Test_SimpleExtensionMap.swift +++ b/Tests/SwiftProtobufTests/Test_SimpleExtensionMap.swift @@ -18,7 +18,7 @@ import XCTest extension AnyMessageExtension { // Support equality to simplify testing of getting the correct errors. - func isEqual(_ other: AnyMessageExtension) -> Bool { + func isEqual(_ other: any AnyMessageExtension) -> Bool { return (fieldNumber == other.fieldNumber && fieldName == other.fieldName && messageType == other.messageType) @@ -51,9 +51,9 @@ let ext4 = MessageExtension, SwiftProtoTest final class Test_SimpleExtensionMap: XCTestCase { - func assert(map: SimpleExtensionMap, contains: [AnyMessageExtension], line: UInt = #line) { + func assert(map: SimpleExtensionMap, contains: [any AnyMessageExtension], line: UInt = #line) { // Extact what it constaings. - var includes = [AnyMessageExtension]() + var includes = [any AnyMessageExtension]() for (_, l) in map.fields { for e in l { includes.append(e) diff --git a/Tests/SwiftProtobufTests/Test_Unknown_proto2.swift b/Tests/SwiftProtobufTests/Test_Unknown_proto2.swift index dab869df7..23c1f3b2b 100644 --- a/Tests/SwiftProtobufTests/Test_Unknown_proto2.swift +++ b/Tests/SwiftProtobufTests/Test_Unknown_proto2.swift @@ -159,7 +159,7 @@ final class Test_Unknown_proto2: XCTestCase, PBTestHelpers { } - func assertUnknownFields(_ message: Message, _ bytes: [UInt8], line: UInt = #line) { + func assertUnknownFields(_ message: any Message, _ bytes: [UInt8], line: UInt = #line) { XCTAssertEqual(message.unknownFields.data, Data(bytes), line: line) } diff --git a/Tests/SwiftProtobufTests/Test_Unknown_proto3.swift b/Tests/SwiftProtobufTests/Test_Unknown_proto3.swift index e086cc5bc..47f6ac1d5 100644 --- a/Tests/SwiftProtobufTests/Test_Unknown_proto3.swift +++ b/Tests/SwiftProtobufTests/Test_Unknown_proto3.swift @@ -161,7 +161,7 @@ final class Test_Unknown_proto3: XCTestCase, PBTestHelpers { } - func assertUnknownFields(_ message: Message, _ bytes: [UInt8], line: UInt = #line) { + func assertUnknownFields(_ message: any Message, _ bytes: [UInt8], line: UInt = #line) { XCTAssertEqual(message.unknownFields.data, Data(bytes), line: line) }