Skip to content

Immediately receiving "error: fatalError" with "The compiler is unable to type-check this expression in reasonable time" #69621

Open
@art-divin

Description

@art-divin

Description

While tinkering with swift-syntax I have changed the signature of the following method:

 private func visitImpl<NodeType: SyntaxProtocol>(
    _ node: Syntax,
    _ nodeType: NodeType.Type,
    _ visit: (NodeType) -> SyntaxVisitorContinueKind,
    _ visitPost: (NodeType) -> Void
  ) {
    let node = node.cast(NodeType.self)
    let needsChildren = (visit(node) == .visitChildren)
    // Avoid calling into visitChildren if possible.
    if needsChildren && !node.raw.layoutView!.children.isEmpty {
      visitChildren(node)
    }
    visitPost(node)
  }

to variant without generics:

private func visitImpl(
    _ node: Syntax,
    _ nodeType: SyntaxProtocol.Type,
    _ visit: (SyntaxProtocol) -> SyntaxVisitorContinueKind,
    _ visitPost: (SyntaxProtocol) -> Void
  ) {
    let node = node.cast(nodeType)
    let needsChildren = (visit(node) == .visitChildren)
    // Avoid calling into visitChildren if possible.
    if needsChildren && !node.raw.layoutView!.children.isEmpty {
      visitChildren(node)
    }
    visitPost(node)
  }

I then immediately receive "error: fatalError" with "The compiler is unable to type-check this expression in reasonable time"

Steps to reproduce

  1. clone https://github.com/art-divin/swift-syntax/ and checkout branch "resolve-compilation-time-issues" with commit 16c35c5ffb529185adf1af8f0d3fe38c96b89ecb
  2. cd into cloned directory
  3. swift build to see error: fatalError or use Xcode to see The compiler is unable to type-check this expression in reasonable time

Expected behavior

Code should compile

Environment

  • Swift compiler version info swift-driver version: 1.87.1 Apple Swift version 5.9 (swiftlang-5.9.0.128.108 clang-1500.0.40.1)
  • Xcode version info Xcode 15.0.1 (Build version 15A507)
  • Deployment target: Target: arm64-apple-macosx14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions