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

Parens: undentation in sequentials #16977

Merged
merged 10 commits into from
Apr 15, 2024

Conversation

brianrourkeboll
Copy link
Contributor

@brianrourkeboll brianrourkeboll commented Apr 2, 2024

Another followup to #16079.

Description

  • Handle some undentation oddities in sequential expressions. Adding the semicolon range to the AST as proposed in SynExpr.Sequential doesn't store presence or range of semicolon ; #16914 would probably still be useful in other scenarios, but I think this is a viable workaround for this particular problem.
  • Keep parens around nested sequentials. This is technically only necessary if the outer sequential is itself nested inside of a list/array/sequence/computation expression where each "sequential" expression node is actually an implicit yield, but there is currently no easy, inexpensive way of knowing that (i.e., for each parenthesized nested sequential expression, we'd need to walk back up the chain of ancestor sequentials in search of an outer list/array/sequence/computation expression).

Examples

Undentation

[
   (if p then q else r); // Cannot remove in place because of the indentation of y below.
    y
]
[
    x;
   (if p then q else r); // Cannot remove in place because of the indentation of x above and the presence of z below.
    z
]
[
     x;                   // This line's indentation means we cannot remove anywhere below.
    ();
    ();
    (* 𝑛 more such lines. *)
    ();
    ();
    (if p then q else r); // Can no longer remove here because of the indentation of x above.
    z
]

Nested sequentials

// [(); (); ()]
let xs =
    [
        ()
        (printfn "1"; ())
        ()
    ]

Before, the parens analyzer would suggest:

// [(); (); (); ()]
let xs =
    [
        ()
        printfn "1"; ()
        ()
    ]

Checklist

  • Test cases added.
  • Release notes entry updated. (This will probably go in 8.0.4xx, so I'll wait till the default target switches over from 8.0.300 to update the release notes.)

* This is technically only necessary if the outer sequential is itself
  nested inside of a list/array/sequence/computation expression where
  each node of the "sequential" expression is actually an implicit
  yield, but there is currently no easy, inexpensive way of knowing
  that.
Copy link
Contributor

github-actions bot commented Apr 2, 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.400.md

@brianrourkeboll brianrourkeboll marked this pull request as ready for review April 8, 2024 16:44
@brianrourkeboll brianrourkeboll requested a review from a team as a code owner April 8, 2024 16:44
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. Please add release notes, otherwise good to go I think :)

@brianrourkeboll brianrourkeboll mentioned this pull request Apr 9, 2024
2 tasks
@psfinaki psfinaki merged commit b4bf40c into dotnet:main Apr 15, 2024
32 checks passed
@brianrourkeboll brianrourkeboll deleted the parens-indent-in-sequentials branch April 15, 2024 11:59
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.

3 participants