Skip to content

Commit a53573e

Browse files
mluisbrownactions-user
authored andcommitted
Run swift-format
1 parent 6c127d0 commit a53573e

18 files changed

+1629
-1620
lines changed

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ let package = Package(
7171
)
7272

7373
#if os(Linux) || os(Android)
74-
package.products.removeAll(where: { $0.name != "ComposableArchitecture" })
75-
package.targets.removeAll(where: { $0.name != "ComposableArchitecture" && $0.name != "ComposableArchitectureTests" })
74+
package.products.removeAll(where: { $0.name != "ComposableArchitecture" })
75+
package.targets.removeAll(where: {
76+
$0.name != "ComposableArchitecture" && $0.name != "ComposableArchitectureTests"
77+
})
7678
#endif

Sources/ComposableArchitecture/Debugging/ReducerInstrumentation.swift

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,88 @@
11
#if canImport(os)
2-
import os.signpost
2+
import os.signpost
33

4-
extension Reducer {
5-
/// Instruments the reducer with
6-
/// [signposts](https://developer.apple.com/documentation/os/logging/recording_performance_data).
7-
/// Each invocation of the reducer will be measured by an interval, and the lifecycle of its
8-
/// effects will be measured with interval and event signposts.
9-
///
10-
/// To use, build your app for Instruments (⌘I), create a blank instrument, and then use the "+"
11-
/// icon at top right to add the signpost instrument. Start recording your app (red button at top
12-
/// left) and then you should see timing information for every action sent to the store and every
13-
/// effect executed.
14-
///
15-
/// Effect instrumentation can be particularly useful for inspecting the lifecycle of long-living
16-
/// effects. For example, if you start an effect (e.g. a location manager) in `onAppear` and
17-
/// forget to tear down the effect in `onDisappear`, it will clearly show in Instruments that the
18-
/// effect never completed.
19-
///
20-
/// - Parameters:
21-
/// - prefix: A string to print at the beginning of the formatted message for the signpost.
22-
/// - log: An `OSLog` to use for signposts.
23-
/// - Returns: A reducer that has been enhanced with instrumentation.
24-
@available(iOS 12.0, *)
25-
public func signpost(
26-
_ prefix: String = "",
27-
log: OSLog = OSLog(
28-
subsystem: "co.pointfree.composable-architecture",
29-
category: "Reducer Instrumentation"
30-
)
31-
) -> Self {
32-
guard log.signpostsEnabled else { return self }
4+
extension Reducer {
5+
/// Instruments the reducer with
6+
/// [signposts](https://developer.apple.com/documentation/os/logging/recording_performance_data).
7+
/// Each invocation of the reducer will be measured by an interval, and the lifecycle of its
8+
/// effects will be measured with interval and event signposts.
9+
///
10+
/// To use, build your app for Instruments (⌘I), create a blank instrument, and then use the "+"
11+
/// icon at top right to add the signpost instrument. Start recording your app (red button at top
12+
/// left) and then you should see timing information for every action sent to the store and every
13+
/// effect executed.
14+
///
15+
/// Effect instrumentation can be particularly useful for inspecting the lifecycle of long-living
16+
/// effects. For example, if you start an effect (e.g. a location manager) in `onAppear` and
17+
/// forget to tear down the effect in `onDisappear`, it will clearly show in Instruments that the
18+
/// effect never completed.
19+
///
20+
/// - Parameters:
21+
/// - prefix: A string to print at the beginning of the formatted message for the signpost.
22+
/// - log: An `OSLog` to use for signposts.
23+
/// - Returns: A reducer that has been enhanced with instrumentation.
24+
@available(iOS 12.0, *)
25+
public func signpost(
26+
_ prefix: String = "",
27+
log: OSLog = OSLog(
28+
subsystem: "co.pointfree.composable-architecture",
29+
category: "Reducer Instrumentation"
30+
)
31+
) -> Self {
32+
guard log.signpostsEnabled else { return self }
3333

34-
// NB: Prevent rendering as "N/A" in Instruments
35-
let zeroWidthSpace = "\u{200B}"
34+
// NB: Prevent rendering as "N/A" in Instruments
35+
let zeroWidthSpace = "\u{200B}"
3636

37-
let prefix = prefix.isEmpty ? zeroWidthSpace : "[\(prefix)] "
37+
let prefix = prefix.isEmpty ? zeroWidthSpace : "[\(prefix)] "
3838

39-
return Self { state, action, environment in
40-
var actionOutput: String!
41-
if log.signpostsEnabled {
42-
actionOutput = debugCaseOutput(action)
43-
os_signpost(.begin, log: log, name: "Action", "%s%s", prefix, actionOutput)
39+
return Self { state, action, environment in
40+
var actionOutput: String!
41+
if log.signpostsEnabled {
42+
actionOutput = debugCaseOutput(action)
43+
os_signpost(.begin, log: log, name: "Action", "%s%s", prefix, actionOutput)
44+
}
45+
let effects = self.run(&state, action, environment)
46+
if log.signpostsEnabled {
47+
os_signpost(.end, log: log, name: "Action")
48+
return
49+
effects
50+
.effectSignpost(prefix, log: log, actionOutput: actionOutput)
51+
}
52+
return effects
4453
}
45-
let effects = self.run(&state, action, environment)
46-
if log.signpostsEnabled {
47-
os_signpost(.end, log: log, name: "Action")
48-
return
49-
effects
50-
.effectSignpost(prefix, log: log, actionOutput: actionOutput)
51-
}
52-
return effects
5354
}
5455
}
55-
}
5656

57-
extension Effect where Error == Never {
58-
@available(iOS 12.0, *)
59-
func effectSignpost(
60-
_ prefix: String,
61-
log: OSLog,
62-
actionOutput: String
63-
) -> Effect<Value, Error> {
64-
let sid = OSSignpostID(log: log)
57+
extension Effect where Error == Never {
58+
@available(iOS 12.0, *)
59+
func effectSignpost(
60+
_ prefix: String,
61+
log: OSLog,
62+
actionOutput: String
63+
) -> Effect<Value, Error> {
64+
let sid = OSSignpostID(log: log)
6565

66-
return self.on(
67-
starting: {
68-
os_signpost(
69-
.begin, log: log, name: "Effect", signpostID: sid, "%sStarted from %s", prefix,
70-
actionOutput
71-
)
72-
},
73-
completed: {
74-
os_signpost(.end, log: log, name: "Effect", signpostID: sid, "%sFinished", prefix)
75-
},
76-
disposed: {
77-
os_signpost(.end, log: log, name: "Effect", signpostID: sid, "%sCancelled", prefix)
78-
},
79-
value: { value in
80-
os_signpost(
81-
.event, log: log, name: "Effect Output", "%sOutput from %s", prefix, actionOutput
82-
)
83-
})
66+
return self.on(
67+
starting: {
68+
os_signpost(
69+
.begin, log: log, name: "Effect", signpostID: sid, "%sStarted from %s", prefix,
70+
actionOutput
71+
)
72+
},
73+
completed: {
74+
os_signpost(.end, log: log, name: "Effect", signpostID: sid, "%sFinished", prefix)
75+
},
76+
disposed: {
77+
os_signpost(.end, log: log, name: "Effect", signpostID: sid, "%sCancelled", prefix)
78+
},
79+
value: { value in
80+
os_signpost(
81+
.event, log: log, name: "Effect Output", "%sOutput from %s", prefix, actionOutput
82+
)
83+
})
84+
}
8485
}
85-
}
8686
#endif
8787

8888
func debugCaseOutput(_ value: Any) -> String {

Sources/ComposableArchitecture/Internal/Debug.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
22

33
#if os(Linux) || os(Android)
4-
import let CDispatch.NSEC_PER_USEC
5-
import let CDispatch.NSEC_PER_SEC
4+
import let CDispatch.NSEC_PER_USEC
5+
import let CDispatch.NSEC_PER_SEC
66
#endif
77

88
func debugOutput(_ value: Any, indent: Int = 0) -> String {
@@ -178,29 +178,29 @@ private let dateFormatter: ISO8601DateFormatter = {
178178
}()
179179

180180
extension DispatchQueue: CustomDebugOutputConvertible {
181-
#if os(Linux) || os(Android)
182-
public var debugOutput: String {
183-
switch self.label {
184-
case "com.apple.main-thread": return "DispatchQueue.main"
185-
case "com.apple.root.default-qos": return "DispatchQueue.global()"
186-
case _ where self.label == "com.apple.root.\(self.qos.qosClass)-qos":
187-
return "DispatchQueue.global(qos: .\(self.qos.qosClass))"
188-
default:
189-
return "DispatchQueue(label: \(self.label.debugDescription), qos: .\(self.qos.qosClass))"
181+
#if os(Linux) || os(Android)
182+
public var debugOutput: String {
183+
switch self.label {
184+
case "com.apple.main-thread": return "DispatchQueue.main"
185+
case "com.apple.root.default-qos": return "DispatchQueue.global()"
186+
case _ where self.label == "com.apple.root.\(self.qos.qosClass)-qos":
187+
return "DispatchQueue.global(qos: .\(self.qos.qosClass))"
188+
default:
189+
return "DispatchQueue(label: \(self.label.debugDescription), qos: .\(self.qos.qosClass))"
190+
}
190191
}
191-
}
192-
#else
193-
public var debugOutput: String {
194-
switch (self, self.label) {
195-
case (.main, _): return "DispatchQueue.main"
196-
case (_, "com.apple.root.default-qos"): return "DispatchQueue.global()"
197-
case (_, _) where self.label == "com.apple.root.\(self.qos.qosClass)-qos":
198-
return "DispatchQueue.global(qos: .\(self.qos.qosClass))"
199-
default:
200-
return "DispatchQueue(label: \(self.label.debugDescription), qos: .\(self.qos.qosClass))"
192+
#else
193+
public var debugOutput: String {
194+
switch (self, self.label) {
195+
case (.main, _): return "DispatchQueue.main"
196+
case (_, "com.apple.root.default-qos"): return "DispatchQueue.global()"
197+
case (_, _) where self.label == "com.apple.root.\(self.qos.qosClass)-qos":
198+
return "DispatchQueue.global(qos: .\(self.qos.qosClass))"
199+
default:
200+
return "DispatchQueue(label: \(self.label.debugDescription), qos: .\(self.qos.qosClass))"
201+
}
201202
}
202-
}
203-
#endif
203+
#endif
204204
}
205205

206206
extension Effect: CustomDebugOutputConvertible {
Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
11
#if canImport(SwiftUI)
2-
import SwiftUI
2+
import SwiftUI
33

4-
@available(iOS 13.0, macOS 10.15, macCatalyst 13, tvOS 13.0, watchOS 6.0, *)
5-
extension LocalizedStringKey: CustomDebugOutputConvertible {
6-
// NB: `LocalizedStringKey` conforms to `Equatable` but returns false for equivalent format strings.
7-
public func formatted(locale: Locale? = nil) -> String {
8-
let children = Array(Mirror(reflecting: self).children)
9-
let key = children[0].value as! String
10-
let arguments: [CVarArg] = Array(Mirror(reflecting: children[2].value).children)
11-
.compactMap {
12-
let children = Array(Mirror(reflecting: $0.value).children)
13-
let value: Any
14-
let formatter: Formatter?
15-
// `LocalizedStringKey.FormatArgument` differs depending on OS/platform.
16-
if children[0].label == "storage" {
17-
(value, formatter) =
18-
Array(Mirror(reflecting: children[0].value).children)[0].value as! (Any, Formatter?)
19-
} else {
20-
value = children[0].value
21-
formatter = children[1].value as? Formatter
4+
@available(iOS 13.0, macOS 10.15, macCatalyst 13, tvOS 13.0, watchOS 6.0, *)
5+
extension LocalizedStringKey: CustomDebugOutputConvertible {
6+
// NB: `LocalizedStringKey` conforms to `Equatable` but returns false for equivalent format strings.
7+
public func formatted(locale: Locale? = nil) -> String {
8+
let children = Array(Mirror(reflecting: self).children)
9+
let key = children[0].value as! String
10+
let arguments: [CVarArg] = Array(Mirror(reflecting: children[2].value).children)
11+
.compactMap {
12+
let children = Array(Mirror(reflecting: $0.value).children)
13+
let value: Any
14+
let formatter: Formatter?
15+
// `LocalizedStringKey.FormatArgument` differs depending on OS/platform.
16+
if children[0].label == "storage" {
17+
(value, formatter) =
18+
Array(Mirror(reflecting: children[0].value).children)[0].value as! (Any, Formatter?)
19+
} else {
20+
value = children[0].value
21+
formatter = children[1].value as? Formatter
22+
}
23+
return formatter?.string(for: value) ?? value as! CVarArg
2224
}
23-
return formatter?.string(for: value) ?? value as! CVarArg
24-
}
2525

26-
return String(format: key, locale: locale, arguments: arguments)
27-
}
26+
return String(format: key, locale: locale, arguments: arguments)
27+
}
2828

29-
public var debugOutput: String {
30-
self.formatted().debugDescription
29+
public var debugOutput: String {
30+
self.formatted().debugDescription
31+
}
3132
}
32-
}
3333
#endif

Sources/ComposableArchitecture/Internal/Locking.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Foundation
22

33
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
4-
extension UnsafeMutablePointer where Pointee == os_unfair_lock_s {
5-
@inlinable @discardableResult
6-
func sync<R>(_ work: () -> R) -> R {
7-
os_unfair_lock_lock(self)
8-
defer { os_unfair_lock_unlock(self) }
9-
return work()
4+
extension UnsafeMutablePointer where Pointee == os_unfair_lock_s {
5+
@inlinable @discardableResult
6+
func sync<R>(_ work: () -> R) -> R {
7+
os_unfair_lock_lock(self)
8+
defer { os_unfair_lock_unlock(self) }
9+
return work()
10+
}
1011
}
11-
}
1212
#endif
1313

1414
extension NSRecursiveLock {

0 commit comments

Comments
 (0)