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

Use a separate pattern type for rustc_pattern_analysis diagnostics #128430

Merged
merged 3 commits into from
Jul 31, 2024

Conversation

Zalathar
Copy link
Contributor

The pattern-analysis code needs to print patterns, as part of its user-visible diagnostics. But it never actually tries to print "real" patterns! Instead, it only ever prints synthetic patterns that it has reconstructed from its own internal represenations.

We can therefore simultaneously remove two obstacles to changing thir::Pat, by having the pattern-analysis code use its own dedicated type for building printable patterns, and then making thir::Pat not printable at all.

r? @Nadrieril

This further reduces the amount of code that relies on `thir::Pat` being
printable.
This reverts commit ae0ec73.

The original change in rust-lang#128304 was intended to be a step towards being able to
print `thir::Pat` even after switching to `PatId`.

But because the only patterns that need to be printed are the synthetic ones
created by pattern analysis (for diagnostic purposes only), it makes more sense
to completely separate the printable patterns from the real THIR patterns.
The pattern-analysis code needs to print patterns, as part of its user-visible
diagnostics. But it never actually tries to print "real" patterns! Instead, it
only ever prints synthetic patterns that it has reconstructed from its own
internal represenations.

We can therefore simultaneously remove two obstacles to changing `thir::Pat`,
by having the pattern-analysis code use its own dedicated type for building
printable patterns, and then making `thir::Pat` not printable at all.
@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 31, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jul 31, 2024

Some changes occurred in exhaustiveness checking

cc @Nadrieril

@Zalathar
Copy link
Contributor Author

I've performed basic simplifications on print::Pat (e.g. removing unused arms/fields), but there are probably further opportunities to simplify the creation and printing of these print patterns.

@Nadrieril
Copy link
Member

Did you try printing rustc::DeconstructedPat<'tcx> directly? That would remove the conversion code which is a bit annoying to maintain

@Zalathar
Copy link
Contributor Author

I did look into printing WitnessPat directly, but that was before I had the idea of splitting out print::Pat, so it felt like it was requiring too many code changes to happen all at once.

Trying to print WitnessPat (without an intermediate print::Pat) does seem like the way to go, eventually. I see print::Pat as a necessary intermediate step on that path.

@Zalathar
Copy link
Contributor Author

That said, I'll have another try at printing WitnessPat directly, and see how feasible it feels now.

@Nadrieril
Copy link
Member

Oh yeah, WitnessPat is the one. I agree this is a good intermediate step, happy to merge this first.

Copy link
Member

@Nadrieril Nadrieril left a comment

Choose a reason for hiding this comment

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

Changes look good

@Nadrieril
Copy link
Member

Btw, no need to make the printing of WitnessPat generic; only printing rustc::WitnessPat is good enough, if rust-analyzer needs similar printing we can dedup later.

@Zalathar
Copy link
Contributor Author

What I plan to do next is to add a special print::PatKind variant that just contains and prints a string, and then incrementally migrate all the other kinds to just be that instead.

Once that's done, all the printing logic will have naturally migrated into hoist_witness_pat, and it should be much more viable to start removing print::Pat entirely.

@Nadrieril
Copy link
Member

Sounds good! Let's merge this first then.

@bors r+

@bors
Copy link
Contributor

bors commented Jul 31, 2024

📌 Commit dd5a8d7 has been approved by Nadrieril

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 Jul 31, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#126454 (bump-stage0: use IndexMap for determinism)
 - rust-lang#127681 (derive(SmartPointer): rewrite bounds in where and generic bounds)
 - rust-lang#127830 (When an archive fails to build, print the path)
 - rust-lang#128151 (Structured suggestion for `extern crate foo` when `foo` isn't resolved in import)
 - rust-lang#128387 (More detailed note to deprecate ONCE_INIT)
 - rust-lang#128388 (Match LLVM ABI in `extern "C"` functions for `f128` on Windows)
 - rust-lang#128402 (Attribute checking simplifications)
 - rust-lang#128412 (Remove `crate_level_only` from `ELIDED_LIFETIMES_IN_PATHS`)
 - rust-lang#128430 (Use a separate pattern type for `rustc_pattern_analysis` diagnostics )

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 031093f into rust-lang:master Jul 31, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jul 31, 2024
Rollup merge of rust-lang#128430 - Zalathar:print-pat, r=Nadrieril

Use a separate pattern type for `rustc_pattern_analysis` diagnostics

The pattern-analysis code needs to print patterns, as part of its user-visible diagnostics. But it never actually tries to print "real" patterns! Instead, it only ever prints synthetic patterns that it has reconstructed from its own internal represenations.

We can therefore simultaneously remove two obstacles to changing `thir::Pat`, by having the pattern-analysis code use its own dedicated type for building printable patterns, and then making `thir::Pat` not printable at all.

r? `@Nadrieril`
@rustbot rustbot added this to the 1.82.0 milestone Jul 31, 2024
@Zalathar Zalathar deleted the print-pat branch August 1, 2024 00:48
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 11, 2024
Preliminary cleanup of `WitnessPat` hoisting/printing

Follow-up to rust-lang#128430.

The eventual goal is to remove `print::Pat` entirely, but in the course of working towards that I made so many small improvements that it seems wise to let those be reviewed/merged on their own first.

Best reviewed commit-by-commit, most of which should be pretty simple and straightforward.

r? `@Nadrieril`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Aug 11, 2024
Preliminary cleanup of `WitnessPat` hoisting/printing

Follow-up to rust-lang#128430.

The eventual goal is to remove `print::Pat` entirely, but in the course of working towards that I made so many small improvements that it seems wise to let those be reviewed/merged on their own first.

Best reviewed commit-by-commit, most of which should be pretty simple and straightforward.

r? ``@Nadrieril``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Aug 11, 2024
Rollup merge of rust-lang#128536 - Zalathar:print-cleanup, r=Nadrieril

Preliminary cleanup of `WitnessPat` hoisting/printing

Follow-up to rust-lang#128430.

The eventual goal is to remove `print::Pat` entirely, but in the course of working towards that I made so many small improvements that it seems wise to let those be reviewed/merged on their own first.

Best reviewed commit-by-commit, most of which should be pretty simple and straightforward.

r? ``@Nadrieril``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants