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

ScalametaParser: less backtrack on ctrl cond, body #3803

Merged
merged 2 commits into from
Jul 8, 2024

Conversation

kitbellew
Copy link
Contributor

If a scala3 if/while actually uses scala2 syntax, we might have parsed part of the body while looking for then or do, which leads to some backtracking.

Specifically, for nested if clauses with their then part in explicit braces, each will be parsed exactly twice, once as a continuation of the condition expression and second time as the body, thus leading to an exponential time complexity.

Let's instead reduce backtracking by processing what might be both an argument to a condition expression or an initial part of the body, such as a brace expression, and then using it either for condition or for body.

Fixes scalameta/metals#6552. Supersedes #3795.

@kitbellew kitbellew requested a review from tgodzik July 5, 2024 08:56
If a scala3 if/while actually uses scala2 syntax, we might have parsed
part of the body while looking for `then` or `do`, which leads to some
backtracking.

Specifically, for nested `if` clauses with their `then` part in explicit
braces, each will be parsed exactly twice, once as a continuation of the
condition expression and second time as the body, thus leading to an
exponential time complexity.

Let's instead reduce backtracking by processing what might be both an
argument to a condition expression or an initial part of the body,
such as a brace expression, and then using it either for condition or
for body.
Copy link
Collaborator

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik tgodzik merged commit 70e0f69 into scalameta:main Jul 8, 2024
24 checks passed
@kitbellew kitbellew deleted the mtl6552_4 branch July 8, 2024 12:27
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.

Indexing never completes on large Scala codebase
2 participants