Skip to content

Commit 917b455

Browse files
committed
coverage: Reduce/simplify visibility in coverage::graph
Using `pub(super)` makes it harder to move code between modules, and doesn't provide much privacy benefit over `pub(crate)`.
1 parent 5eb30f0 commit 917b455

File tree

1 file changed

+28
-24
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+28
-24
lines changed

compiler/rustc_mir_transform/src/coverage/graph.rs

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ use std::ops::{Index, IndexMut};
1414
/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
1515
/// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
1616
#[derive(Debug)]
17-
pub(super) struct CoverageGraph {
17+
pub(crate) struct CoverageGraph {
1818
bcbs: IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
1919
bb_to_bcb: IndexVec<BasicBlock, Option<BasicCoverageBlock>>,
20-
pub successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
21-
pub predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
20+
pub(crate) successors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
21+
pub(crate) predecessors: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
2222
dominators: Option<Dominators<BasicCoverageBlock>>,
2323
}
2424

2525
impl CoverageGraph {
26-
pub fn from_mir(mir_body: &mir::Body<'_>) -> Self {
26+
pub(crate) fn from_mir(mir_body: &mir::Body<'_>) -> Self {
2727
let (bcbs, bb_to_bcb) = Self::compute_basic_coverage_blocks(mir_body);
2828

2929
// Pre-transform MIR `BasicBlock` successors and predecessors into the BasicCoverageBlock
@@ -135,24 +135,28 @@ impl CoverageGraph {
135135
}
136136

137137
#[inline(always)]
138-
pub fn iter_enumerated(
138+
pub(crate) fn iter_enumerated(
139139
&self,
140140
) -> impl Iterator<Item = (BasicCoverageBlock, &BasicCoverageBlockData)> {
141141
self.bcbs.iter_enumerated()
142142
}
143143

144144
#[inline(always)]
145-
pub fn bcb_from_bb(&self, bb: BasicBlock) -> Option<BasicCoverageBlock> {
145+
pub(crate) fn bcb_from_bb(&self, bb: BasicBlock) -> Option<BasicCoverageBlock> {
146146
if bb.index() < self.bb_to_bcb.len() { self.bb_to_bcb[bb] } else { None }
147147
}
148148

149149
#[inline(always)]
150-
pub fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
150+
pub(crate) fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
151151
self.dominators.as_ref().unwrap().dominates(dom, node)
152152
}
153153

154154
#[inline(always)]
155-
pub fn cmp_in_dominator_order(&self, a: BasicCoverageBlock, b: BasicCoverageBlock) -> Ordering {
155+
pub(crate) fn cmp_in_dominator_order(
156+
&self,
157+
a: BasicCoverageBlock,
158+
b: BasicCoverageBlock,
159+
) -> Ordering {
156160
self.dominators.as_ref().unwrap().cmp_in_dominator_order(a, b)
157161
}
158162

@@ -166,7 +170,7 @@ impl CoverageGraph {
166170
///
167171
/// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
168172
#[inline(always)]
169-
pub(super) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
173+
pub(crate) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
170174
// Even though bcb0 conceptually has an extra virtual in-edge due to
171175
// being the entry point, we've already asserted that it has no _other_
172176
// in-edges, so there's no possibility of it having _multiple_ in-edges.
@@ -227,7 +231,7 @@ rustc_index::newtype_index! {
227231
/// A node in the control-flow graph of CoverageGraph.
228232
#[orderable]
229233
#[debug_format = "bcb{}"]
230-
pub(super) struct BasicCoverageBlock {
234+
pub(crate) struct BasicCoverageBlock {
231235
const START_BCB = 0;
232236
}
233237
}
@@ -259,23 +263,23 @@ rustc_index::newtype_index! {
259263
/// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow)
260264
/// significance.
261265
#[derive(Debug, Clone)]
262-
pub(super) struct BasicCoverageBlockData {
263-
pub basic_blocks: Vec<BasicBlock>,
266+
pub(crate) struct BasicCoverageBlockData {
267+
pub(crate) basic_blocks: Vec<BasicBlock>,
264268
}
265269

266270
impl BasicCoverageBlockData {
267-
pub fn from(basic_blocks: Vec<BasicBlock>) -> Self {
271+
fn from(basic_blocks: Vec<BasicBlock>) -> Self {
268272
assert!(basic_blocks.len() > 0);
269273
Self { basic_blocks }
270274
}
271275

272276
#[inline(always)]
273-
pub fn leader_bb(&self) -> BasicBlock {
277+
pub(crate) fn leader_bb(&self) -> BasicBlock {
274278
self.basic_blocks[0]
275279
}
276280

277281
#[inline(always)]
278-
pub fn last_bb(&self) -> BasicBlock {
282+
pub(crate) fn last_bb(&self) -> BasicBlock {
279283
*self.basic_blocks.last().unwrap()
280284
}
281285
}
@@ -364,7 +368,7 @@ fn bcb_filtered_successors<'a, 'tcx>(terminator: &'a Terminator<'tcx>) -> Covera
364368
/// CoverageGraph outside all loops. This supports traversing the BCB CFG in a way that
365369
/// ensures a loop is completely traversed before processing Blocks after the end of the loop.
366370
#[derive(Debug)]
367-
pub(super) struct TraversalContext {
371+
struct TraversalContext {
368372
/// BCB with one or more incoming loop backedges, indicating which loop
369373
/// this context is for.
370374
///
@@ -375,7 +379,7 @@ pub(super) struct TraversalContext {
375379
worklist: VecDeque<BasicCoverageBlock>,
376380
}
377381

378-
pub(super) struct TraverseCoverageGraphWithLoops<'a> {
382+
pub(crate) struct TraverseCoverageGraphWithLoops<'a> {
379383
basic_coverage_blocks: &'a CoverageGraph,
380384

381385
backedges: IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>>,
@@ -384,7 +388,7 @@ pub(super) struct TraverseCoverageGraphWithLoops<'a> {
384388
}
385389

386390
impl<'a> TraverseCoverageGraphWithLoops<'a> {
387-
pub(super) fn new(basic_coverage_blocks: &'a CoverageGraph) -> Self {
391+
pub(crate) fn new(basic_coverage_blocks: &'a CoverageGraph) -> Self {
388392
let backedges = find_loop_backedges(basic_coverage_blocks);
389393

390394
let worklist = VecDeque::from([basic_coverage_blocks.start_node()]);
@@ -400,15 +404,15 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
400404

401405
/// For each loop on the loop context stack (top-down), yields a list of BCBs
402406
/// within that loop that have an outgoing edge back to the loop header.
403-
pub(super) fn reloop_bcbs_per_loop(&self) -> impl Iterator<Item = &[BasicCoverageBlock]> {
407+
pub(crate) fn reloop_bcbs_per_loop(&self) -> impl Iterator<Item = &[BasicCoverageBlock]> {
404408
self.context_stack
405409
.iter()
406410
.rev()
407411
.filter_map(|context| context.loop_header)
408412
.map(|header_bcb| self.backedges[header_bcb].as_slice())
409413
}
410414

411-
pub(super) fn next(&mut self) -> Option<BasicCoverageBlock> {
415+
pub(crate) fn next(&mut self) -> Option<BasicCoverageBlock> {
412416
debug!(
413417
"TraverseCoverageGraphWithLoops::next - context_stack: {:?}",
414418
self.context_stack.iter().rev().collect::<Vec<_>>()
@@ -440,7 +444,7 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
440444
None
441445
}
442446

443-
pub fn add_successors_to_worklists(&mut self, bcb: BasicCoverageBlock) {
447+
fn add_successors_to_worklists(&mut self, bcb: BasicCoverageBlock) {
444448
let successors = &self.basic_coverage_blocks.successors[bcb];
445449
debug!("{:?} has {} successors:", bcb, successors.len());
446450

@@ -494,19 +498,19 @@ impl<'a> TraverseCoverageGraphWithLoops<'a> {
494498
}
495499
}
496500

497-
pub fn is_complete(&self) -> bool {
501+
pub(crate) fn is_complete(&self) -> bool {
498502
self.visited.count() == self.visited.domain_size()
499503
}
500504

501-
pub fn unvisited(&self) -> Vec<BasicCoverageBlock> {
505+
pub(crate) fn unvisited(&self) -> Vec<BasicCoverageBlock> {
502506
let mut unvisited_set: BitSet<BasicCoverageBlock> =
503507
BitSet::new_filled(self.visited.domain_size());
504508
unvisited_set.subtract(&self.visited);
505509
unvisited_set.iter().collect::<Vec<_>>()
506510
}
507511
}
508512

509-
pub(super) fn find_loop_backedges(
513+
fn find_loop_backedges(
510514
basic_coverage_blocks: &CoverageGraph,
511515
) -> IndexVec<BasicCoverageBlock, Vec<BasicCoverageBlock>> {
512516
let num_bcbs = basic_coverage_blocks.num_nodes();

0 commit comments

Comments
 (0)