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

Don't blow the stack when traversing deeply nested sequential expressions #16882

Merged
merged 9 commits into from
Mar 20, 2024

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Mar 15, 2024

Description

Fixes one of the problems discovered in #16869 (#16869 (comment)).

Sequential expressions are more likely than most other expression kinds to be very deeply nested, e.g., in very large list or array expressions. Since traverseSynExpr is not tail-recursive, we must treat sequential expressions specially to avoid blowing the stack.

(This change isn't specific to the parens analyzer; the parens analyzer was just more likely to run into the underlying problem, since it always traverses each file's full AST.)

With this change in place, I can now successfully apply the "fix all in document" action to remove unnecessary parens in ServiceDeclarationLists.fs:

Screenshot 2024-03-15 115305

Screenshot 2024-03-15 115408

I can even apply the fix inside of the ~17,000-line array expression in pars.fs:

paren_fix

Checklist

  • Test cases added
    • The existing tests that exercise this pathway still pass.
    • Very big array expr test: beef3a6.
  • Release notes entry updated

* Sequential expressions are more likely than most other expression
  kinds to be deeply nested, e.g., in very large list or array
  expressions. Since `traverseSynExpr` is not tail-recursive, we must
  treat them specially to avoid blowing the stack.
Copy link
Contributor

github-actions bot commented Mar 15, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.300.md

@brianrourkeboll brianrourkeboll marked this pull request as ready for review March 15, 2024 20:59
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner March 15, 2024 20:59
Copy link
Member

@psfinaki psfinaki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good stuff, thanks a lot. If that megatest is easy to add, go ahead, would be also useful :)

@psfinaki
Copy link
Member

/azp run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@psfinaki psfinaki merged commit dff5eba into dotnet:main Mar 20, 2024
32 checks passed
@brianrourkeboll brianrourkeboll deleted the deep-sequentials branch March 20, 2024 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants