Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 009beb0

Browse files
committed
Change code to use map insead of for-loop
1 parent b763f90 commit 009beb0

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

compiler/rustc_mir_transform/src/ctfe_limit.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::MirPass;
22

3-
use rustc_middle::mir::{BasicBlockData, Body, Statement, StatementKind, TerminatorKind};
3+
use rustc_middle::mir::{
4+
BasicBlock, BasicBlockData, Body, Statement, StatementKind, TerminatorKind,
5+
};
46
use rustc_middle::ty::TyCtxt;
57

68
pub struct CtfeLimit;
@@ -9,28 +11,28 @@ impl<'tcx> MirPass<'tcx> for CtfeLimit {
911
#[instrument(skip(self, _tcx, body))]
1012
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
1113
let doms = body.basic_blocks.dominators();
12-
let mut indices = Vec::new();
13-
for (node, node_data) in body.basic_blocks.iter_enumerated() {
14-
if let TerminatorKind::Call { .. } = node_data.terminator().kind {
15-
indices.push(node);
16-
continue;
17-
}
18-
// Back edges in a CFG indicate loops
19-
for (potential_dom, _) in body.basic_blocks.iter_enumerated() {
20-
if doms.is_reachable(potential_dom)
21-
&& doms.is_reachable(node)
22-
&& doms.is_dominated_by(node, potential_dom)
23-
&& node_data
24-
.terminator()
25-
.successors()
26-
.into_iter()
27-
.any(|succ| succ == potential_dom)
28-
{
29-
indices.push(node);
30-
continue;
31-
}
32-
}
33-
}
14+
let indices: Vec<BasicBlock> =
15+
body.basic_blocks
16+
.iter_enumerated()
17+
.filter_map(|(node, node_data)| {
18+
if matches!(node_data.terminator().kind, TerminatorKind::Call { .. }) ||
19+
// Back edges in a CFG indicate loops
20+
body.basic_blocks.iter_enumerated().any(|(potential_dom, _)| {
21+
doms.is_reachable(potential_dom)
22+
&& doms.is_reachable(node)
23+
&& doms.is_dominated_by(node, potential_dom)
24+
&& node_data
25+
.terminator()
26+
.successors()
27+
.into_iter()
28+
.any(|succ| succ == potential_dom)
29+
}) {
30+
Some(node)
31+
} else {
32+
None
33+
}
34+
})
35+
.collect();
3436
for index in indices {
3537
insert_counter(
3638
body.basic_blocks_mut()

0 commit comments

Comments
 (0)