about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/graph.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2023-10-11 17:40:37 +1100
committerZalathar <Zalathar@users.noreply.github.com>2023-10-12 21:41:13 +1100
commit15360b3bc8f75c33af8a41da5dc9a1cab19691ba (patch)
tree8a071cd7535ad99c7b12b2444df8c06e85338635 /compiler/rustc_mir_transform/src/coverage/graph.rs
parentea3fb7bc2cd64fc124209e6f4ffcda8d053fd7ae (diff)
downloadrust-15360b3bc8f75c33af8a41da5dc9a1cab19691ba.tar.gz
rust-15360b3bc8f75c33af8a41da5dc9a1cab19691ba.zip
coverage: Store a graph reference in the graph traversal struct
Having to keep passing in a graph reference was a holdover from when the graph
was partly mutated during traversal. As of #114354 that is no longer necessary,
so we can simplify the traversal code by storing a graph reference as a field
in `TraverseCoverageGraphWithLoops`.
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/graph.rs')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/graph.rs21
1 files changed, 10 insertions, 11 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs
index 8dc13117b9f..02bc62a7d26 100644
--- a/compiler/rustc_mir_transform/src/coverage/graph.rs
+++ b/compiler/rustc_mir_transform/src/coverage/graph.rs
@@ -393,14 +393,16 @@ pub(super) struct TraversalContext {
     worklist: VecDeque<BasicCoverageBlock>,
 }
 
-pub(super) struct TraverseCoverageGraphWithLoops {
+pub(super) struct TraverseCoverageGraphWithLoops<'a> {
+    basic_coverage_blocks: &'a CoverageGraph,
+
     backedges: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
     context_stack: Vec<TraversalContext>,
     visited: BitSet<BasicCoverageBlock>,
 }
 
-impl TraverseCoverageGraphWithLoops {
-    pub fn new(basic_coverage_blocks: &CoverageGraph) -> Self {
+impl<'a> TraverseCoverageGraphWithLoops<'a> {
+    pub(super) fn new(basic_coverage_blocks: &'a CoverageGraph) -> Self {
         let backedges = find_loop_backedges(basic_coverage_blocks);
 
         let worklist = VecDeque::from([basic_coverage_blocks.start_node()]);
@@ -411,7 +413,7 @@ impl TraverseCoverageGraphWithLoops {
         // of the stack as loops are entered, and popped off of the stack when a loop's worklist is
         // exhausted.
         let visited = BitSet::new_empty(basic_coverage_blocks.num_nodes());
-        Self { backedges, context_stack, visited }
+        Self { basic_coverage_blocks, backedges, context_stack, visited }
     }
 
     /// For each loop on the loop context stack (top-down), yields a list of BCBs
@@ -424,7 +426,7 @@ impl TraverseCoverageGraphWithLoops {
             .map(|(from_bcbs, _to_bcb)| from_bcbs.as_slice())
     }
 
-    pub fn next(&mut self, basic_coverage_blocks: &CoverageGraph) -> Option<BasicCoverageBlock> {
+    pub(super) fn next(&mut self) -> Option<BasicCoverageBlock> {
         debug!(
             "TraverseCoverageGraphWithLoops::next - context_stack: {:?}",
             self.context_stack.iter().rev().collect::<Vec<_>>()
@@ -445,7 +447,7 @@ impl TraverseCoverageGraphWithLoops {
                         worklist: VecDeque::new(),
                     });
                 }
-                self.extend_worklist(basic_coverage_blocks, bcb);
+                self.extend_worklist(bcb);
                 return Some(bcb);
             } else {
                 // Strip contexts with empty worklists from the top of the stack
@@ -456,11 +458,8 @@ impl TraverseCoverageGraphWithLoops {
         None
     }
 
-    pub fn extend_worklist(
-        &mut self,
-        basic_coverage_blocks: &CoverageGraph,
-        bcb: BasicCoverageBlock,
-    ) {
+    pub fn extend_worklist(&mut self, bcb: BasicCoverageBlock) {
+        let Self { basic_coverage_blocks, .. } = *self;
         let successors = &basic_coverage_blocks.successors[bcb];
         debug!("{:?} has {} successors:", bcb, successors.len());
         for &successor in successors {