1
Fork 0

Rollup merge of #121706 - Nadrieril:simplify-sort-candidate, r=matthewjasper

match lowering: Remove hacky branch in sort_candidate

Reusing `self.test()` there wasn't actually pulling a lot of weight. In particular the `TestKind::Len` cases were all already correctly handled.

r? `@matthewjasper`
This commit is contained in:
Matthias Krüger 2024-03-01 22:38:48 +01:00 committed by GitHub
commit 1fbc53af48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -583,10 +583,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fully_matched = true; fully_matched = true;
Some(variant_index.as_usize()) Some(variant_index.as_usize())
} }
(&TestKind::Switch { .. }, _) => {
fully_matched = false;
None
}
// If we are performing a switch over integers, then this informs integer // If we are performing a switch over integers, then this informs integer
// equality, but nothing else. // equality, but nothing else.
@ -611,10 +607,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
options.len() options.len()
}) })
} }
(&TestKind::SwitchInt { .. }, _) => {
fully_matched = false;
None
}
( (
&TestKind::Len { len: test_len, op: BinOp::Eq }, &TestKind::Len { len: test_len, op: BinOp::Eq },
@ -703,34 +695,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
None None
} }
} }
(&TestKind::Range { .. }, _) => {
fully_matched = false; // FIXME(#29623): return `Some(1)` when the values are different.
None (TestKind::Eq { value: test_val, .. }, TestCase::Constant { value: case_val })
if test_val == case_val =>
{
fully_matched = true;
Some(0)
} }
(&TestKind::Eq { .. } | &TestKind::Len { .. }, _) => { (
// The call to `self.test(&match_pair)` below is not actually used to generate any TestKind::Switch { .. }
// MIR. Instead, we just want to compare with `test` (the parameter of the method) | TestKind::SwitchInt { .. }
// to see if it is the same. | TestKind::Len { .. }
// | TestKind::Range { .. }
// However, at this point we can still encounter or-patterns that were extracted | TestKind::Eq { .. },
// 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 { fully_matched = false;
return None; 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
}
} }
}; };