Skip to content

Commit f1614c5

Browse files
committed
Avoid recursion in creating and merging or-patterns
By calling back into `match_candidates`, we only need to expand one layer at a time. Conversely, since we always try to simplify a layer that we just expanded, we only have to merge one layer at a time.
1 parent 4f45632 commit f1614c5

File tree

2 files changed

+3
-21
lines changed

2 files changed

+3
-21
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13091309
for candidate in candidates.iter_mut() {
13101310
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
13111311
}
1312-
self.match_simplified_candidates(
1312+
self.match_candidates(
13131313
span,
13141314
scrutinee_span,
13151315
start_block,
@@ -1566,11 +1566,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15661566
}
15671567

15681568
let mut can_merge = true;
1569-
1570-
// Not `Iterator::all` because we don't want to short-circuit.
15711569
for subcandidate in &mut candidate.subcandidates {
1572-
self.merge_trivial_subcandidates(subcandidate);
1573-
15741570
// FIXME(or_patterns; matthewjasper) Try to be more aggressive here.
15751571
can_merge &=
15761572
subcandidate.subcandidates.is_empty() && subcandidate.extra_data.is_empty();

compiler/rustc_mir_build/src/build/matches/simplify.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -80,26 +80,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8080
debug!(simplified = ?match_pairs, "simplify_match_pairs");
8181
}
8282

83-
/// Create a new candidate for each pattern in `pats`, and recursively simplify tje
84-
/// single-or-pattern case.
83+
/// Create a new candidate for each pattern in `pats`.
8584
pub(super) fn create_or_subcandidates<'pat>(
8685
&mut self,
8786
pats: &[FlatPat<'pat, 'tcx>],
8887
has_guard: bool,
8988
) -> Vec<Candidate<'pat, 'tcx>> {
90-
pats.iter()
91-
.cloned()
92-
.map(|flat_pat| {
93-
let mut candidate = Candidate::from_flat_pat(flat_pat, has_guard);
94-
if let [MatchPair { test_case: TestCase::Or { pats, .. }, .. }] =
95-
&*candidate.match_pairs
96-
{
97-
candidate.subcandidates = self.create_or_subcandidates(pats, has_guard);
98-
let first_match_pair = candidate.match_pairs.pop().unwrap();
99-
candidate.or_span = Some(first_match_pair.pattern.span);
100-
}
101-
candidate
102-
})
103-
.collect()
89+
pats.iter().cloned().map(|flat_pat| Candidate::from_flat_pat(flat_pat, has_guard)).collect()
10490
}
10591
}

0 commit comments

Comments
 (0)