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

Tweak parsing recovery of enums, for exprs and match arm patterns #117565

Merged
merged 13 commits into from
Nov 30, 2023

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Nov 4, 2023

Tweak recovery of for (pat in expr) {} for more accurate spans.

When encountering match arm (pat if expr) => {}, recover and suggest removing parentheses. Fix #100825.

When encountering malformed enums, try more localized per-variant parse recovery.

Move parser recovery tests to subdirectory.

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2023

r? @petrochenkov

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 2023
@rust-log-analyzer

This comment has been minimized.

compiler/rustc_parse/src/parser/expr.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor

oli-obk commented Nov 4, 2023

r? @Nilstrieb for parser recovery stuff

@rustbot rustbot assigned Noratrieb and unassigned petrochenkov Nov 4, 2023
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

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

This PR is quite big and changes a lot of things, making it hard to follow and doesn't allow merging the parts that are good already. It also makes it harder to see which test changes are caused by which code changes. Can you split it up into several PRs for the different parts, like enums, for loops and match arms?

tests/ui/parser/issues/issue-104088.rs Show resolved Hide resolved
compiler/rustc_parse/src/parser/expr.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 5, 2023
@rust-log-analyzer

This comment was marked as resolved.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 6, 2023
@estebank
Copy link
Contributor Author

estebank commented Nov 7, 2023

I split the commits as much as possible. I didn't bother making the test comments be accurate for each commit, but did include the .stderr changes corresponding to each of them.

Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

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

Thanks for splitting, that makes it a lot easier to review. I've already reviewed the first 4 commits and they look good. I'll review the rest later.
If you want those merged already (making your job rebasing this easier) you can split them into a separate PR and r=me it. Or you can wait here if you prefer.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 16, 2023
…=Nilstrieb

Tweak error and move tests

r? `@Nilstrieb`

Split off rust-lang#117565.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 17, 2023
Rollup merge of rust-lang#117990 - estebank:issue-100825-part-deux, r=Nilstrieb

Tweak error and move tests

r? `@Nilstrieb`

Split off rust-lang#117565.
Copy link
Member

@Noratrieb Noratrieb left a comment

Choose a reason for hiding this comment

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

finally got around to review it fully, thanks for the patience and sorry for the delay, partially missing time and partially also just forgetting about it 💀

one suggestion for an improvement but that can be a follow up

Splitting up the PR into the many commits was definitely very helpful, thanks. For the future, I think you could have gone further and split every semantic change "pattern changes", "for loop changes", "enum changes", would have also made it easier to see the final UI test diff.

}

fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (P<Pat>, Option<P<Expr>>)> {
if self.token.kind == token::OpenDelim(Delimiter::Parenthesis) {
Copy link
Member

Choose a reason for hiding this comment

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

To make it obvious that the only semantic difference is in the error path, I'd prefer to move the call to parse_pat_allow_top_alt out of the if and move the if down to the error case.
This doesn't have to block the PR and can be done as a follow-up (it wouldn't be too bad if it never happens either, but it would be nice to have it).`

compiler/rustc_parse/src/parser/expr.rs Outdated Show resolved Hide resolved
@@ -1,3 +1,4 @@
// ignore-tidy-filelength
Copy link
Member

Choose a reason for hiding this comment

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

:(

(not really something this PR has to fix though, but it may be nice to split this file up further in the future, maybe by moving out more diagnostic paths)

@Noratrieb
Copy link
Member

Didn't follow all the recovery paths super closely, but I think I got the high level idea and it looks good. Specifically looked out for happy-path regressions, doesn't look like it had any.
So with that
@bors r+

@bors
Copy link
Contributor

bors commented Nov 28, 2023

📌 Commit b4b5981 has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 28, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 29, 2023
Tweak parsing recovery of enums, for exprs and match arm patterns

Tweak recovery of `for (pat in expr) {}` for more accurate spans.

When encountering `match` arm `(pat if expr) => {}`, recover and suggest removing parentheses. Fix rust-lang#100825.

When encountering malformed enums, try more localized per-variant parse recovery.

Move parser recovery tests to subdirectory.
@estebank
Copy link
Contributor Author

@bors r=Nilstrieb

@bors
Copy link
Contributor

bors commented Nov 29, 2023

📌 Commit 88453aa has been approved by Nilstrieb

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 29, 2023
@bors
Copy link
Contributor

bors commented Nov 29, 2023

⌛ Testing commit 88453aa with merge cc74eaa...

bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 29, 2023
Tweak parsing recovery of enums, for exprs and match arm patterns

Tweak recovery of `for (pat in expr) {}` for more accurate spans.

When encountering `match` arm `(pat if expr) => {}`, recover and suggest removing parentheses. Fix rust-lang#100825.

When encountering malformed enums, try more localized per-variant parse recovery.

Move parser recovery tests to subdirectory.
@bors
Copy link
Contributor

bors commented Nov 29, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 29, 2023
@compiler-errors
Copy link
Member

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 29, 2023
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Nov 30, 2023

⌛ Testing commit 88453aa with merge 74fccd0...

@bors
Copy link
Contributor

bors commented Nov 30, 2023

☀️ Test successful - checks-actions
Approved by: Nilstrieb
Pushing 74fccd0 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 30, 2023
@bors bors merged commit 74fccd0 into rust-lang:master Nov 30, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 30, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (74fccd0): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.8% [2.7%, 4.9%] 2
Improvements ✅
(primary)
-3.6% [-3.6%, -3.6%] 1
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) -3.6% [-3.6%, -3.6%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 672.348s -> 673.65s (0.19%)
Artifact size: 313.40 MiB -> 313.41 MiB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Parenthesized match guards should have a specific parser error (and suggestion)
10 participants