Skip to content

Commit 6251d16

Browse files
committed
coverage: Streamline creation of physical edge counters
1 parent 7cb8586 commit 6251d16

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,33 @@ impl CoverageCounters {
9595
this
9696
}
9797

98-
fn make_counter(&mut self, site: CounterIncrementSite) -> BcbCounter {
98+
/// Shared helper used by [`Self::make_phys_node_counter`] and
99+
/// [`Self::make_phys_edge_counter`]. Don't call this directly.
100+
fn make_counter_inner(&mut self, site: CounterIncrementSite) -> BcbCounter {
99101
let id = self.counter_increment_sites.push(site);
100102
BcbCounter::Counter { id }
101103
}
102104

103105
/// Creates a new physical counter attached a BCB node.
104106
/// The node must not already have a counter.
105107
fn make_phys_node_counter(&mut self, bcb: BasicCoverageBlock) -> BcbCounter {
106-
let counter = self.make_counter(CounterIncrementSite::Node { bcb });
108+
let counter = self.make_counter_inner(CounterIncrementSite::Node { bcb });
107109
debug!(?bcb, ?counter, "node gets a physical counter");
108110
self.set_bcb_counter(bcb, counter)
109111
}
110112

113+
/// Creates a new physical counter attached to a BCB edge.
114+
/// The edge must not already have a counter.
115+
fn make_phys_edge_counter(
116+
&mut self,
117+
from_bcb: BasicCoverageBlock,
118+
to_bcb: BasicCoverageBlock,
119+
) -> BcbCounter {
120+
let counter = self.make_counter_inner(CounterIncrementSite::Edge { from_bcb, to_bcb });
121+
debug!(?from_bcb, ?to_bcb, ?counter, "edge gets a physical counter");
122+
self.set_bcb_edge_counter(from_bcb, to_bcb, counter)
123+
}
124+
111125
fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter {
112126
let new_expr = BcbExpression { lhs, op, rhs };
113127
*self
@@ -417,10 +431,7 @@ impl<'a> MakeBcbCounters<'a> {
417431
}
418432

419433
// Make a new counter to count this edge.
420-
let counter_kind =
421-
self.coverage_counters.make_counter(CounterIncrementSite::Edge { from_bcb, to_bcb });
422-
debug!("Edge {from_bcb:?}->{to_bcb:?} gets a new counter: {counter_kind:?}");
423-
self.coverage_counters.set_bcb_edge_counter(from_bcb, to_bcb, counter_kind)
434+
self.coverage_counters.make_phys_edge_counter(from_bcb, to_bcb)
424435
}
425436

426437
/// Choose one of the out-edges of `from_bcb` to receive an expression

0 commit comments

Comments
 (0)