-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Expand potential inner Or
pattern for THIR
#98200
Conversation
r? @estebank (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This could use a test, preferably also other negative test(s) that check that this logic is sound as well. |
please squash your commits, r=me |
@@ -453,7 +453,17 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { | |||
/// expands it. | |||
fn push(&mut self, row: PatStack<'p, 'tcx>) { | |||
if !row.is_empty() && row.head().is_or_pat() { | |||
self.patterns.extend(row.expand_or_pat()); | |||
let pats = row.expand_or_pat(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make expand_or_pat
recursively expand or patterns instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't make that one recursive but made a new function that is recursive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either the other use of expand_or_Pat is dead code now or it's still got that issue. Check whether it's dead by panicking inside of it instead of doing any logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can't be dead code because line 835, it's the only reason I couldn't replace the function altogether
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That call may be dead after your change is what I'm thinking. Since you now expand all the nested Or
patterns, line 835 may not encounter Or
patterns anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did as you said, it panicked. Newly added function is only called via fn push
and that is called via line 846.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that we now have one function that does the recursive work and one that doesn't. On what kind of matches did it panic? Should we call the new function at that site to reduce duplication and make it more general?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other function just works like iterator right now, I tried to merge these two functions together but problem is, it's quite tricky because of line 838 if I remove expand_or_pat
altogether and just call expand_and_extend
compiler gives a warning unreachable pattern
even though both of them should do the same thing at this point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that is suspicious indeed and makes me confident that we should definitely make them work the same and figure out why they are problematic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I understand now why the compiler gives "unreachable pattern" err, to reach those places I need to access is_under_guard
for each recursive call, but also push to the matrix has to happen after the call is_useful
to trigger if v.is_empty()
where the matrix has to be empty. Even if I throw all those out of the window I need to call is_useful
for each v
🤷♂️
r? @oli-obk |
Here's a very similar ICE: enum Foo {
A,
B,
C,
}
fn main() {
match Foo::A {
| _foo @ (Foo::A | Foo::B) => {}
// ^ note the trailing `|`
Foo::C => {}
};
} The trailing |
Yeah this PR fixes this, added it as test case, thanks! |
@bors r+ |
Expand potential inner `Or` pattern for THIR Code assumed there wouldn't be a deeper `Or` pattern inside expanded `PatStack` this fixes it by looking for the `Or` pattern inside expanded `PatStack`. A more ideal solution would be recursively doing this but I haven't found a good way to do that. _fixes #97898_
Rollup of 8 pull requests Successful merges: - rust-lang#98200 (Expand potential inner `Or` pattern for THIR) - rust-lang#99770 (Make some const prop mir-opt tests `unit-test`s) - rust-lang#99957 (Rework Ipv6Addr::is_global to check for global reachability rather than global scope - rebase) - rust-lang#100331 (Guarantee `try_reserve` preserves the contents on error) - rust-lang#100336 (Fix two const_trait_impl issues) - rust-lang#100713 (Convert diagnostics in parser/expr to SessionDiagnostic) - rust-lang#100820 (Use pointer `is_aligned*` methods) - rust-lang#100872 (Add guarantee that Vec::default() does not alloc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Code assumed there wouldn't be a deeper
Or
pattern inside expandedPatStack
this fixes it by looking for theOr
pattern inside expandedPatStack
.A more ideal solution would be recursively doing this but I haven't found a good way to do that.
fixes #97898