1
Fork 0

Move the loop out of the function

This commit is contained in:
Nadrieril 2024-02-16 04:26:50 +01:00
parent e561dbb0b6
commit 998d0e9793

View file

@ -1207,7 +1207,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
span: Span,
scrutinee_span: Span,
start_block: BasicBlock,
mut start_block: BasicBlock,
otherwise_block: BasicBlock,
candidates: &mut [&mut Candidate<'_, 'tcx>],
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
@ -1219,14 +1219,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
debug!("match_candidates: {:?} candidates fully matched", fully_matched);
let (matched_candidates, unmatched_candidates) = candidates.split_at_mut(fully_matched);
let block = self.select_matched_candidates(matched_candidates, start_block, fake_borrows);
for candidate in matched_candidates.iter_mut() {
start_block = self.select_matched_candidate(candidate, start_block, fake_borrows);
}
// If there are no candidates that still need testing, we're
// done. Since all matches are exhaustive, execution should
// never reach this point.
if unmatched_candidates.is_empty() {
let source_info = self.source_info(span);
self.cfg.goto(block, source_info, otherwise_block);
self.cfg.goto(start_block, source_info, otherwise_block);
return;
}
@ -1235,7 +1237,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span,
scrutinee_span,
unmatched_candidates,
block,
start_block,
otherwise_block,
fake_borrows,
);
@ -1260,20 +1262,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
/// * the [otherwise block] of the third pattern to a block with an
/// [`Unreachable` terminator](TerminatorKind::Unreachable).
///
/// In addition, we add fake edges from the otherwise blocks to the
/// In addition, we later add fake edges from the otherwise blocks to the
/// pre-binding block of the next candidate in the original set of
/// candidates.
///
/// [pre-binding block]: Candidate::pre_binding_block
/// [otherwise block]: Candidate::otherwise_block
fn select_matched_candidates(
fn select_matched_candidate(
&mut self,
matched_candidates: &mut [&mut Candidate<'_, 'tcx>],
candidate: &mut Candidate<'_, 'tcx>,
start_block: BasicBlock,
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
) -> BasicBlock {
let mut next_prebinding = start_block;
for candidate in matched_candidates.iter_mut() {
assert!(candidate.otherwise_block.is_none());
assert!(candidate.pre_binding_block.is_none());
debug_assert!(
@ -1312,15 +1312,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}
}
candidate.pre_binding_block = Some(next_prebinding);
next_prebinding = self.cfg.start_new_block();
candidate.pre_binding_block = Some(start_block);
let otherwise_block = self.cfg.start_new_block();
if candidate.has_guard {
// Create the otherwise block for this candidate, which is the
// pre-binding block for the next candidate.
candidate.otherwise_block = Some(next_prebinding);
candidate.otherwise_block = Some(otherwise_block);
}
}
next_prebinding
otherwise_block
}
/// Tests a candidate where there are only or-patterns left to test, or