From ef94433003fcbd41420a42720c31b7521531eced Mon Sep 17 00:00:00 2001 From: Joe Newton Date: Wed, 15 Nov 2023 15:05:07 -0500 Subject: [PATCH] Added strict concurrency checking and Sendable conformances --- CBORCoding.podspec | 13 ++++---- CBORCoding.xcodeproj/project.pbxproj | 2 ++ Half | 2 +- Package.resolved | 24 +++++++-------- Package.swift | 20 +++++++++--- Sources/CBORCoding/CBOR.swift | 44 ++++++++++++++++++--------- Tests/CBORCodingTests/CBORTests.swift | 2 +- 7 files changed, 68 insertions(+), 39 deletions(-) diff --git a/CBORCoding.podspec b/CBORCoding.podspec index 7d3be4b..df89621 100644 --- a/CBORCoding.podspec +++ b/CBORCoding.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "CBORCoding" - s.version = "1.4.0" + s.version = "1.4.1" s.summary = "A CBOR Encoder and Decoder" s.description = <<-DESC A lightweight framework containing a coder pair for encoding and decoding `Codable` conforming types to and from CBOR document format for iOS, macOS, tvOS, and watchOS. @@ -17,11 +17,12 @@ Pod::Spec.new do |s| s.tvos.deployment_target = '12.0' s.watchos.deployment_target = '4.0' - s.source = { :git => "https://github.com/SomeRandomiOSDev/CBORCoding.git", :tag => s.version.to_s } - s.source_files = 'Sources/**/*.swift' - s.swift_versions = ['5.0'] - s.cocoapods_version = '>= 1.7.3' + s.source = { :git => "https://github.com/SomeRandomiOSDev/CBORCoding.git", :tag => s.version.to_s } + s.source_files = 'Sources/**/*.swift' + s.pod_target_xcconfig = { 'SWIFT_STRICT_CONCURRENCY' => 'complete' } + s.swift_versions = ['5.0'] + s.cocoapods_version = '>= 1.7.3' - s.dependency 'Half', '~> 1.4' + s.dependency 'Half', '~> 1.4.2' end diff --git a/CBORCoding.xcodeproj/project.pbxproj b/CBORCoding.xcodeproj/project.pbxproj index 59f4037..20108c5 100644 --- a/CBORCoding.xcodeproj/project.pbxproj +++ b/CBORCoding.xcodeproj/project.pbxproj @@ -1120,6 +1120,7 @@ SDKROOT = iphoneos; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_STRICT_CONCURRENCY = complete; SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 12.0; VERSIONING_SYSTEM = "apple-generic"; @@ -1184,6 +1185,7 @@ SDKROOT = iphoneos; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_STRICT_CONCURRENCY = complete; SWIFT_VERSION = 5.0; TVOS_DEPLOYMENT_TARGET = 12.0; VALIDATE_PRODUCT = YES; diff --git a/Half b/Half index bb32fc7..14b1ab3 160000 --- a/Half +++ b/Half @@ -1 +1 @@ -Subproject commit bb32fc7a5d5cfcee01e5442b1381450b1fcd4803 +Subproject commit 14b1ab35ffdf62c999ef1016ec0f8e745a6feed5 diff --git a/Package.resolved b/Package.resolved index b9d4306..6492fcb 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,16 +1,14 @@ { - "object": { - "pins": [ - { - "package": "Half", - "repositoryURL": "https://github.com/SomeRandomiOSDev/Half", - "state": { - "branch": null, - "revision": "bb32fc7a5d5cfcee01e5442b1381450b1fcd4803", - "version": "1.4.1" - } + "pins" : [ + { + "identity" : "half", + "kind" : "remoteSourceControl", + "location" : "https://github.com/SomeRandomiOSDev/Half", + "state" : { + "revision" : "14b1ab35ffdf62c999ef1016ec0f8e745a6feed5", + "version" : "1.4.2" } - ] - }, - "version": 1 + } + ], + "version" : 2 } diff --git a/Package.swift b/Package.swift index f961d75..4b89dd7 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.8 import PackageDescription let package = Package( @@ -16,11 +16,23 @@ let package = Package( ], dependencies: [ - .package(url: "https://github.com/SomeRandomiOSDev/Half", from: "1.4.1") + .package(url: "https://github.com/SomeRandomiOSDev/Half", from: "1.4.2") ], targets: [ - .target(name: "CBORCoding", dependencies: ["Half"]), - .testTarget(name: "CBORCodingTests", dependencies: ["CBORCoding", "Half"]) + .target( + name: "CBORCoding", + dependencies: ["Half"], + swiftSettings: [ + .enableExperimentalFeature("StrictConcurrency") + ] + ), + .testTarget( + name: "CBORCodingTests", + dependencies: ["CBORCoding", "Half"], + swiftSettings: [ + .enableExperimentalFeature("StrictConcurrency") + ] + ) ] ) diff --git a/Sources/CBORCoding/CBOR.swift b/Sources/CBORCoding/CBOR.swift index 04e4a11..dc72692 100644 --- a/Sources/CBORCoding/CBOR.swift +++ b/Sources/CBORCoding/CBOR.swift @@ -18,7 +18,7 @@ public enum CBOR { Type value for encoding/decoding Undefined values as outlined in [RFC 8949 Section 5.7](https://datatracker.ietf.org/doc/html/rfc8949#section-5.7). */ - public struct Undefined { } + public struct Undefined: Sendable { } /** CBOR supports encoding negative values normally outside of the range `Int64`. @@ -35,7 +35,7 @@ public enum CBOR { --------------Int64-------------- ``` */ - public struct NegativeUInt64: RawRepresentable { + public struct NegativeUInt64: RawRepresentable, Sendable { // MARK: Public Constants @@ -70,7 +70,7 @@ public enum CBOR { to any particular type/value. `SimpleValue` fills this gap by returning the exact encoded value for those codes that are unassigned or unused. */ - public struct SimpleValue: RawRepresentable { + public struct SimpleValue: RawRepresentable, Sendable { // MARK: RawRepresentable Protocol Requirements @@ -94,7 +94,7 @@ public enum CBOR { Type value for encoding/decoding Big numbers as outlined in [RFC 8949 Section 3.4.3](https://datatracker.ietf.org/doc/html/rfc8949#section-3.4.3). */ - public struct Bignum { + public struct Bignum: Sendable { // MARK: Public Properties @@ -250,7 +250,7 @@ public enum CBOR { support for encoding byte data in this way. This may be useful for sending to decoders that expect byte data lengths to be undefined. */ - public struct IndefiniteLengthData { + public struct IndefiniteLengthData: Sendable { // MARK: Public Properties @@ -310,7 +310,7 @@ public enum CBOR { provides support for encoding byte strings in this way. This may be useful for sending to decoders that expect byte string lengths to be undefined. */ - public struct IndefiniteLengthString { + public struct IndefiniteLengthString: Sendable { // MARK: Public Properties @@ -394,7 +394,7 @@ public enum CBOR { A type that asserts its data is already in CBOR encoded format. No additional encoding is done on the contained byte data. */ - public struct CBOREncoded { + public struct CBOREncoded: Sendable { // MARK: - Properties @@ -424,15 +424,15 @@ extension CBOR { // MARK: Internal Types /// `Null` type for encoding - internal struct Null: Encodable { } + internal struct Null: Encodable, Sendable { } /// `Break` code for ending indefinite length types. This is only used for /// type-mismatch error messages - internal struct Break { } + internal struct Break: Sendable { } /// A byte mask used for splitting the major type bits from the additional /// information bits - internal enum ByteMask: UInt8 { + internal enum ByteMask: UInt8, Sendable { // MARK: Cases @@ -441,7 +441,7 @@ extension CBOR { } /// CBOR Major Type - internal enum MajorType: UInt8 { + internal enum MajorType: UInt8, Sendable { // MARK: Cases @@ -456,7 +456,7 @@ extension CBOR { } /// Major Type 7 defined bits - internal enum Bits: UInt8 { + internal enum Bits: UInt8, Sendable { // MARK: Cases @@ -474,7 +474,7 @@ extension CBOR { Optional CBOR Tags described by [RFC 8949 Section 3.4](https://datatracker.ietf.org/doc/html/rfc8949#section-3.4). */ - internal enum Tag: CustomStringConvertible { + internal enum Tag: CustomStringConvertible, Sendable { // MARK: Cases @@ -590,7 +590,7 @@ extension CBOR { constructing the `codingPath` property of the `__CBOREncoder` and `__CBORDecoder` instances */ - internal struct CodingKey: Swift.CodingKey { + internal struct CodingKey: Swift.CodingKey, Sendable { // MARK: Swift.CodingKey Protocol Requirements @@ -696,3 +696,19 @@ extension DecodingError { } } } + +// MARK: - CBOR.DecimalFraction Extension + +extension CBOR.DecimalFraction: Sendable where I1: Sendable, I2: Sendable { } + +// MARK: - CBOR.Bigfloat Extension + +extension CBOR.Bigfloat: Sendable where I1: Sendable, I2: Sendable { } + +// MARK: - CBOR.IndefiniteLengthArray Extension + +extension CBOR.IndefiniteLengthArray: Sendable where Element: Sendable { } + +// MARK: - CBOR.IndefiniteLengthMap Extension + +extension CBOR.IndefiniteLengthMap: Sendable where Key: Sendable, Value: Sendable { } diff --git a/Tests/CBORCodingTests/CBORTests.swift b/Tests/CBORCodingTests/CBORTests.swift index aff06d5..59592db 100644 --- a/Tests/CBORCodingTests/CBORTests.swift +++ b/Tests/CBORCodingTests/CBORTests.swift @@ -504,7 +504,7 @@ class CBORTests: XCTestCase { func testDirectlyEncodeCBOREncoded() { struct Test: Encodable { - static var value: Data = { + static let value: Data = { try! CBOREncoder().encode("CBOR") }()