about summary refs log tree commit diff
path: root/compiler/rustc_pattern_analysis
AgeCommit message (Collapse)AuthorLines
2024-01-07Remove incorrect `assert`Nadrieril-6/+0
It's incorrect because `CtorSet::split` returns a non-present constructor into `present` in one specific case: variable-length slices of an empty type. That's because empty constructors of arity 0 break the algorithm. This is a tricky corner case that's hard to do cleanly. The assert wasn't adding much anyway.
2024-01-07Factor out pushing onto `PatternColumn`Nadrieril-12/+12
2024-01-06Reuse `ctor_sub_tys` when we have one aroundNadrieril-6/+11
2024-01-06Remove `Matrix.wildcard_row`Nadrieril-18/+24
It was only used to track types and relevancy, so may as well store that directly.
2024-01-06Auto merge of #119329 - Nadrieril:reveal-opaques-early, r=compiler-errorsbors-90/+128
Exhaustiveness: Statically enforce revealing of opaques In https://github.com/rust-lang/rust/pull/116821 it was decided that exhaustiveness should operate on the hidden type of an opaque type when relevant. This PR makes sure we consistently reveal opaques within exhaustiveness. This makes it possible to remove `reveal_opaque_ty` from the `TypeCx` trait which was an unfortunate implementation detail. r? `@compiler-errors`
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-1/+1
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2024-01-01Statically enforce revealing of opaquesNadrieril-90/+128
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-1/+1
2023-12-26Keep reference to the original `Pat` in `DeconstructedPat`Nadrieril-5/+5
2023-12-26Rollup merge of #119307 - compiler-errors:pat-lifetimes, r=NadrierilMichael Goulet-69/+61
Clean up some lifetimes in `rustc_pattern_analysis` This PR removes some redundant lifetimes. I figured out that we were shortening the lifetime of an arena-allocated `&'p DeconstructedPat<'p>` to `'a DeconstructedPat<'p>`, which forced us to carry both lifetimes when we could otherwise carry just one. This PR also removes and elides some unnecessary lifetimes. I also cherry-picked 0292eb9bb9b897f5c0926c6a8530877f67e7cc9b, and then simplified more lifetimes in `MatchVisitor`, which should make #119233 a very simple PR! r? Nadrieril
2023-12-26Merge 'thir and 'pMichael Goulet-1/+1
2023-12-26Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, ↵bors-1/+1
r=compiler-errors Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
2023-12-26Elide more lifetimesMichael Goulet-12/+12
2023-12-26Clean up more lifetimesMichael Goulet-15/+10
2023-12-26Even moreMichael Goulet-13/+10
2023-12-26Yeet some lifetimesMichael Goulet-40/+40
2023-12-24Auto merge of #118796 - Nadrieril:fix-exponential-id-match-2, r=cjgillotbors-29/+205
Exhaustiveness: Improve complexity on some wide matches https://github.com/rust-lang/rust/issues/118437 revealed an exponential case in exhaustiveness checking. While [exponential cases are unavoidable](https://compilercrim.es/rust-np/), this one only showed up after my https://github.com/rust-lang/rust/pull/117611 rewrite of the algorithm. I remember anticipating a case like this and dismissing it as unrealistic, but here we are :'). The tricky match is as follows: ```rust match command { BaseCommand { field01: true, .. } => {} BaseCommand { field02: true, .. } => {} BaseCommand { field03: true, .. } => {} BaseCommand { field04: true, .. } => {} BaseCommand { field05: true, .. } => {} BaseCommand { field06: true, .. } => {} BaseCommand { field07: true, .. } => {} BaseCommand { field08: true, .. } => {} BaseCommand { field09: true, .. } => {} BaseCommand { field10: true, .. } => {} // ...20 more of the same _ => {} } ``` To fix this, this PR formalizes a concept of "relevancy" (naming is hard) that was already used to decide what patterns to report. Now we track it for every row, which in wide matches like the above can drastically cut on the number of cases we explore. After this fix, the above match is checked with linear-many cases instead of exponentially-many. Fixes https://github.com/rust-lang/rust/issues/118437 r? `@cjgillot`
2023-12-23Rework the explanation of relevancyNadrieril-48/+138
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-1/+1
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Reveal empty opaques in depthNadrieril-4/+14
2023-12-23Improve performance on wide matchesNadrieril-29/+115
2023-12-23Clarify the situation with dummy patterns and `PatData`Nadrieril-17/+19
Use an explicit `Option` instead of requiring a `Default` bound
2023-12-23Use `derivative` for better derive boundsNadrieril-21/+20
2023-12-20Reveal opaque types in exhaustiveness checkingNadrieril-33/+33
2023-12-19Auto merge of #118842 - Nadrieril:librarify-further, r=compiler-errorsbors-431/+641
Make exhaustiveness usable outside of rustc With this PR, `rustc_pattern_analysis` compiles on stable (with the `stable` feature)! `rust-analyzer` will be able to use it to provide match-related diagnostics and refactors. Two questions: - Should I name the feature `nightly` instead of `rustc` for consistency with other crates? `rustc` makes more sense imo. - `typed-arena` is an optional dependency but tidy made me add it to the allow-list anyway. Can I avoid that somehow? r? `@compiler-errors`
2023-12-15NFC: do not clone types that are copyMatthias Krüger-1/+1
2023-12-15s/MatchCx/TypeCx/Nadrieril-48/+48
2023-12-15Introduce `MatchCtxt`Nadrieril-77/+93
2023-12-15s/PatCtxt/PlaceCtxt/Nadrieril-33/+33
2023-12-15`pattern_analysis` doesn't need to know what spans areNadrieril-28/+31
2023-12-15Address review commentsNadrieril-12/+4
2023-12-15s/RustcCtxt/RustcMatchCheckCtxt/Nadrieril-34/+44
2023-12-15Make the crate compile on stableNadrieril-3/+17
2023-12-15Make the `rustc_data_structures` dependency optionalNadrieril-13/+28
2023-12-15Gate rustc-specific code under a featureNadrieril-16/+41
2023-12-15Iron out last rustc-specific detailsNadrieril-14/+38
2023-12-15Name rustc-specific things "rustc"Nadrieril-43/+36
2023-12-15Abstract `MatchCheckCtxt` into a traitNadrieril-218/+294
2023-12-15Disentangle the arena from `MatchCheckCtxt`Nadrieril-116/+135
2023-12-15Remove all matching on `ty.kind()` outside `cx`Nadrieril-36/+31
2023-12-15Split `Single` ctor into more specific variantsNadrieril-51/+79
2023-12-12Update compiler/rustc_pattern_analysis/src/constructor.rs Matthias Krüger-0/+1
add note that `missing_empty` is cleared now Co-authored-by: Nadrieril <Nadrieril@users.noreply.github.com>
2023-12-12simplify merging of two vecsMatthias Krüger-1/+1
2023-12-11Fix doc linksNadrieril-22/+22
2023-12-11Fix item visibilitiesNadrieril-31/+27
2023-12-11Make `MaybeInfiniteInt` rustc-independentNadrieril-34/+59
2023-12-11Move lints to their own moduleNadrieril-297/+343
2023-12-11Gather rustc-specific functions around `MatchCheckCtxt`Nadrieril-889/+891
2023-12-11Extract exhaustiveness into its own crateNadrieril-0/+3780