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

Keep parsed lambda patterns and expression in syntax tree #10166

Merged
merged 2 commits into from
Sep 21, 2020

Conversation

auduchinok
Copy link
Member

@auduchinok auduchinok commented Sep 21, 2020

Keeps initially parsed lambda patterns and expressions in the syntax tree.

The parser replaces patterns and expression with iterated lambdas that are later used by the type checker and code generation. Ideally this conversion should be done at a later stage, so the syntax tree keeps the actually parsed data instead. Doing so would make a lot of churn, since at this point every other part of the compiler already assumes to work with the iterated lambdas.

The problem with this early conversion approach is tools interested in the syntax tree try to "reconstruct" the original lambdas, each one using a different approach (e.g. FSharpLint, Fantomas). This may be error-prone due to in some of the cases the compiler effectively throws the tree data away (by stripping parens and errors in various cases).

This PR adds another field to SynExpr.Lambda so tooling interested in the syntax tree would be able to work with parsed data.

Other possible approaches:

  • split SynExpr.Lambda into Lambda and IteratedLambda cases (clutters SynExpr, less obvious meaning, more churn)
  • move converting lambdas out of the parser and add a new type for type checker to use (ideal solution, significantly more churn and work to do)

Copy link
Contributor

@TIHan TIHan left a comment

Choose a reason for hiding this comment

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

Looks good. Having the parsed data as part of the Expr.Lambda is fine; we shouldn't need to split it out.

Copy link
Contributor

@cartermp cartermp left a comment

Choose a reason for hiding this comment

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

Thanks, looks good.

For reference, since this changes a public API it is breaking. We are planning on revving the major version to coincide with the F# 5 release so this is fine. But in the future there may be a requirement that we rev the major version.

@cartermp cartermp merged commit f4e6973 into dotnet:main Sep 21, 2020
nosami pushed a commit to xamarin/visualfsharp that referenced this pull request Feb 23, 2021
jaccarmac added a commit to jaccarmac/ShenSharp that referenced this pull request Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants