Skip to content

Commit 419e998

Browse files
committed
coverage: Push down creation of a visited node's counter
Now that this code path unconditionally calls `make_branch_counters`, we might as well make that method responsible for creating the node's counter as well, since it needs the resulting term anyway.
1 parent 29bca1e commit 419e998

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,7 @@ impl<'a> MakeBcbCounters<'a> {
226226
while let Some(bcb) = traversal.next() {
227227
if bcb_has_coverage_spans(bcb) {
228228
debug!("{:?} has at least one coverage span. Get or make its counter", bcb);
229-
let branching_counter_operand = self.get_or_make_counter_operand(bcb);
230-
231-
self.make_branch_counters(&traversal, bcb, branching_counter_operand);
229+
self.make_node_and_branch_counters(&traversal, bcb);
232230
} else {
233231
debug!(
234232
"{:?} does not have any coverage spans. A counter will only be added if \
@@ -245,12 +243,15 @@ impl<'a> MakeBcbCounters<'a> {
245243
);
246244
}
247245

248-
fn make_branch_counters(
246+
fn make_node_and_branch_counters(
249247
&mut self,
250248
traversal: &TraverseCoverageGraphWithLoops<'_>,
251249
from_bcb: BasicCoverageBlock,
252-
branching_counter_operand: CovTerm,
253250
) {
251+
// First, ensure that this node has a counter of some kind.
252+
// We might also use its term later to compute one of the branch counters.
253+
let from_bcb_operand = self.get_or_make_counter_operand(from_bcb);
254+
254255
let branches = self.bcb_branches(from_bcb);
255256

256257
// If this node doesn't have multiple out-edges, or all of its out-edges
@@ -321,7 +322,7 @@ impl<'a> MakeBcbCounters<'a> {
321322
self.bcb_predecessors(expression_branch.target_bcb),
322323
);
323324
let expression = self.coverage_counters.make_expression(
324-
branching_counter_operand,
325+
from_bcb_operand,
325326
Op::Subtract,
326327
sumup_counter_operand,
327328
);

0 commit comments

Comments
 (0)