Skip to content

Commit

Permalink
Swift Language Support: Drop <5.9, Add 6.0 (#121)
Browse files Browse the repository at this point in the history
* Swift Language Support: Drop <5.9, Add 6.0

* wip

* wip

* wip

* wip

* wip
  • Loading branch information
stephencelis authored Jun 18, 2024
1 parent a918a38 commit f48c096
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 137 deletions.
20 changes: 2 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,11 @@ concurrency:
jobs:
macos-14:
name: macOS 14 (Xcode ${{ matrix.xcode }})
runs-on: macOS-13
runs-on: macOS-14
strategy:
matrix:
xcode:
- '15.2'
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app
- name: Print Swift version
run: swift --version
- name: Run tests (platforms)
run: make test-platforms

macos-13:
name: macOS 13 (Xcode ${{ matrix.xcode }})
runs-on: macOS-13
strategy:
matrix:
xcode:
- '14.3.1'
- '15.4'
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version: 5.9

import PackageDescription

Expand All @@ -24,6 +24,9 @@ let package = Package(
name: "CustomDump",
dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
Expand Down
5 changes: 1 addition & 4 deletions [email protected][email protected]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.9
// swift-tools-version: 6.0

import PackageDescription

Expand All @@ -24,9 +24,6 @@ let package = Package(
name: "CustomDump",
dependencies: [
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
],
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
Expand Down
9 changes: 3 additions & 6 deletions Sources/CustomDump/Conformances/KeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import Foundation

extension AnyKeyPath: CustomDumpStringConvertible {
public var customDumpDescription: String {
// NB: We gate this to 5.9+ due to this crasher: https://github.com/apple/swift/issues/64865
#if swift(>=5.9)
if #available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) {
return self.debugDescription
}
#endif
if #available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) {
return self.debugDescription
}
return """
\(typeName(Self.self))<\
\(typeName(Self.rootType, genericsAbbreviated: false)), \
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomDump/Conformances/Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ extension Character: CustomDumpRepresentable {
}
}

#if (swift(>=5.7) && !targetEnvironment(macCatalyst) && (os(iOS) || os(tvOS) || os(watchOS))) || (swift(>=5.7.1) && os(macOS))
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
@available(macOS 13, iOS 16, watchOS 9, tvOS 16, *)
extension Duration: CustomDumpStringConvertible {
public var customDumpDescription: String {
Expand Down
31 changes: 9 additions & 22 deletions Sources/CustomDump/Conformances/UserNotifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
switch self.rawValue {
case .alert:
return "UNAuthorizationOptions.alert"
#if (os(iOS) || os(watchOS)) && (swift(<5.9) || !canImport(CompositorServices))
#if os(iOS) || os(watchOS)
case .announcement:
return "UNAuthorizationOptions.announcement"
#endif
Expand All @@ -56,7 +56,7 @@
var allCases: [UNAuthorizationOptions] = [
.alert
]
#if (os(iOS) || os(watchOS)) && (swift(<5.9) || !canImport(CompositorServices))
#if os(iOS) || os(watchOS)
allCases.append(.announcement)
#endif
allCases.append(contentsOf: [
Expand Down Expand Up @@ -132,11 +132,9 @@
struct Option: CustomDumpStringConvertible {
var rawValue: UNNotificationPresentationOptions
var customDumpDescription: String {
#if swift(<5.9) || !canImport(CompositorServices)
if self.rawValue == .alert {
return "UNNotificationPresentationOptions.alert"
}
#endif
if self.rawValue == .alert {
return "UNNotificationPresentationOptions.alert"
}
if self.rawValue == .badge {
return "UNNotificationPresentationOptions.badge"
}
Expand All @@ -155,8 +153,10 @@

var options = self
var children: [Option] = []
var allCases: [UNNotificationPresentationOptions] = []
appendBannerList(&allCases)
var allCases: [UNNotificationPresentationOptions] = [.alert, .badge]
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
allCases.append(contentsOf: [.banner, .list])
}
allCases.append(.sound)
for option in allCases {
if options.contains(option) {
Expand All @@ -174,19 +174,6 @@
displayStyle: .set
)
}

// NB: Workaround for Xcode 13.2's new, experimental build system.
//
// defaults write com.apple.dt.XCBuild EnableSwiftBuildSystemIntegration 1
private func appendBannerList(_ allCases: inout [UNNotificationPresentationOptions]) {
#if swift(<5.9) || !canImport(CompositorServices)
allCases.append(.alert)
#endif
allCases.append(.badge)
if #available(iOS 14, macOS 11, tvOS 14, watchOS 7, *) {
allCases.append(contentsOf: [.banner, .list])
}
}
}

@available(iOS 10, macOS 10.14, tvOS 10, watchOS 3, *)
Expand Down
6 changes: 3 additions & 3 deletions Sources/CustomDump/Diff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
to: &out
)

if let areInIncreasingOrder = areInIncreasingOrder {
if let areInIncreasingOrder {
lhsChildren.sort(by: areInIncreasingOrder)
rhsChildren.sort(by: areInIncreasingOrder)
}
Expand Down Expand Up @@ -692,8 +692,8 @@ public func diff<T>(_ lhs: T, _ rhs: T, format: DiffFormat = .default) -> String
)

default:
if let lhs = stringFromStringProtocol(lhs),
let rhs = stringFromStringProtocol(rhs),
if let lhs = String(stringProtocol: lhs),
let rhs = String(stringProtocol: rhs),
lhs.contains(where: \.isNewline) || rhs.contains(where: \.isNewline)
{
let lhsMirror = Mirror(
Expand Down
2 changes: 1 addition & 1 deletion Sources/CustomDump/Dump.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func _customDump<T, TargetStream>(
)

default:
if let value = stringFromStringProtocol(value) {
if let value = String(stringProtocol: value) {
if value.contains(where: \.isNewline) {
if maxDepth <= 0 {
out.write("\"\"")
Expand Down
79 changes: 0 additions & 79 deletions Sources/CustomDump/Internal/Box.swift

This file was deleted.

8 changes: 8 additions & 0 deletions Sources/CustomDump/Internal/Identifiable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
func isIdentityEqual(_ lhs: Any, _ rhs: Any) -> Bool {
guard let lhs = lhs as? any Identifiable else { return false }
func open<LHS: Identifiable>(_ lhs: LHS) -> Bool {
guard let rhs = rhs as? LHS else { return false }
return lhs.id == rhs.id
}
return open(lhs)
}
27 changes: 27 additions & 0 deletions Sources/CustomDump/Internal/Mirror.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,30 @@ extension Mirror {
}
}
}

func isMirrorEqual(_ lhs: Any, _ rhs: Any) -> Bool {
guard let lhs = lhs as? any Equatable else {
let lhsMirror = Mirror(customDumpReflecting: lhs)
let rhsMirror = Mirror(customDumpReflecting: rhs)
guard
lhsMirror.subjectType == rhsMirror.subjectType,
lhsMirror.children.count == rhsMirror.children.count
else { return false }
guard !lhsMirror.children.isEmpty, !rhsMirror.children.isEmpty
else {
return String(describing: lhs) == String(describing: rhs)
}
for (lhsChild, rhsChild) in zip(lhsMirror.children, rhsMirror.children) {
guard
lhsChild.label == rhsChild.label,
isMirrorEqual(lhsChild.value, rhsChild.value)
else { return false }
}
return true
}
func open<T: Equatable>(_ lhs: T) -> Bool {
guard let rhs = rhs as? T else { return false }
return lhs == rhs
}
return open(lhs)
}
5 changes: 5 additions & 0 deletions Sources/CustomDump/Internal/String.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import Foundation

extension String {
init?(stringProtocol value: Any) {
guard let value = value as? any StringProtocol else { return nil }
self.init(value)
}

func indenting(by count: Int) -> String {
self.indenting(with: String(repeating: " ", count: count))
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/CustomDumpTests/DumpTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ final class DumpTests: XCTestCase {
}

func testKeyPath() {
// NB: While this should run on >=5.9, it currently crashes CI on Xcode 15.2
// NB: While this should run on >=5.9, it currently crashes CI on Xcode 15
#if swift(>=5.10) && (os(iOS) || os(macOS) || os(tvOS) || os(watchOS))
var dump = ""
if #available(macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4, *) {
Expand Down Expand Up @@ -1184,7 +1184,7 @@ final class DumpTests: XCTestCase {
)
}

#if (swift(>=5.7) && !targetEnvironment(macCatalyst) && (os(iOS) || os(tvOS) || os(watchOS))) || (swift(>=5.7.1) && os(macOS))
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
func testDuration() {
guard #available(macOS 13, iOS 16, watchOS 9, tvOS 16, *) else { return }

Expand Down

0 comments on commit f48c096

Please sign in to comment.