Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 6 #212

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let package = Package(
),
],
dependencies: [
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.2.1")),
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")),
],
targets: [
Expand All @@ -29,14 +29,14 @@ let package = Package(
"Bytes"
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
.enableExperimentalFeature("StrictConcurrency"),
]
),
.testTarget(
name: "CodableDatastoreTests",
dependencies: ["CodableDatastore"],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
.enableExperimentalFeature("StrictConcurrency"),
]
),
]
Expand Down
43 changes: 43 additions & 0 deletions Package@swift-6.0.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "CodableDatastore",
platforms: [
.macOS(.v10_15),
.iOS(.v13),
.tvOS(.v13),
.watchOS(.v6),
],
products: [
.library(
name: "CodableDatastore",
targets: ["CodableDatastore"]
),
],
dependencies: [
.package(url: "https://github.com/mochidev/AsyncSequenceReader.git", .upToNextMinor(from: "0.3.0")),
.package(url: "https://github.com/mochidev/Bytes.git", .upToNextMinor(from: "0.3.0")),
],
targets: [
.target(
name: "CodableDatastore",
dependencies: [
"AsyncSequenceReader",
"Bytes"
],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
.testTarget(
name: "CodableDatastoreTests",
dependencies: ["CodableDatastore"],
swiftSettings: [
.swiftLanguageVersion(.v6),
]
),
]
)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please check the [releases](https://github.com/mochidev/CodableDatastore/release
dependencies: [
.package(
url: "https://github.com/mochidev/CodableDatastore.git",
.upToNextMinor(from: "0.3.1")
.upToNextMinor(from: "0.3.2")
),
],
...
Expand Down
4 changes: 4 additions & 0 deletions Sources/CodableDatastore/Indexes/IndexRepresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -276,4 +276,8 @@ public struct AnyIndexRepresentation<Instance: Sendable>: Hashable, Sendable {
}

/// Forced KeyPath conformance since Swift 5.10 doesn't support it out of the box.
#if compiler(>=6)
extension KeyPath: @unchecked @retroactive Sendable where Root: Sendable, Value: Sendable {}
#else
extension KeyPath: @unchecked Sendable where Root: Sendable, Value: Sendable {}
#endif
9 changes: 9 additions & 0 deletions Sources/CodableDatastore/Indexes/Indexable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,21 @@ extension UInt16: DiscreteIndexable, RangedIndexable {}
extension UInt32: DiscreteIndexable, RangedIndexable {}
extension UInt64: DiscreteIndexable, RangedIndexable {}

#if compiler(>=6)
extension Optional: @retroactive Comparable where Wrapped: Comparable {
public static func < (lhs: Self, rhs: Self) -> Bool {
if let lhs, let rhs { return lhs < rhs }
return lhs == nil && rhs != nil
}
}
#else
extension Optional: Comparable where Wrapped: Comparable {
public static func < (lhs: Self, rhs: Self) -> Bool {
if let lhs, let rhs { return lhs < rhs }
return lhs == nil && rhs != nil
}
}
#endif
extension Optional: DiscreteIndexable where Wrapped: DiscreteIndexable {}
extension Optional: RangedIndexable where Wrapped: RangedIndexable {}

Expand Down
25 changes: 21 additions & 4 deletions Sources/CodableDatastore/Indexes/UUID+Comparable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,30 @@ import Foundation

#if swift(<5.9) || os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(Windows)
/// Make UUIDs comparable, so that they can be used transparently as an index.
///
/// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156
#if compiler(>=6)
extension UUID: @retroactive Comparable {
@inlinable
public static func < (lhs: UUID, rhs: UUID) -> Bool {
lhs.isLessThan(rhs: rhs)
}
}
#else
extension UUID: Comparable {
@inlinable
public static func < (lhs: UUID, rhs: UUID) -> Bool {
var leftUUID = lhs.uuid
lhs.isLessThan(rhs: rhs)
}
}
#endif
#endif

extension UUID {
/// Make UUIDs comparable, so that they can be used transparently as an index.
///
/// - SeeAlso: https://github.com/apple/swift-foundation/blob/5388acf1d929865d4df97d3c50e4d08bc4c6bdf0/Sources/FoundationEssentials/UUID.swift#L135-L156
@usableFromInline
func isLessThan(rhs: UUID) -> Bool {
var leftUUID = self.uuid
var rightUUID = rhs.uuid
var result: Int = 0
var diff: Int = 0
Expand All @@ -36,4 +54,3 @@ extension UUID: Comparable {
return result < 0
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Foundation

extension ISO8601DateFormatter {
#if compiler(>=6)
nonisolated(unsafe)
static let withMilliseconds: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(secondsFromGMT: 0)
Expand All @@ -21,6 +23,20 @@ extension ISO8601DateFormatter {
]
return formatter
}()
#else
static let withMilliseconds: ISO8601DateFormatter = {
let formatter = ISO8601DateFormatter()
formatter.timeZone = TimeZone(secondsFromGMT: 0)
formatter.formatOptions = [
.withInternetDateTime,
.withDashSeparatorInDate,
.withColonSeparatorInTime,
.withTimeZone,
.withFractionalSeconds
]
return formatter
}()
#endif
}

extension JSONDecoder.DateDecodingStrategy {
Expand Down
Loading