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

match lowering: Remove hacky branch in sort_candidate #121706

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove hacky branch in sort_candidate
Reusing `self.test` wasn't actually pulling a lot of weight.
Nadrieril committed Feb 27, 2024
commit 5e11a99bb662629cc7d0ad3ce7475b7738c9c2cb
37 changes: 14 additions & 23 deletions compiler/rustc_mir_build/src/build/matches/test.rs
Original file line number Diff line number Diff line change
@@ -673,6 +673,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
}
(TestKind::Len { .. }, _) => {
fully_matched = false;
None
}

(TestKind::Range(test), &TestCase::Range(pat)) => {
if test.as_ref() == pat {
@@ -700,29 +704,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
None
}

(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => {
// The call to `self.test(&match_pair)` below is not actually used to generate any
// MIR. Instead, we just want to compare with `test` (the parameter of the method)
// to see if it is the same.
//
// However, at this point we can still encounter or-patterns that were extracted
// from previous calls to `sort_candidate`, so we need to manually address that
// case to avoid panicking in `self.test()`.
if let TestCase::Or { .. } = &match_pair.test_case {
return None;
}

// These are all binary tests.
//
// FIXME(#29623) we can be more clever here
let pattern_test = self.test(match_pair);
if pattern_test.kind == test.kind {
fully_matched = true;
Some(0)
} else {
fully_matched = false;
None
}
// FIXME(#29623): return `Some(1)` when the values are different.
(TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
if test_val == case_val =>
{
fully_matched = true;
Some(0)
}
(TestKind::Eq { .. }, _) => {
fully_matched = false;
None
}
};