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

exhaustiveness: Explain why a given pattern is considered unreachable #128034

Merged
merged 4 commits into from
Jul 26, 2024

Conversation

Nadrieril
Copy link
Member

@Nadrieril Nadrieril commented Jul 21, 2024

This PR tells the user why a given pattern is considered unreachable. I reused the intersection information we were already computing; even though it's incomplete I convinced myself that it is sufficient to always get a set of patterns that cover the unreachable one.

I'm not a fan of the diagnostic messages I came up with, I'm open to suggestions.

Fixes #127870. This is also the other one of the two diagnostic improvements I wanted to do before #122792.

Note: the first commit is an unrelated drive-by tweak.

r? @compiler-errors

@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 Jul 21, 2024
Comment on lines +4 to +7
LL | (1 | 2,) => {}
| -------- matches all the values already
LL | (1,) => {}
| ^^^^
| ^^^^ unreachable pattern
Copy link
Member Author

@Nadrieril Nadrieril Jul 21, 2024

Choose a reason for hiding this comment

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

@estebank do you have a better idea for the message here? I want to express that the pattern above already matches all the values matched by the pattern below but I'm not sure what terminology is appropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about "unreachable pattern because it is already fully covered by a(n) earlier one(s)"?

Copy link
Member

Choose a reason for hiding this comment

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

or slightly shorter: "unreachable pattern is already fully covered by an earlier one"

Copy link
Member Author

Choose a reason for hiding this comment

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

I like this. What about the "matches all the values already"?

@Nadrieril
Copy link
Member Author

Nadrieril commented Jul 21, 2024

Turns out we can always get a covering set of patterns! I updated the code and added a proof-sketch as to why.

@Nadrieril Nadrieril force-pushed the explain-unreachable branch 3 times, most recently from 9ffcdd3 to fbc2f03 Compare July 21, 2024 17:29
@Nadrieril
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 21, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 21, 2024
exhaustiveness: Explain why a given pattern is considered unreachable

This PR tells the user why a given pattern is considered unreachable. I reused the intersection information we were already computing; even though it's incomplete I convinced myself that it is sufficient to always get a set of patterns that cover the unreachable one.

I'm not a fan of the diagnostic messages I came up with, I'm open to suggestions.

Fixes rust-lang#127870. This is also the other one of the two diagnostic improvements I wanted to do before rust-lang#122792.

Note: the first commit is rust-lang#128015, the second is an unrelated drive-by tweak.

r? `@compiler-errors`
@bors
Copy link
Contributor

bors commented Jul 21, 2024

⌛ Trying commit fbc2f03 with merge 49ee7bc...

@bors
Copy link
Contributor

bors commented Jul 21, 2024

☀️ Try build successful - checks-actions
Build commit: 49ee7bc (49ee7bc0950a2e4d6de1d7b8e1dad394785091fe)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (49ee7bc): comparison URL.

Overall result: ❌✅ regressions and improvements - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -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.5% [0.1%, 1.6%] 4
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.2% [-0.2%, -0.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

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

Cycles

Results (secondary -2.5%)

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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.5% [-2.6%, -2.4%] 2
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 772.021s -> 773.1s (0.14%)
Artifact size: 328.86 MiB -> 328.93 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 21, 2024
@Nadrieril
Copy link
Member Author

@rustbot ready

@compiler-errors
Copy link
Member

@bors r+ rollup=never

@bors
Copy link
Contributor

bors commented Jul 25, 2024

📌 Commit 940769a has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 25, 2024
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 25, 2024
@@ -403,18 +456,24 @@ error: unreachable pattern
|
LL | _ => {}
| ^
|
= note: this pattern matches no values because `[!; 3]` is uninhabited
Copy link
Contributor

Choose a reason for hiding this comment

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

We should look into making this the span label and maybe have the note be a link to an explanation of uninhabited types (!).

LL | (_, true) => {}
| ^^^^^^^^^ unreachable pattern
|
note: these patterns collectively make the last one unreachable
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not assured that the unreachable pattern was the last one, so we should tweak the wording of this note message to be something along the lines "these patterns collectively make the other one unreachable" or something.

Copy link
Member Author

@Nadrieril Nadrieril Jul 27, 2024

Choose a reason for hiding this comment

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

Hm, it may not be the last one in term of spans, but it has to be the last one in terms of match order

@estebank
Copy link
Contributor

@Nadrieril thank you for doing this! It's gonna be super helpful.

@bors
Copy link
Contributor

bors commented Jul 26, 2024

⌛ Testing commit 940769a with merge 355efac...

Comment on lines +10 to +15
LL | Some(_) => {/* ... */}
| ------- matches some of the same values
LL | None => {/* ... */}
| ---- matches some of the same values
LL | _ => {/* ... */}
| ^ collectively making this unreachable
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the flat line a bit hard to parse, looks more like a separator or a leader to another arrow than an indicator itself. Any specific reason this uses the spatula rather than the forks?

(regardless, this change is wonderful)

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know what "spatula" and "forks" mean, I think just used the default principal/non-principal span mechanism in diagnostics

Copy link
Contributor

Choose a reason for hiding this comment

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

I was being too creative, but

______-- spatula

^^--- fork

I figured it wasn't anything done specifically here. This diagnostic just winds up with more alternating lines of code and ---- than many others, and I think it is somewhat ambiguous whether ---- refers to the line up or down.

Obviously not a big deal since it is just a hint anyway.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. It looks a lot clearer with color at least

@bors
Copy link
Contributor

bors commented Jul 26, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 355efac to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 26, 2024
@bors bors merged commit 355efac into rust-lang:master Jul 26, 2024
7 checks passed
@rustbot rustbot added this to the 1.82.0 milestone Jul 26, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (355efac): 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.2% [0.1%, 0.2%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results (primary -3.1%, secondary -3.1%)

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)
- - 0
Improvements ✅
(primary)
-3.1% [-4.9%, -1.3%] 2
Improvements ✅
(secondary)
-3.1% [-3.1%, -3.1%] 1
All ❌✅ (primary) -3.1% [-4.9%, -1.3%] 2

Cycles

Results (secondary 3.0%)

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.0% [3.0%, 3.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

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

Bootstrap: 771.116s -> 771.493s (0.05%)
Artifact size: 328.99 MiB -> 328.96 MiB (-0.01%)

@Nadrieril Nadrieril deleted the explain-unreachable branch July 26, 2024 23:15
@Nadrieril
Copy link
Member Author

@estebank let's chat about this, I can make another PR to tweak the messages

@Nadrieril
Copy link
Member Author

Is this worthy of relnotes? I think it's cute

@traviscross traviscross added the relnotes Marks issues that should be documented in the release notes of the next release. label Jul 27, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 21, 2024
…ording, r=estebank

Tweak unreachable lint wording

Some tweaks to the notes added in rust-lang#128034.

r? `@estebank`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 21, 2024
Rollup merge of rust-lang#129281 - Nadrieril:tweak-unreachable-lint-wording, r=estebank

Tweak unreachable lint wording

Some tweaks to the notes added in rust-lang#128034.

r? `@estebank`
@Mark-Simulacrum Mark-Simulacrum added relnotes Marks issues that should be documented in the release notes of the next release. and removed relnotes Marks issues that should be documented in the release notes of the next release. labels Aug 25, 2024
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. relnotes Marks issues that should be documented in the release notes of the next release. 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
9 participants