Skip to content

Commit 5901e46

Browse files
authored
[VER] Bump up Swift compiler version to 5.7.1 to follow Apple's policy (#140)
* [VER] Bump up Swift compiler version to 5.7.1 * [MOD] Modified swiftwasm version to use over 5.7.0 package
1 parent 341b551 commit 5901e46

File tree

7 files changed

+138
-245
lines changed

7 files changed

+138
-245
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
steps:
6363
- uses: actions/checkout@v3
6464
- run: echo "${{ matrix.toolchain }}" > .swift-version
65-
- uses: swiftwasm/swiftwasm-action@v5.7
65+
- uses: swiftwasm/swiftwasm-action@v5.8
6666
with:
6767
shell-action: carton test --environment node
6868

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.6
1+
// swift-tools-version: 5.7.1
22

33
import PackageDescription
44

Sources/Dependencies/DependencyKey.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,7 @@ public protocol DependencyKey: TestDependencyKey {
120120
/// See ``DependencyKey`` to define a static, default value for the live application.
121121
public protocol TestDependencyKey {
122122
/// The associated type representing the type of the dependency key's value.
123-
#if swift(>=5.7.1)
124-
associatedtype Value: Sendable = Self
125-
#else
126-
// NB: Can't constrain to `Sendable` on earlier Swift versions due to this bug:
127-
// https://github.com/apple/swift/issues/60649
128-
associatedtype Value = Self
129-
#endif
123+
associatedtype Value: Sendable = Self
130124

131125
/// The preview value for the dependency key.
132126
///

Sources/Dependencies/DependencyValues/Clocks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst))
1+
#if (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst))
22
@available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
33
extension DependencyValues {
44
/// The current clock that features should use when a `ContinuousClock` would be appropriate.
Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
#if swift(>=5.7)
2-
// MARK: swift(>=5.7)
3-
4-
func _liveValue(_ key: Any.Type) -> Any? {
5-
(key as? any DependencyKey.Type)?.liveValue
6-
}
7-
#else
8-
// MARK: -
9-
// MARK: swift(<5.7)
10-
11-
private enum Witness<T> {}
12-
13-
func _liveValue(_ key: Any.Type) -> Any? {
14-
func open<T>(_: T.Type) -> Any? {
15-
(Witness<T>.self as? AnyDependencyKey.Type)?.liveValue
16-
}
17-
return _openExistential(key, do: open)
18-
}
19-
20-
protocol AnyDependencyKey {
21-
static var liveValue: Any { get }
22-
}
23-
24-
extension Witness: AnyDependencyKey where T: DependencyKey {
25-
static var liveValue: Any { T.liveValue }
26-
}
27-
#endif
1+
func _liveValue(_ key: Any.Type) -> Any? {
2+
(key as? any DependencyKey.Type)?.liveValue
3+
}

Sources/Dependencies/WithDependencies.swift

Lines changed: 100 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -39,67 +39,45 @@ public func withDependencies<R>(
3939
}
4040
}
4141

42-
#if swift(>=5.7)
43-
/// Updates the current dependencies for the duration of an asynchronous operation.
44-
///
45-
/// Any mutations made to ``DependencyValues`` inside `updateValuesForOperation` will be visible
46-
/// to everything executed in the operation. For example, if you wanted to force the
47-
/// ``DependencyValues/date`` dependency to be a particular date, you can do:
48-
///
49-
/// ```swift
50-
/// await withDependencies {
51-
/// $0.date.now = Date(timeIntervalSince1970: 1234567890)
52-
/// } operation: {
53-
/// // References to date in here are pinned to 1234567890.
54-
/// }
55-
/// ```
56-
///
57-
/// - Parameters:
58-
/// - updateValuesForOperation: A closure for updating the current dependency values for the
59-
/// duration of the operation.
60-
/// - operation: An operation to perform wherein dependencies have been overridden.
61-
/// - Returns: The result returned from `operation`.
62-
@_unsafeInheritExecutor
63-
@discardableResult
64-
public func withDependencies<R>(
65-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
66-
operation: () async throws -> R
67-
) async rethrows -> R {
68-
try await isSetting(true) {
69-
var dependencies = DependencyValues._current
70-
try await updateValuesForOperation(&dependencies)
71-
return try await DependencyValues.$_current.withValue(dependencies) {
72-
try await isSetting(false) {
73-
let result = try await operation()
74-
if R.self is AnyClass {
75-
dependencyObjects.store(result as AnyObject)
76-
}
77-
return result
78-
}
79-
}
80-
}
81-
}
82-
#else
83-
@discardableResult
84-
public func withDependencies<R>(
85-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
86-
operation: () async throws -> R
87-
) async rethrows -> R {
88-
try await isSetting(true) {
89-
var dependencies = DependencyValues._current
90-
try await updateValuesForOperation(&dependencies)
91-
return try await DependencyValues.$_current.withValue(dependencies) {
92-
try await isSetting(false) {
93-
let result = try await operation()
94-
if R.self is AnyClass {
95-
dependencyObjects.store(result as AnyObject)
96-
}
97-
return result
42+
/// Updates the current dependencies for the duration of an asynchronous operation.
43+
///
44+
/// Any mutations made to ``DependencyValues`` inside `updateValuesForOperation` will be visible
45+
/// to everything executed in the operation. For example, if you wanted to force the
46+
/// ``DependencyValues/date`` dependency to be a particular date, you can do:
47+
///
48+
/// ```swift
49+
/// await withDependencies {
50+
/// $0.date.now = Date(timeIntervalSince1970: 1234567890)
51+
/// } operation: {
52+
/// // References to date in here are pinned to 1234567890.
53+
/// }
54+
/// ```
55+
///
56+
/// - Parameters:
57+
/// - updateValuesForOperation: A closure for updating the current dependency values for the
58+
/// duration of the operation.
59+
/// - operation: An operation to perform wherein dependencies have been overridden.
60+
/// - Returns: The result returned from `operation`.
61+
@_unsafeInheritExecutor
62+
@discardableResult
63+
public func withDependencies<R>(
64+
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
65+
operation: () async throws -> R
66+
) async rethrows -> R {
67+
try await isSetting(true) {
68+
var dependencies = DependencyValues._current
69+
try await updateValuesForOperation(&dependencies)
70+
return try await DependencyValues.$_current.withValue(dependencies) {
71+
try await isSetting(false) {
72+
let result = try await operation()
73+
if R.self is AnyClass {
74+
dependencyObjects.store(result as AnyObject)
9875
}
76+
return result
9977
}
10078
}
10179
}
102-
#endif
80+
}
10381

10482
/// Updates the current dependencies for the duration of a synchronous operation by taking the
10583
/// dependencies tied to a given object.
@@ -168,129 +146,76 @@ public func withDependencies<Model: AnyObject, R>(
168146
)
169147
}
170148

171-
#if swift(>=5.7)
172-
/// Updates the current dependencies for the duration of an asynchronous operation by taking the
173-
/// dependencies tied to a given object.
174-
///
175-
/// - Parameters:
176-
/// - model: An object with dependencies. The given model should have at least one `@Dependency`
177-
/// property, or should have been initialized and returned from a `withDependencies`
178-
/// operation.
179-
/// - updateValuesForOperation: A closure for updating the current dependency values for the
180-
/// duration of the operation.
181-
/// - operation: The operation to run with the updated dependencies.
182-
/// - Returns: The result returned from `operation`.
183-
@_unsafeInheritExecutor
184-
@discardableResult
185-
public func withDependencies<Model: AnyObject, R>(
186-
from model: Model,
187-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
188-
operation: () async throws -> R,
189-
file: StaticString? = nil,
190-
line: UInt? = nil
191-
) async rethrows -> R {
192-
guard let values = dependencyObjects.values(from: model)
193-
else {
194-
runtimeWarn(
195-
"""
196-
You are trying to propagate dependencies to a child model from a model with no \
197-
dependencies. To fix this, the given '\(Model.self)' must be returned from another \
198-
'withDependencies' closure, or the class must hold at least one '@Dependency' property.
199-
""",
200-
file: file,
201-
line: line
202-
)
203-
return try await operation()
204-
}
205-
return try await withDependencies {
206-
$0 = values.merging(DependencyValues._current)
207-
try await updateValuesForOperation(&$0)
208-
} operation: {
209-
let result = try await operation()
210-
if R.self is AnyClass {
211-
dependencyObjects.store(result as AnyObject)
212-
}
213-
return result
214-
}
215-
}
216-
#else
217-
@discardableResult
218-
public func withDependencies<Model: AnyObject, R>(
219-
from model: Model,
220-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
221-
operation: () async throws -> R,
222-
file: StaticString? = nil,
223-
line: UInt? = nil
224-
) async rethrows -> R {
225-
guard let values = dependencyObjects.values(from: model)
226-
else {
227-
runtimeWarn(
228-
"""
229-
You are trying to propagate dependencies to a child model from a model with no \
230-
dependencies. To fix this, the given '\(Model.self)' must be returned from another \
231-
'withDependencies' closure, or the class must hold at least one '@Dependency' property.
232-
""",
233-
file: file,
234-
line: line
235-
)
236-
return try await operation()
237-
}
238-
return try await withDependencies {
239-
$0 = values.merging(DependencyValues._current)
240-
try await updateValuesForOperation(&$0)
241-
} operation: {
242-
let result = try await operation()
243-
if R.self is AnyClass {
244-
dependencyObjects.store(result as AnyObject)
245-
}
246-
return result
247-
}
248-
}
249-
#endif
250-
251-
#if swift(>=5.7)
252-
/// Updates the current dependencies for the duration of an asynchronous operation by taking the
253-
/// dependencies tied to a given object.
254-
///
255-
/// - Parameters:
256-
/// - model: An object with dependencies. The given model should have at least one `@Dependency`
257-
/// property, or should have been initialized and returned from a `withDependencies`
258-
/// operation.
259-
/// - operation: The operation to run with the updated dependencies.
260-
/// - Returns: The result returned from `operation`.
261-
@_unsafeInheritExecutor
262-
@discardableResult
263-
public func withDependencies<Model: AnyObject, R>(
264-
from model: Model,
265-
operation: () async throws -> R,
266-
file: StaticString? = nil,
267-
line: UInt? = nil
268-
) async rethrows -> R {
269-
try await withDependencies(
270-
from: model,
271-
{ _ in },
272-
operation: operation,
149+
/// Updates the current dependencies for the duration of an asynchronous operation by taking the
150+
/// dependencies tied to a given object.
151+
///
152+
/// - Parameters:
153+
/// - model: An object with dependencies. The given model should have at least one `@Dependency`
154+
/// property, or should have been initialized and returned from a `withDependencies`
155+
/// operation.
156+
/// - updateValuesForOperation: A closure for updating the current dependency values for the
157+
/// duration of the operation.
158+
/// - operation: The operation to run with the updated dependencies.
159+
/// - Returns: The result returned from `operation`.
160+
@_unsafeInheritExecutor
161+
@discardableResult
162+
public func withDependencies<Model: AnyObject, R>(
163+
from model: Model,
164+
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void,
165+
operation: () async throws -> R,
166+
file: StaticString? = nil,
167+
line: UInt? = nil
168+
) async rethrows -> R {
169+
guard let values = dependencyObjects.values(from: model)
170+
else {
171+
runtimeWarn(
172+
"""
173+
You are trying to propagate dependencies to a child model from a model with no \
174+
dependencies. To fix this, the given '\(Model.self)' must be returned from another \
175+
'withDependencies' closure, or the class must hold at least one '@Dependency' property.
176+
""",
273177
file: file,
274178
line: line
275179
)
180+
return try await operation()
276181
}
277-
#else
278-
@discardableResult
279-
public func withDependencies<Model: AnyObject, R>(
280-
from model: Model,
281-
operation: () async throws -> R,
282-
file: StaticString? = nil,
283-
line: UInt? = nil
284-
) async rethrows -> R {
285-
try await withDependencies(
286-
from: model,
287-
{ _ in },
288-
operation: operation,
289-
file: file,
290-
line: line
291-
)
182+
return try await withDependencies {
183+
$0 = values.merging(DependencyValues._current)
184+
try await updateValuesForOperation(&$0)
185+
} operation: {
186+
let result = try await operation()
187+
if R.self is AnyClass {
188+
dependencyObjects.store(result as AnyObject)
189+
}
190+
return result
292191
}
293-
#endif
192+
}
193+
194+
/// Updates the current dependencies for the duration of an asynchronous operation by taking the
195+
/// dependencies tied to a given object.
196+
///
197+
/// - Parameters:
198+
/// - model: An object with dependencies. The given model should have at least one `@Dependency`
199+
/// property, or should have been initialized and returned from a `withDependencies`
200+
/// operation.
201+
/// - operation: The operation to run with the updated dependencies.
202+
/// - Returns: The result returned from `operation`.
203+
@_unsafeInheritExecutor
204+
@discardableResult
205+
public func withDependencies<Model: AnyObject, R>(
206+
from model: Model,
207+
operation: () async throws -> R,
208+
file: StaticString? = nil,
209+
line: UInt? = nil
210+
) async rethrows -> R {
211+
try await withDependencies(
212+
from: model,
213+
{ _ in },
214+
operation: operation,
215+
file: file,
216+
line: line
217+
)
218+
}
294219

295220
/// Propagates the current dependencies to an escaping context.
296221
///

0 commit comments

Comments
 (0)