Closed lydell closed 3 years ago
Hello @lydell, thank you for this detailed report.
I'm clueless why this occurs on Mac and not on Windows.
Perhaps this a problem in FSharp.Core
or FSharp.Compiler.Service
.
Would you be interested in submitting a PR?
Getting a stack overflow on just one OS sure is puzzling!
Would you be interested in submitting a PR?
Interested, yes. But since last time I said that I still haven’t got around to doing anything. So it might take a while depending on how much time I have and how often I bump into this issue.
Now we have an issue at least so we can see if other bump into this as well.
What would the PR that fixes this do? Maybe there's some recursive algorithm that needs to be converted into a proper tailcall?
So, I think the problem occurs in https://github.com/fsprojects/fantomas/blob/a7dd05ab2b85c4e300e778984d41e9e2eeaef88e/src/Fantomas/AstTransformer.fs#L320-L332
The code Simon has is a deeply nested version of Syn.App
and that is giving problems on Mac.
Fantomas actually does not need the tree of AST Nodes
, it will flatten the tree later in: https://github.com/fsprojects/fantomas/blob/a7dd05ab2b85c4e300e778984d41e9e2eeaef88e/src/Fantomas/Trivia.fs#L541-L544
So changing the code in ASTTransformer, to return a list of nodes instead of a parent/child tree might resolve the problem. This is speculation at this point.
@lydell does this still occur in the latest alpha? I've implemented those suggested changes a while ago.
@nojaf I just tested 4.5.0-alpha-011. The problem is fixed! Thank you very much! 🎉
Thanks for confirming!
Repro repo: https://github.com/lydell/fantomas-stack-overflow-demo
Issue created from fantomas-online
Code
Result
Online and in GitHub Actions (we run on
ubuntu-latest
):On macOS:
Problem description
Fantomas crashes with a stack overflow on macOS.
And yes, we do have two long enough pipelines at work to trigger this 😄 Our longest pipeline is currently over 50 pipes long. I had to break it into 3 pieces to get Fantomas to work 🙈
Workaround
Split the pipeline into two parts:
Extra information
Options
Fantomas Master at 02/12/2021 20:07:06 - e016b1c933e8a5b41023098c816279a637bd0965
Default Fantomas configuration
Using 4.4.0-beta-007 locally