Skip to content
Closed
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Sources/ComposableArchitectureMacros/ReducerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,9 @@ extension ReducerMacro: MemberMacro {
\(access)static func scope(\
_ store: ComposableArchitecture.Store<Self.State, Self.Action>\
) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
\(raw: storeScopes.joined(separator: "\n"))
}
Expand Down Expand Up @@ -627,7 +630,7 @@ private enum ReducerCase {
{
return """
case .\(name):
return .\(name)(store.scope(state: \\.\(name), action: \\.\(name))!)
return { .\(name)(store.scope(state: \\.\(name), action: \\.\(name))!) }()
"""
} else if let parameters = element.parameterClause?.parameters {
let bindingNames = (0..<parameters.count).map { "v\($0)" }.joined(separator: ", ")
Expand All @@ -636,12 +639,12 @@ private enum ReducerCase {
.joined(separator: ", ")
return """
case let .\(name)(\(bindingNames)):
return .\(name)(\(returnNames))
return { .\(name)(\(returnNames)) }()
"""
} else {
return """
case .\(name):
return .\(name)
return { .\(name) }()
"""
}
case let .ifConfig(configs):
Expand Down
145 changes: 118 additions & 27 deletions Tests/ComposableArchitectureMacrosTests/ReducerMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
final class ReducerMacroTests: XCTestCase {
override func invokeTest() {
withMacroTesting(
// record: .failed,
record: .failed,
macros: [ReducerMacro.self]
) {
super.invokeTest()
Expand Down Expand Up @@ -242,6 +242,9 @@

}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {

}
Expand Down Expand Up @@ -321,15 +324,26 @@
case alert(AlertState<Alert>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .activity:
return .activity(store.scope(state: \.activity, action: \.activity)!)
return {
.activity(store.scope(state: \.activity, action: \.activity)!)
}()
case .timeline:
return .timeline(store.scope(state: \.timeline, action: \.timeline)!)
return {
.timeline(store.scope(state: \.timeline, action: \.timeline)!)
}()
case .tweet:
return .tweet(store.scope(state: \.tweet, action: \.tweet)!)
return {
.tweet(store.scope(state: \.tweet, action: \.tweet)!)
}()
case let .alert(v0):
return .alert(v0)
return {
.alert(v0)
}()
}
}
}
Expand Down Expand Up @@ -385,11 +399,18 @@
case meeting(ComposableArchitecture.StoreOf<Meeting>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .timeline:
return .timeline(store.scope(state: \.timeline, action: \.timeline)!)
return {
.timeline(store.scope(state: \.timeline, action: \.timeline)!)
}()
case .meeting:
return .meeting(store.scope(state: \.meeting, action: \.meeting)!)
return {
.meeting(store.scope(state: \.meeting, action: \.meeting)!)
}()
}
}
}
Expand Down Expand Up @@ -433,6 +454,9 @@

}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {

}
Expand Down Expand Up @@ -483,6 +507,9 @@
}

package static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {

}
Expand Down Expand Up @@ -533,6 +560,9 @@
}

public static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {

}
Expand Down Expand Up @@ -581,9 +611,14 @@
case alert(AlertState<Never>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case let .alert(v0):
return .alert(v0)
return {
.alert(v0)
}()
}
}
}
Expand Down Expand Up @@ -639,11 +674,18 @@
case timeline(ComposableArchitecture.StoreOf<Timeline>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .activity:
return .activity(store.scope(state: \.activity, action: \.activity)!)
return {
.activity(store.scope(state: \.activity, action: \.activity)!)
}()
case .timeline:
return .timeline(store.scope(state: \.timeline, action: \.timeline)!)
return {
.timeline(store.scope(state: \.timeline, action: \.timeline)!)
}()
}
}
}
Expand Down Expand Up @@ -698,11 +740,18 @@
case meeting(Meeting)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .timeline:
return .timeline(store.scope(state: \.timeline, action: \.timeline)!)
return {
.timeline(store.scope(state: \.timeline, action: \.timeline)!)
}()
case let .meeting(v0):
return .meeting(v0)
return {
.meeting(v0)
}()
}
}
}
Expand Down Expand Up @@ -761,13 +810,22 @@
case meeting(Meeting, syncUp: SyncUp)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case let .alert(v0):
return .alert(v0)
return {
.alert(v0)
}()
case let .dialog(v0):
return .dialog(v0)
return {
.dialog(v0)
}()
case let .meeting(v0, v1):
return .meeting(v0, syncUp: v1)
return {
.meeting(v0, syncUp: v1)
}()
}
}
}
Expand Down Expand Up @@ -831,13 +889,22 @@
case sheet(ComposableArchitecture.StoreOf<Counter>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .drillDown:
return .drillDown(store.scope(state: \.drillDown, action: \.drillDown)!)
return {
.drillDown(store.scope(state: \.drillDown, action: \.drillDown)!)
}()
case .popover:
return .popover(store.scope(state: \.popover, action: \.popover)!)
return {
.popover(store.scope(state: \.popover, action: \.popover)!)
}()
case .sheet:
return .sheet(store.scope(state: \.sheet, action: \.sheet)!)
return {
.sheet(store.scope(state: \.sheet, action: \.sheet)!)
}()
}
}
}
Expand Down Expand Up @@ -885,9 +952,14 @@
case feature(ComposableArchitecture.StoreOf<Nested.Feature>)
}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .feature:
return .feature(store.scope(state: \.feature, action: \.feature)!)
return {
.feature(store.scope(state: \.feature, action: \.feature)!)
}()
}
}
}
Expand Down Expand Up @@ -1247,30 +1319,49 @@

}
static func scope(_ store: ComposableArchitecture.Store<Self.State, Self.Action>) -> CaseScope {
// NB: We are using immediately invoked closures in each case of this switch to work around a Swift
// bug that can cause large switch statements to blow the stack.
// https://forums.swift.org/t/struct-and-enum-accessors-take-a-large-amount-of-stack-space/63251/12
switch store.state {
case .child:
return .child(store.scope(state: \.child, action: \.child)!)
return {
.child(store.scope(state: \.child, action: \.child)!)
}()
#if os(macOS)
case .mac:
return .mac(store.scope(state: \.mac, action: \.mac)!)
return {
.mac(store.scope(state: \.mac, action: \.mac)!)
}()
case let .macAlert(v0):
return .macAlert(v0)
return {
.macAlert(v0)
}()
#elseif os(iOS)
case .phone:
return .phone(store.scope(state: \.phone, action: \.phone)!)
return {
.phone(store.scope(state: \.phone, action: \.phone)!)
}()
#else
case .other:
return .other(store.scope(state: \.other, action: \.other)!)
return {
.other(store.scope(state: \.other, action: \.other)!)
}()
case .another:
return .another
return {
.another
}()
#endif

#if DEBUG
#if INNER
case .inner:
return .inner(store.scope(state: \.inner, action: \.inner)!)
return {
.inner(store.scope(state: \.inner, action: \.inner)!)
}()
case let .innerDialog(v0):
return .innerDialog(v0)
return {
.innerDialog(v0)
}()
#endif
#endif

Expand Down
Loading
Loading