summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis
AgeCommit message (Collapse)AuthorLines
2024-09-29cleanup: don't clone types that are CopyMatthias Krüger-4/+4
2024-09-28remove couple redundant clonesMatthias Krüger-1/+1
2024-09-23Rollup merge of #130715 - compiler-errors:mir-build-const-eval, r=BoxyUwUMatthias Krüger-4/+7
Replace calls to `ty::Const::{try_}eval` in mir build/pattern analysis We normalize consts in writeback: #130645. This means that consts are gonna be as normalized as they're ever gonna get in MIR building and pattern analysis. Therefore we can just use `try_to_target_usize` rather than calling `eval_target_usize`. Regarding the `.expect` calls, I'm not totally certain whether they're correct given rigid unevaluated consts. But this PR shouldn't make *more* ICEs occur; we may have to squash these ICEs when mGCE comes around, tho 😺
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-14/+14
2024-09-22Replace calls to Const::eval in mir buildMichael Goulet-4/+7
2024-09-11Revert warning empty patterns as unreachableNadrieril-1/+5
2024-09-03Rollup merge of #128934 - Nadrieril:fix-empty-non-exhaustive, r=compiler-errorsMatthias Krüger-7/+1
Non-exhaustive structs may be empty This is a follow-up to a discrepancy noticed in https://github.com/rust-lang/rust/pull/122792: today, the following struct is considered inhabited (non-empty) outside its defining crate: ```rust #[non_exhaustive] pub struct UninhabitedStruct { pub never: !, // other fields } ``` `#[non_exhaustive]` on a struct should mean that adding fields to it isn't a breaking change. There is no way that adding fields to this struct could make it non-empty since the `never` field must stay and is inconstructible. I suspect this was implemented this way due to confusion with `#[non_exhaustive]` enums, which indeed should be considered non-empty outside their defining crate. I propose that we consider such a struct uninhabited (empty), just like it would be without the `#[non_exhaustive]` annotation. Code that doesn't pass today and will pass after this: ```rust // In a different crate fn empty_match_on_empty_struct<T>(x: UninhabitedStruct) -> T { match x {} } ``` This is not a breaking change. r? ``@compiler-errors``
2024-09-02Non-exhaustive structs may be emptyNadrieril-7/+1
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-2/+2
2024-08-29Add `warn(unreachable_pub)` to `rustc_pattern_analysis`.Nicholas Nethercote-0/+1
2024-08-15Rollup merge of #128965 - Zalathar:no-pat, r=NadrierilJubilee-112/+60
Remove `print::Pat` from the printing of `WitnessPat` After the preliminary work done in #128536, we can now get rid of `print::Pat` entirely. - First, we introduce a variant `PatKind::Print(String)`. - Then we incrementally remove each other variant of `PatKind`, by having the relevant code produce `PatKind::Print` instead. - Once `PatKind::Print` is the only remaining variant, it becomes easy to remove `print::Pat` and replace it with `String`. There is more cleanup that I have in mind, but this seemed like a natural stopping point for one PR. r? ```@Nadrieril```
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-1/+1
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-11Remove `print::Pat` entirely, replacing it with `String`Zalathar-69/+35
2024-08-11Remove `PatKind::Never`Zalathar-4/+1
2024-08-11Remove `PatKind::Slice`Zalathar-17/+8
2024-08-11Remove `PatKind::Range`Zalathar-5/+1
2024-08-11Remove `PatKind::Constant`Zalathar-9/+4
2024-08-11Remove `PatKind::Ref`Zalathar-7/+7
2024-08-11Remove `PatKind::Box`Zalathar-6/+1
2024-08-11Remove `PatKind::StructLike`Zalathar-10/+11
2024-08-11Remove `PatKind::Wild`Zalathar-5/+4
2024-08-11Add `print::PatKind::Print`Zalathar-0/+3
This will allow for the gradual removal of all other variants.
2024-08-11Avoid matching on `PatKind::Wild` in `write_struct_like`Zalathar-5/+10
2024-08-11Rollup merge of #128536 - Zalathar:print-cleanup, r=NadrierilMatthias Krüger-185/+216
Preliminary cleanup of `WitnessPat` hoisting/printing Follow-up to #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``
2024-08-10Stabilize `min_exhaustive_patterns`Nadrieril-23/+8
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-1/+1
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-07Use `TyCtxt::is_diagnostic_item`Zalathar-2/+2
2024-08-07Avoid using `ty::tls::with` in `write_struct_like`Zalathar-5/+6
2024-08-07Simplify hoisting of ref patterns (`&` and `&mut`)Zalathar-6/+1
2024-08-07Simplify hoisting of array/slice patternsZalathar-30/+44
We can replace some tricky iterator-mutation code with a much simpler version that uses `while let` to shrink a slice. We also check whether a subpattern would be a wildcard _before_ hoisting it, which will be very useful when trying to get rid of `print::PatKind` later.
2024-08-07Simplify hoisting of struct-like patternsZalathar-23/+16
2024-08-07Split out hoisting/printing of `box` patternsZalathar-7/+10
2024-08-07Split out a `hoist` helper in `hoist_witness_pat`Zalathar-1/+2
2024-08-07Replace an unnecessary slice pattern with `has_dot_dot: bool`Zalathar-14/+10
2024-08-07Remove an impossible case under `EnumInfo::NotEnum`Zalathar-7/+1
2024-08-07Unify `Variant` and `Leaf` into `print::PatKind::StructLike`Zalathar-20/+25
2024-08-07Break up `print::Pat` printing into several helper functionsZalathar-113/+142
2024-07-31Use a separate pattern type for `rustc_pattern_analysis` diagnosticsZalathar-11/+208
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.
2024-07-31Print `thir::PatRange`, not its surrounding `thir::Pat`Zalathar-8/+7
This further reduces the amount of code that relies on `thir::Pat` being printable.
2024-07-29Rollup merge of #128304 - Zalathar:thir-pat-display, r=NadrierilMatthias Krüger-39/+40
Isolate the diagnostic code that expects `thir::Pat` to be printable Currently, `thir::Pat` implements `fmt::Display` (and `IntoDiagArg`) directly, for use by a few diagnostics. That makes it tricky to experiment with alternate representations for THIR patterns, because the patterns currently need to be printable on their own. That immediately rules out possibilities like storing subpatterns as a `PatId` index into a central list (instead of the current directly-owned `Box<Pat>`). This PR therefore takes an incremental step away from that obstacle, by removing `thir::Pat` from diagnostic structs in `rustc_pattern_analysis`, and hiding the pattern-printing process behind a single public `Pat::to_string` method. Doing so makes it easier to identify and update the code that wants to print patterns, and gives a place to pass in additional context in the future if necessary. --- I'm currently not sure whether switching over to `PatId` is actually desirable or not, but I think this change makes sense on its own merits, by reducing the coupling between `thir::Pat` and the pattern-analysis error types.
2024-07-29Encapsulate the printing of `WitnessPat`Zalathar-12/+14
This hides the fact that we print `WitnessPat` by converting it to `thir::Pat` and then printing that.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-30/+28
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Don't store `thir::Pat` in error structsZalathar-32/+31
In several cases this avoids the need to clone the underlying pattern, and then print the clone later.
2024-07-24Explain why a given pattern is considered unreachableNadrieril-49/+163
2024-07-24Add some testsNadrieril-4/+74
2024-07-24Move rustc-specific entrypoint to the `rustc` moduleNadrieril-34/+29
2024-07-23Auto merge of #128015 - Nadrieril:two-step-or-expansion, r=compiler-errorsbors-107/+86
match exhaustiveness: Expand or-patterns as a separate step To compute exhaustiveness, we must expand or-patterns. Previously, we expanded them at the same time that we pushed patterns into the matrix. This made it harder to track pattern reachability, because the or-pattern itself would never show up in the matrix so we had to recover missing information. This PR changes that: we no longer expand or-patterns as we push them into the matrix. Instead, if we find an or-pattern in the matrix we expand them in a step very much like the specialization we already do. This simplifies a bunch of things, and should greatly simplify the implementation of https://github.com/rust-lang/rust/issues/127870. r? `@compiler-errors`
2024-07-21Tweak `collect_non_exhaustive_tys`Nadrieril-1/+7
2024-07-20Expand or-patterns as a separate stepNadrieril-107/+86
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-1/+1
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.