summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_mir_transform/src/coverage/graph.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /compiler/rustc_mir_transform/src/coverage/graph.rs
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/graph.rs')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/graph.rs56
1 files changed, 27 insertions, 29 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs
index a2671eef2..7391a77b0 100644
--- a/compiler/rustc_mir_transform/src/coverage/graph.rs
+++ b/compiler/rustc_mir_transform/src/coverage/graph.rs
@@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::dominators::{self, Dominators};
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
use rustc_index::bit_set::BitSet;
-use rustc_index::vec::IndexVec;
+use rustc_index::vec::{IndexSlice, IndexVec};
use rustc_middle::mir::coverage::*;
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
@@ -37,8 +37,7 @@ impl CoverageGraph {
// `SwitchInt` to have multiple targets to the same destination `BasicBlock`, so
// de-duplication is required. This is done without reordering the successors.
- let bcbs_len = bcbs.len();
- let mut seen = IndexVec::from_elem_n(false, bcbs_len);
+ let mut seen = IndexVec::from_elem(false, &bcbs);
let successors = IndexVec::from_fn_n(
|bcb| {
for b in seen.iter_mut() {
@@ -60,7 +59,7 @@ impl CoverageGraph {
bcbs.len(),
);
- let mut predecessors = IndexVec::from_elem_n(Vec::new(), bcbs.len());
+ let mut predecessors = IndexVec::from_elem(Vec::new(), &bcbs);
for (bcb, bcb_successors) in successors.iter_enumerated() {
for &successor in bcb_successors {
predecessors[successor].push(bcb);
@@ -123,7 +122,7 @@ impl CoverageGraph {
match term.kind {
TerminatorKind::Return { .. }
- | TerminatorKind::Abort
+ | TerminatorKind::Terminate
| TerminatorKind::Yield { .. }
| TerminatorKind::SwitchInt { .. } => {
// The `bb` has more than one _outgoing_ edge, or exits the function. Save the
@@ -137,7 +136,7 @@ impl CoverageGraph {
debug!(" because term.kind = {:?}", term.kind);
// Note that this condition is based on `TerminatorKind`, even though it
// theoretically boils down to `successors().len() != 1`; that is, either zero
- // (e.g., `Return`, `Abort`) or multiple successors (e.g., `SwitchInt`), but
+ // (e.g., `Return`, `Terminate`) or multiple successors (e.g., `SwitchInt`), but
// since the BCB CFG ignores things like unwind branches (which exist in the
// `Terminator`s `successors()` list) checking the number of successors won't
// work.
@@ -156,7 +155,6 @@ impl CoverageGraph {
| TerminatorKind::Resume
| TerminatorKind::Unreachable
| TerminatorKind::Drop { .. }
- | TerminatorKind::DropAndReplace { .. }
| TerminatorKind::Call { .. }
| TerminatorKind::GeneratorDrop
| TerminatorKind::Assert { .. }
@@ -177,10 +175,10 @@ impl CoverageGraph {
fn add_basic_coverage_block(
bcbs: &mut IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
- bb_to_bcb: &mut IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
+ bb_to_bcb: &mut IndexSlice<BasicBlock, Option<BasicCoverageBlock>>,
basic_blocks: Vec<BasicBlock>,
) {
- let bcb = BasicCoverageBlock::from_usize(bcbs.len());
+ let bcb = bcbs.next_index();
for &bb in basic_blocks.iter() {
bb_to_bcb[bb] = Some(bcb);
}
@@ -538,29 +536,29 @@ impl TraverseCoverageGraphWithLoops {
"TraverseCoverageGraphWithLoops::next - context_stack: {:?}",
self.context_stack.iter().rev().collect::<Vec<_>>()
);
- while let Some(next_bcb) = {
- // Strip contexts with empty worklists from the top of the stack
- while self.context_stack.last().map_or(false, |context| context.worklist.is_empty()) {
+
+ while let Some(context) = self.context_stack.last_mut() {
+ if let Some(next_bcb) = context.worklist.pop() {
+ if !self.visited.insert(next_bcb) {
+ debug!("Already visited: {:?}", next_bcb);
+ continue;
+ }
+ debug!("Visiting {:?}", next_bcb);
+ if self.backedges[next_bcb].len() > 0 {
+ debug!("{:?} is a loop header! Start a new TraversalContext...", next_bcb);
+ self.context_stack.push(TraversalContext {
+ loop_backedges: Some((self.backedges[next_bcb].clone(), next_bcb)),
+ worklist: Vec::new(),
+ });
+ }
+ self.extend_worklist(basic_coverage_blocks, next_bcb);
+ return Some(next_bcb);
+ } else {
+ // Strip contexts with empty worklists from the top of the stack
self.context_stack.pop();
}
- // Pop the next bcb off of the current context_stack. If none, all BCBs were visited.
- self.context_stack.last_mut().map_or(None, |context| context.worklist.pop())
- } {
- if !self.visited.insert(next_bcb) {
- debug!("Already visited: {:?}", next_bcb);
- continue;
- }
- debug!("Visiting {:?}", next_bcb);
- if self.backedges[next_bcb].len() > 0 {
- debug!("{:?} is a loop header! Start a new TraversalContext...", next_bcb);
- self.context_stack.push(TraversalContext {
- loop_backedges: Some((self.backedges[next_bcb].clone(), next_bcb)),
- worklist: Vec::new(),
- });
- }
- self.extend_worklist(basic_coverage_blocks, next_bcb);
- return Some(next_bcb);
}
+
None
}