Commit Graph

186 Commits

Author SHA1 Message Date
Nadrieril
2a541cea35 Completely rework the explanation of the algorithm 2020-12-22 15:20:23 +00:00
Nadrieril
43d445c8d1 Pass Matrix explicitly instead of via PatCtxt 2020-12-22 15:20:23 +00:00
Nadrieril
8b38b6859a Inline the constructor-specific split functions 2020-12-22 15:20:23 +00:00
Nadrieril
3141f2d78c Inline all_constructors 2020-12-22 15:20:23 +00:00
Nadrieril
bbb4ac0651 Rebrand MissingConstructors as SplitWildcard 2020-12-22 15:20:23 +00:00
Nadrieril
9d0c2ed913 Factor out SplitVarLenSlice used for slice splitting 2020-12-22 15:20:23 +00:00
Nadrieril
7948f91910 Run the annoying lint separately 2020-12-22 15:20:23 +00:00
Nadrieril
5a24b2c2c7 Factor out SplitIntRange used for integer range splitting 2020-12-22 15:20:23 +00:00
bors
75e1acb63a Auto merge of #78242 - Nadrieril:rename-overlapping_endpoints-lint, r=varkor
Rename `overlapping_patterns` lint

As discussed in https://github.com/rust-lang/rust/issues/65477. I also tweaked a few things along the way.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-12-22 10:32:03 +00:00
bors
1f5bc176b0 Auto merge of #80104 - Nadrieril:usefulness-merging, r=varkor
Improve and fix diagnostics of exhaustiveness checking

Primarily, this fixes https://github.com/rust-lang/rust/issues/56379. This also fixes incorrect interactions between or-patterns and slice patterns that I discovered while working on #56379. Those two examples show the incorrect diagnostics:

```rust
match &[][..] {
    [true] => {}
    [true // detected as unreachable but that's not true
        | false, ..] => {}
    _ => {}
}
match (true, None) {
    (true, Some(_)) => {}
    (false, Some(true)) => {}
    (true | false, None | Some(true // should be detected as unreachable
                               | false)) => {}
}
```

I did not measure any perf impact. However, I suspect that [`616ba9f`](616ba9f9f7) should have a negative impact on large or-patterns. I'll see what the perf run says; I have optimization ideas up my sleeve if needed.

EDIT: I initially had a noticeable perf impact that I thought unavoidable. I then proceeded to avoid it x)

r? `@varkor`
`@rustbot` label +A-exhaustiveness-checking
2020-12-19 19:14:04 +00:00
Nadrieril
5b6c175566 Tweak diagnostics 2020-12-19 17:48:31 +00:00
Nadrieril
cefcadbe92 Unify the two kinds of usefulness merging
This is elegant but a bit of a perf gamble. That said, or-patterns
rarely have many branches and it's easy to optimize or revert if we ever
need to. In the meantime simpler code is worth it.
2020-12-18 16:21:39 +00:00
Nadrieril
6319d737e0 Merge unreachable subpatterns correctly 2020-12-18 16:21:39 +00:00
Nadrieril
2d71a0b9b9 Keep all witnesses of non-exhaustiveness 2020-12-18 16:21:38 +00:00
Nadrieril
d7a6365b77 Rewrite usefulness merging using SpanSet
`SpanSet` is heavily inspired from `DefIdForest`.
2020-12-18 16:21:38 +00:00
Nadrieril
170fae2c18 Log the output of is_useful in the or-pattern case too 2020-12-18 16:21:38 +00:00
Nadrieril
7009d20290 Factor out or-pattern usefulness merging 2020-12-18 16:21:38 +00:00
Yuki Okushi
1e1ba7c936
Rollup merge of #79051 - LeSeulArtichaut:if-let-guard, r=matthewjasper
Implement if-let match guards

Implements rust-lang/rfcs#2294 (tracking issue: #51114).

I probably should do a few more things before this can be merged:
- [x] Add tests (added basic tests, more advanced tests could be done in the future?)
- [x] Add lint for exhaustive if-let guard (comparable to normal if-let statements)
- [x] Fix clippy

However since this is a nightly feature maybe it's fine to land this and do those steps in follow-up PRs.

Thanks a lot `@matthewjasper` ❤️ for helping me with lowering to MIR! Would you be interested in reviewing this?
r? `@ghost` for now
2020-12-17 11:43:55 +09:00
bors
e99a89c7c0 Auto merge of #73210 - wesleywiser:consts_in_debuginfo, r=oli-obk
[mir-opt] Allow debuginfo to be generated for a constant or a Place

Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-15 08:46:00 +00:00
Yuki Okushi
1b81f08d4c
Rollup merge of #79940 - matthiaskrgr:cl15ppy, r=Dylan-DPC
fix more clippy::complexity findings

fix clippy::unnecessary_filter_map
use if let Some(x) = ..  instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn)
fix clippy::{needless_bool, manual_unwrap_or}
don't clone types that are copy (clippy::clone_on_copy)
don't convert types into identical types with .into() (clippy::useless_conversion)
use strip_prefix over slicing (clippy::manual_strip)

r? ``@Dylan-DPC``
2020-12-13 11:05:36 +09:00
bors
5bd9b60333 Auto merge of #79553 - sexxi-goose:mir_min_cap_writeback, r=nikomatsakis
Capture precise paths in THIR and MIR

This PR allows THIR and MIR to use the result of the new capture analysis to actually capture precise paths

To achieve we:
- Writeback min capture results to TypeckResults
- Move handling upvars to PlaceBuilder in mir_build
- Lower precise paths in THIR build by reading min_captures
- Search for ancestors in min_capture when trying to build a MIR place which starts off of an upvar

Closes: https://github.com/rust-lang/project-rfc-2229/issues/10

Partly implements: rust-lang/project-rfc-2229#18

Work that remains (not in this PR):
- [ ] [Known bugs when feature gate is enabled](https://github.com/rust-lang/project-rfc-2229/projects/1?card_filter_query=label%3Abug)
- [ ] Use min_capure_map for
  - [ ] Liveness analysis
  - [ ] rustc_mir/interpret/validity.rs
  - [ ] regionck
- [ ] rust-lang/project-rfc-2229#8
- [ ] remove closure_captures and upvar_capture_map

r? `@ghost`
2020-12-12 00:23:29 +00:00
Matthias Krüger
5833f74a9c use if let Some(x) = .. instead of ...map(|x|) to conditionally run fns that return () (clippy::option_map_unit_fn) 2020-12-11 23:02:19 +01:00
Aman Arora
e2efdd156b Use precise places when lowering Closures in THIR
- Closures now use closure_min_captures to figure out captured paths
- Build upvar_mutbls using closure_min_captures
- Change logic in limit_capture_mutability to differentiate b/w
  capturing parent's local variable or capturing a variable that is
  captured by the parent (in case of nested closure) using PlaceBase.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:34:15 -05:00
Aman Arora
6a1d0699a4 Use Places for captures in MIR
- Use closure_min_capture maps to capture precise paths
- PlaceBuilder now searches for ancestors in min_capture list
- Add API to `Ty` to allow access to the n-th element in a
  tuple in O(1) time.

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-09 22:33:33 -05:00
oli
84fe7cf24e Also generate StorageDead in constants 2020-12-09 10:59:10 +00:00
Wesley Wiser
01aec8d185 [mir-opt] Allow debuginfo to be generated for a constant or a Place
Prior to this commit, debuginfo was always generated by mapping a name
to a Place. This has the side-effect that `SimplifyLocals` cannot remove
locals that are only used for debuginfo because their other uses have
been const-propagated.

To allow these locals to be removed, we now allow debuginfo to point to
a constant value. The `ConstProp` pass detects when debuginfo points to
a local with a known constant value and replaces it with the value. This
allows the later `SimplifyLocals` pass to remove the local.
2020-12-06 20:48:25 -05:00
Aman Arora
d9523622ff Move handling UpvarRef to PlaceBuilder
- This allows us to delay figuring out the index of a capture
  in the closure structure when all projections to atleast form
  a capture have been applied to the builder

Co-authored-by: Roxane Fruytier <roxane.fruytier@hotmail.com>
2020-12-06 18:30:23 -05:00
Tomasz Miąsko
91fe548825 Retain assembly operands span when lowering AST to HIR 2020-12-06 20:48:08 +01:00
LeSeulArtichaut
f3d4aa6afb Implement lowering of if-let guards to MIR 2020-12-06 13:42:24 +01:00
LeSeulArtichaut
bab20800f0 Introduce if-let guards in the THIR 2020-12-06 11:48:08 +01:00
Matthew Jasper
4fef39113a Avoid leaking block expression values 2020-12-04 23:07:46 +00:00
Matthew Jasper
7f3e8551dd Use record_operands_moved more aggresively 2020-12-04 22:22:52 +00:00
Matthew Jasper
b766abc88f Simplify unscheduling of drops after moves 2020-12-04 22:19:28 +00:00
Nadrieril
793c40e0bd Inline is_covered_by 2020-12-04 01:45:34 +00:00
Nadrieril
94ad5e1672 Improve error message 2020-11-29 21:29:19 +00:00
Nadrieril
c89d439bb5 Be consistent about linting singletons 2020-11-29 21:29:19 +00:00
Nadrieril
d1a50ffb7c Rename the overlapping_patterns lint to overlapping_range_endpoints 2020-11-29 21:29:19 +00:00
Nadrieril
bdd2bdb53b Don't store ty and span in IntRange
We prefer to grab `ty` and `span` from `pcx`. This makes it consistent
with other constructors.
2020-11-28 22:07:15 +00:00
Nadrieril
d8983655c1 Correctly detect usize/isize range overlaps 2020-11-28 21:23:38 +00:00
Nadrieril
941c6ac1a2 Rename _match to usefulness 2020-11-27 18:43:28 +00:00
Nadrieril
2de0475826 Rename pat_constructor to Constructor::from_pat 2020-11-27 18:22:19 +00:00
Nadrieril
ba3c419a43 Move the definitions of the two Ctxts to the top 2020-11-27 18:22:19 +00:00
Nadrieril
2184a1444c Extract everything related to pattern deconstruction to a new module 2020-11-27 18:22:17 +00:00
Nadrieril
3715f1ed00 No need to expose Matrix internals 2020-11-27 18:20:30 +00:00
Nadrieril
d447bdff9b Disentangle Fields and PatStack 2020-11-27 18:20:30 +00:00
Nadrieril
b59792128c Move Constructor::apply to Fields 2020-11-27 18:20:30 +00:00
Jonas Schievink
815d96111d
Rollup merge of #79421 - camelid:_match-docs-fmt, r=petrochenkov
Fix docs formatting for `thir::pattern::_match`

They were being rendered all on one line.
2020-11-26 13:39:18 +01:00
Camelid
c5c70d4017 Fix docs formatting for thir::pattern::_match
A list was being rendered all on one line and there were other
formatting issues as well.
2020-11-25 13:23:06 -08:00
Camelid
82dc99ba7a Use the name "auto traits" everywhere in the compiler
Goodbye, OIBIT!
2020-11-24 16:25:43 -08:00
bors
c643dd2ec8 Auto merge of #79243 - Nadrieril:consolidate-tests, r=varkor
Consolidate exhaustiveness-related tests

I hunted for tests that only exercised the match exhaustiveness algorithm and regrouped them. I also improved integer-range tests since I had found them lacking while hacking around.
The interest is mainly so that one can pass `--test-args patterns` and catch most relevant tests.

r? `@varkor`
`@rustbot` modify labels: +A-exhaustiveness-checking
2020-11-22 18:29:38 +00:00