Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12360] SwiftFormat uses a SwiftSyntax tag that can cause stack overflow in debug mode #334

Closed
swift-ci opened this issue Mar 13, 2020 · 3 comments
Assignees
Labels
bug Something isn't working swift-format

Comments

@swift-ci
Copy link

Previous ID SR-12360
Radar rdar://problem/60832848
Original Reporter cukier (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s swift-format
Labels Bug
Assignee @allevato
Priority Medium

md5: 4111fa0935f36cb69278ce6ab26c299c

Issue Description:

Stack overflow 2: revenge of the rdar://55929175

After implementing formatting in sourcekit-lsp I was investigating why it wasn't working for things that are nested four levels deep. After fighting with debugger, I had a hunch that it may be stack overflow. I found a comment in the function that was crashing:

    // The implementation of every generated case goes into its own function. This
    // circumvents an issue where the compiler allocates stack space for every
    // case statement next to each other in debug builds, causing it to allocate
    // ~50KB per call to this function. rdar://55929175

It crashes only in debug mode, on macos

To reproduce:

  • clone https://github.com/Trzyipolkostkicukru/sourcekit-lsp/tree/format and checkout commit ed642036f4b9ce7696ad340523ed8e9b4bdb9761

  • get toolchain swift-DEVELOPMENT-SNAPSHOT-2020-01-29-a and set it as your compiler

  • compile and set up sourcekit-lsp

  • try to format a file with 4+ levels of nesting, for example:

    do {
    do { do { do { print("Hello, world") } } } 
    }
@beccadax
Copy link

@swift-ci create

@akyrtzi
Copy link
Member

akyrtzi commented Mar 25, 2020

@ahoppen fixed this in apple/swift-syntax#205 but swift-format is using a snapshot tag that is prior to this improvement.

I think this is a case where swift-format needs to update the SwiftSyntax dependency.

\cc @allevato

@allevato
Copy link
Collaborator

I've just cut the swift-5.2-branch of swift-format which depends on swift-syntax 0.50200.0, which contains the above fix. The master branch is also using 0.50200.0 for the time being, so it will work there as well.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working swift-format
Projects
None yet
Development

No branches or pull requests

4 participants