Skip to content

Commit

Permalink
Swift 6 snapshot fixes
Browse files Browse the repository at this point in the history
- `@_unsafeInheritExecutor` is now a build failure, we can use `isolated
  #isolation` instead.
- `swift-corelibs-foundation` doesn't yet have a release
  post-sendability audit, so we can use `UncheckedSendable` to traffic
  them for now.
  • Loading branch information
stephencelis committed Jul 25, 2024
1 parent cc26d06 commit 17470b2
Show file tree
Hide file tree
Showing 5 changed files with 252 additions and 116 deletions.
23 changes: 20 additions & 3 deletions Sources/Dependencies/DependencyValues/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,28 @@ extension DependencyValues {
/// // Make assertions with model...
/// ```
public var calendar: Calendar {
get { self[CalendarKey.self] }
set { self[CalendarKey.self] = newValue }
get {
#if canImport(Darwin)
self[CalendarKey.self]
#else
self[CalendarKey.self].wrappedValue
#endif
}
set {
#if canImport(Darwin)
self[CalendarKey.self] = newValue
#else
self[CalendarKey.self].newValue
#endif
}
}

private enum CalendarKey: DependencyKey {
static let liveValue = Calendar.autoupdatingCurrent
#if canImport(Darwin)
static let liveValue = Calendar.autoupdatingCurrent
#else
// NB: 'Calendar' sendability is not yet available in a 'swift-corelibs-foundation' release
static let liveValue = UncheckedSendable(Calendar.autoupdatingCurrent)
#endif
}
}
23 changes: 20 additions & 3 deletions Sources/Dependencies/DependencyValues/Locale.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,28 @@ extension DependencyValues {
/// // Make assertions with model...
/// ```
public var locale: Locale {
get { self[LocaleKey.self] }
set { self[LocaleKey.self] = newValue }
get {
#if canImport(Darwin)
self[LocaleKey.self]
#else
self[LocaleKey.self].wrappedValue
#endif
}
set {
#if canImport(Darwin)
self[LocaleKey.self] = newValue
#else
self[LocaleKey.self].newValue
#endif
}
}

private enum LocaleKey: DependencyKey {
static let liveValue = Locale.autoupdatingCurrent
#if canImport(Darwin)
static let liveValue = Locale.autoupdatingCurrent
#else
// NB: 'Locale' sendability is not yet available in a 'swift-corelibs-foundation' release
static let liveValue = UncheckedSendable(Locale.autoupdatingCurrent)
#endif
}
}
23 changes: 20 additions & 3 deletions Sources/Dependencies/DependencyValues/TimeZone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,28 @@ extension DependencyValues {
/// // Make assertions with model...
/// ```
public var timeZone: TimeZone {
get { self[TimeZoneKey.self] }
set { self[TimeZoneKey.self] = newValue }
get {
#if canImport(Darwin)
self[TimeZoneKey.self]
#else
self[TimeZoneKey.self].wrappedValue
#endif
}
set {
#if canImport(Darwin)
self[TimeZoneKey.self] = newValue
#else
self[TimeZoneKey.self].newValue
#endif
}
}

private enum TimeZoneKey: DependencyKey {
static let liveValue = TimeZone.autoupdatingCurrent
#if canImport(Darwin)
static let liveValue = TimeZone.autoupdatingCurrent
#else
// NB: 'TimeZone' sendability is not yet available in a 'swift-corelibs-foundation' release
static let liveValue = UncheckedSendable(TimeZone.autoupdatingCurrent)
#endif
}
}
6 changes: 3 additions & 3 deletions Sources/Dependencies/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension DependencyValues {
}

@available(*, deprecated, message: "Use 'withDependencies' instead.")
public static func withValue<Value, R>(
public static func withValue<Value, R: Sendable>(
_ keyPath: WritableKeyPath<DependencyValues, Value>,
_ value: @autoclosure () -> Value,
operation: () async throws -> R
Expand All @@ -133,7 +133,7 @@ extension DependencyValues {
}

@available(*, deprecated, message: "Use 'withDependencies' instead.")
public static func withValues<R>(
public static func withValues<R: Sendable>(
_ updateValuesForOperation: (inout Self) throws -> Void,
operation: () async throws -> R
) async rethrows -> R {
Expand All @@ -149,7 +149,7 @@ extension DependencyValues {
}

@available(*, deprecated, message: "Use 'withDependencies' instead.")
public static func withTestValues<R>(
public static func withTestValues<R: Sendable>(
_ updateValuesForOperation: (inout Self) async throws -> Void,
assert operation: () async throws -> R
) async rethrows -> R {
Expand Down
Loading

0 comments on commit 17470b2

Please sign in to comment.