Skip to content

Commit 955e7fb

Browse files
committed
Consistently use dominates instead of is_dominated_by
There is a number of APIs that answer dominance queries. Previously they were named either "dominates" or "is_dominated_by". Consistently use the "dominates" form. No functional changes.
1 parent b22aa57 commit 955e7fb

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

compiler/rustc_data_structures/src/graph/dominators/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl<Node: Idx> Dominators<Node> {
289289
Iter { dominators: self, node: Some(node) }
290290
}
291291

292-
pub fn is_dominated_by(&self, node: Node, dom: Node) -> bool {
292+
pub fn dominates(&self, dom: Node, node: Node) -> bool {
293293
// FIXME -- could be optimized by using post-order-rank
294294
self.dominators(node).any(|n| n == dom)
295295
}

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3049,7 +3049,7 @@ impl Location {
30493049
if self.block == other.block {
30503050
self.statement_index <= other.statement_index
30513051
} else {
3052-
dominators.is_dominated_by(other.block, self.block)
3052+
dominators.dominates(self.block, other.block)
30533053
}
30543054
}
30553055
}

compiler/rustc_mir_transform/src/coverage/counters.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ impl<'a> BcbCounters<'a> {
520520
let mut found_loop_exit = false;
521521
for &branch in branches.iter() {
522522
if backedge_from_bcbs.iter().any(|&backedge_from_bcb| {
523-
self.bcb_is_dominated_by(backedge_from_bcb, branch.target_bcb)
523+
self.bcb_dominates(branch.target_bcb, backedge_from_bcb)
524524
}) {
525525
if let Some(reloop_branch) = some_reloop_branch {
526526
if reloop_branch.counter(&self.basic_coverage_blocks).is_none() {
@@ -603,8 +603,8 @@ impl<'a> BcbCounters<'a> {
603603
}
604604

605605
#[inline]
606-
fn bcb_is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool {
607-
self.basic_coverage_blocks.is_dominated_by(node, dom)
606+
fn bcb_dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
607+
self.basic_coverage_blocks.dominates(dom, node)
608608
}
609609

610610
#[inline]

compiler/rustc_mir_transform/src/coverage/graph.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ impl CoverageGraph {
209209
}
210210

211211
#[inline(always)]
212-
pub fn is_dominated_by(&self, node: BasicCoverageBlock, dom: BasicCoverageBlock) -> bool {
213-
self.dominators.as_ref().unwrap().is_dominated_by(node, dom)
212+
pub fn dominates(&self, dom: BasicCoverageBlock, node: BasicCoverageBlock) -> bool {
213+
self.dominators.as_ref().unwrap().dominates(dom, node)
214214
}
215215

216216
#[inline(always)]
@@ -312,7 +312,7 @@ rustc_index::newtype_index! {
312312
/// to the BCB's primary counter or expression).
313313
///
314314
/// The BCB CFG is critical to simplifying the coverage analysis by ensuring graph path-based
315-
/// queries (`is_dominated_by()`, `predecessors`, `successors`, etc.) have branch (control flow)
315+
/// queries (`dominates()`, `predecessors`, `successors`, etc.) have branch (control flow)
316316
/// significance.
317317
#[derive(Debug, Clone)]
318318
pub(super) struct BasicCoverageBlockData {
@@ -594,7 +594,7 @@ impl TraverseCoverageGraphWithLoops {
594594
// branching block would have given an `Expression` (or vice versa).
595595
let (some_successor_to_add, some_loop_header) =
596596
if let Some((_, loop_header)) = context.loop_backedges {
597-
if basic_coverage_blocks.is_dominated_by(successor, loop_header) {
597+
if basic_coverage_blocks.dominates(loop_header, successor) {
598598
(Some(successor), Some(loop_header))
599599
} else {
600600
(None, None)
@@ -666,15 +666,15 @@ pub(super) fn find_loop_backedges(
666666
//
667667
// The overall complexity appears to be comparable to many other MIR transform algorithms, and I
668668
// don't expect that this function is creating a performance hot spot, but if this becomes an
669-
// issue, there may be ways to optimize the `is_dominated_by` algorithm (as indicated by an
669+
// issue, there may be ways to optimize the `dominates` algorithm (as indicated by an
670670
// existing `FIXME` comment in that code), or possibly ways to optimize it's usage here, perhaps
671671
// by keeping track of results for visited `BasicCoverageBlock`s if they can be used to short
672-
// circuit downstream `is_dominated_by` checks.
672+
// circuit downstream `dominates` checks.
673673
//
674674
// For now, that kind of optimization seems unnecessarily complicated.
675675
for (bcb, _) in basic_coverage_blocks.iter_enumerated() {
676676
for &successor in &basic_coverage_blocks.successors[bcb] {
677-
if basic_coverage_blocks.is_dominated_by(bcb, successor) {
677+
if basic_coverage_blocks.dominates(successor, bcb) {
678678
let loop_header = successor;
679679
let backedge_from_bcb = bcb;
680680
debug!(

compiler/rustc_mir_transform/src/coverage/spans.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl CoverageStatement {
6363
/// Note: A `CoverageStatement` merged into another CoverageSpan may come from a `BasicBlock` that
6464
/// is not part of the `CoverageSpan` bcb if the statement was included because it's `Span` matches
6565
/// or is subsumed by the `Span` associated with this `CoverageSpan`, and it's `BasicBlock`
66-
/// `is_dominated_by()` the `BasicBlock`s in this `CoverageSpan`.
66+
/// `dominates()` the `BasicBlock`s in this `CoverageSpan`.
6767
#[derive(Debug, Clone)]
6868
pub(super) struct CoverageSpan {
6969
pub span: Span,
@@ -705,12 +705,12 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
705705
fn hold_pending_dups_unless_dominated(&mut self) {
706706
// Equal coverage spans are ordered by dominators before dominated (if any), so it should be
707707
// impossible for `curr` to dominate any previous `CoverageSpan`.
708-
debug_assert!(!self.span_bcb_is_dominated_by(self.prev(), self.curr()));
708+
debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev()));
709709

710710
let initial_pending_count = self.pending_dups.len();
711711
if initial_pending_count > 0 {
712712
let mut pending_dups = self.pending_dups.split_off(0);
713-
pending_dups.retain(|dup| !self.span_bcb_is_dominated_by(self.curr(), dup));
713+
pending_dups.retain(|dup| !self.span_bcb_dominates(dup, self.curr()));
714714
self.pending_dups.append(&mut pending_dups);
715715
if self.pending_dups.len() < initial_pending_count {
716716
debug!(
@@ -721,7 +721,7 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
721721
}
722722
}
723723

724-
if self.span_bcb_is_dominated_by(self.curr(), self.prev()) {
724+
if self.span_bcb_dominates(self.prev(), self.curr()) {
725725
debug!(
726726
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
727727
self.prev()
@@ -787,8 +787,8 @@ impl<'a, 'tcx> CoverageSpans<'a, 'tcx> {
787787
}
788788
}
789789

790-
fn span_bcb_is_dominated_by(&self, covspan: &CoverageSpan, dom_covspan: &CoverageSpan) -> bool {
791-
self.basic_coverage_blocks.is_dominated_by(covspan.bcb, dom_covspan.bcb)
790+
fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
791+
self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
792792
}
793793
}
794794

0 commit comments

Comments
 (0)