Skip to content

Commit

Permalink
Inline finalize_or_candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jul 20, 2024
1 parent 886668c commit 239037e
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1624,7 +1624,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
});
for candidate in candidates_to_expand.iter_mut() {
if !candidate.subcandidates.is_empty() {
self.finalize_or_candidate(candidate);
self.merge_trivial_subcandidates(candidate);
self.remove_never_subcandidates(candidate);
}
}
if let Some(last_candidate) = candidates_to_expand.last_mut() {
Expand All @@ -1635,8 +1636,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

/// Given a match-pair that corresponds to an or-pattern, expand each subpattern into a new
/// subcandidate. Any candidate that has been expanded that way should be passed to
/// `finalize_or_candidate` after its subcandidates have been processed.
/// subcandidate. Any candidate that has been expanded this way should also be postprocessed
/// at the end of [`Self::expand_and_match_or_candidates`].
fn create_or_subcandidates<'pat>(
&mut self,
candidate: &mut Candidate<'pat, 'tcx>,
Expand All @@ -1653,8 +1654,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
candidate.subcandidates[0].false_edge_start_block = candidate.false_edge_start_block;
}

/// Simplify subcandidates and remove `is_never` subcandidates.
/// The candidate should have been expanded with `create_or_subcandidates`.
/// Try to merge all of the subcandidates of the given candidate into one. This avoids
/// exponentially large CFGs in cases like `(1 | 2, 3 | 4, ...)`. The candidate should have been
/// expanded with `create_or_subcandidates`.
///
/// Given a pattern `(P | Q, R | S)` we (in principle) generate a CFG like
/// so:
Expand Down Expand Up @@ -1706,18 +1708,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// |
/// ...
/// ```
fn finalize_or_candidate(&mut self, candidate: &mut Candidate<'_, 'tcx>) {
if candidate.subcandidates.is_empty() {
return;
}

self.merge_trivial_subcandidates(candidate);
self.remove_never_subcandidates(candidate);
}

/// Try to merge all of the subcandidates of the given candidate into one. This avoids
/// exponentially large CFGs in cases like `(1 | 2, 3 | 4, ...)`. The candidate should have been
/// expanded with `create_or_subcandidates`.
///
/// Note that this takes place _after_ the subcandidates have participated
/// in match tree lowering.
Expand Down

0 comments on commit 239037e

Please sign in to comment.