pointfreeco/swift-navigation

The compiler is unable to type-check this expression in reasonable time

andriyslyusar opened this issue · 1 comments

Description

I stumble on Xcode unable to compile the project with error The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions.

As an example I have SwiftUI view with 2 .fullScreenCover and 1 .sheet:

    ...
    var body: some View {
        VStack() {
                Button {
                    viewStore.send(.view(.presentCommunicationListButtonTapped))
                } label: {
                    ...
                }

                Button {
                    viewStore.send(.view(.presentDocumentAttachmentsButtonTapped))
                } label: {
                    ...
                }

                Button {
                    viewStore.send(.view(.presentDocumentDetailsButtonTapped))
                } label: {
                    ...
                }
        }
        .sheet(
            store: store.scope(state: \.$destination, action: DocumentFeature.Action.destination),
            state: /DocumentFeature.State.Destination.customerDetails,
            action: DocumentFeature.Action.Destination.customerDetails,
            content: { (store: StoreOf<CustomerDetailsFeature>) in
                CustomerDetailsScreen(store: store)
            }
        )
        .fullScreenCover(
            unwrapping: viewStore.binding(get: { $0.destination }, send: .local(.resetDestination)),
            case: /DocumentFeature.State.Destination.communicationList,
            content: { _ in
                VStack {}
            }
        )
        .fullScreenCover(
            unwrapping: viewStore.binding(get: { $0.destination }, send: .local(.resetDestination)),
            case: /DocumentFeature.State.Destination.documentAttachmentsList,
            content: { _ in
                VStack {}
            }
        )
    }
struct DocumentFeature: ReducerProtocol {
    struct State: Equatable {
        @PresentationState public var destination: Destination?

        enum Destination: Equatable {
            case customerDetails(CustomerDetailsFeature.State)
            case communicationList
            case documentAttachmentsList
        }
    }
    ...
    var body: some ReducerProtocol<State, Action> {
        Reduce { state, action in
                case .view(.presentCustomerDetailsButtonTapped):
                    state.destination = .customerDetails(.init())
                    return .none

                case .view(.presentCommunicationListButtonTapped):
                    state.destination = .communicationList
                    return .none

                case .view(.presentDocumentAttachmentsButtonTapped):
                    state.destination = .documentAttachmentsList
                    return .none
         ...
       }
       .ifLet(\.$destination, action: /Action.destination) {
            Scope(state: /State.Destination.customerDetails, action: /Action.Destination.customerDetails) {
                CustomerDetailsFeature()
            }
        }

But in case I comment and leave single .fullScreenCover(...) everything is compiling and working.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

No response

SwiftUI Navigation version information

0.7.1

Destination operating system

iOS 15

Xcode version information

14.2 (14C18)

Swift Compiler version information

swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx13.0

Hi @andriyslyusar, this isn't really a problem with the library but sadly just a limitation of the Swift compiler. However, I recommend trying again with Xcode 14.3 / Swift 5.8, as Apple made some big improvements to how result builders work, and that helps view compilation a lot.

I am going to convert this into a discussion for now.