Rollup merge of #97079 - SparrowLii:successors, r=lcnr

Change `Successors` to `impl Iterator<Item = BasicBlock>`

This PR fixes the FIXME in `compiler\rustc_middle\src\mir\mod.rs`.
This can omit several `&`, `*` or `cloned` operations on Successros' generated elements
This commit is contained in:
Yuki Okushi 2022-05-17 19:01:32 +09:00 committed by GitHub
commit 70cd85f5e3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 54 additions and 55 deletions

View file

@ -701,7 +701,7 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
edge_labels.retain(|label| label != "unreachable");
let edge_counters = from_terminator
.successors()
.map(|&successor_bb| graphviz_data.get_edge_counter(from_bcb, successor_bb));
.map(|successor_bb| graphviz_data.get_edge_counter(from_bcb, successor_bb));
iter::zip(&edge_labels, edge_counters)
.map(|(label, some_counter)| {
if let Some(counter) = some_counter {

View file

@ -484,17 +484,17 @@ fn bcb_filtered_successors<'a, 'tcx>(
body: &'tcx &'a mir::Body<'tcx>,
term_kind: &'tcx TerminatorKind<'tcx>,
) -> Box<dyn Iterator<Item = BasicBlock> + 'a> {
let mut successors = term_kind.successors();
Box::new(
match &term_kind {
// SwitchInt successors are never unwind, and all of them should be traversed.
TerminatorKind::SwitchInt { .. } => successors,
TerminatorKind::SwitchInt { ref targets, .. } => {
None.into_iter().chain(targets.all_targets().into_iter().copied())
}
// For all other kinds, return only the first successor, if any, and ignore unwinds.
// NOTE: `chain(&[])` is required to coerce the `option::iter` (from
// `next().into_iter()`) into the `mir::Successors` aliased type.
_ => successors.next().into_iter().chain(&[]),
_ => term_kind.successors().next().into_iter().chain((&[]).into_iter().copied()),
}
.copied()
.filter(move |&successor| body[successor].terminator().kind != TerminatorKind::Unreachable),
)
}

View file

@ -450,7 +450,7 @@ impl<'tcx> Inliner<'tcx> {
}
if !is_drop {
for &succ in term.successors() {
for succ in term.successors() {
work_list.push(succ);
}
}

View file

@ -65,7 +65,7 @@ impl RemoveNoopLandingPads {
| TerminatorKind::SwitchInt { .. }
| TerminatorKind::FalseEdge { .. }
| TerminatorKind::FalseUnwind { .. } => {
terminator.successors().all(|&succ| nop_landing_pads.contains(succ))
terminator.successors().all(|succ| nop_landing_pads.contains(succ))
}
TerminatorKind::GeneratorDrop
| TerminatorKind::Yield { .. }

View file

@ -81,7 +81,7 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
for (_, data) in traversal::preorder(body) {
if let Some(ref term) = data.terminator {
for &tgt in term.successors() {
for tgt in term.successors() {
pred_count[tgt] += 1;
}
}
@ -235,8 +235,8 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> {
};
let first_succ = {
if let Some(&first_succ) = terminator.successors().next() {
if terminator.successors().all(|s| *s == first_succ) {
if let Some(first_succ) = terminator.successors().next() {
if terminator.successors().all(|s| s == first_succ) {
let count = terminator.successors().count();
self.pred_count[first_succ] -= (count - 1) as u32;
first_succ