Skip to content

Commit 85bec7a

Browse files
committed
coverage: Remove incorrect assertions from counter allocation
These assertions detect situations where a BCB node would have both a physical counter and one or more in-edge counters/expressions. For most BCBs that situation would indicate an implementation bug. However, it's perfectly fine in the case of a BCB having an edge that loops back to itself. Given the complexity and risk involved in fixing the assertions, and the fact that nothing relies on them actually being true, this patch just removes them instead.
1 parent 70206f0 commit 85bec7a

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

-31
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_data_structures::captures::Captures;
22
use rustc_data_structures::fx::FxHashMap;
33
use rustc_data_structures::graph::WithNumNodes;
4-
use rustc_index::bit_set::BitSet;
54
use rustc_index::IndexVec;
65
use rustc_middle::mir::coverage::*;
76

@@ -18,10 +17,6 @@ pub(super) enum BcbCounter {
1817
}
1918

2019
impl BcbCounter {
21-
fn is_expression(&self) -> bool {
22-
matches!(self, Self::Expression { .. })
23-
}
24-
2520
pub(super) fn as_term(&self) -> CovTerm {
2621
match *self {
2722
BcbCounter::Counter { id, .. } => CovTerm::Counter(id),
@@ -60,10 +55,6 @@ pub(super) struct CoverageCounters {
6055
/// We currently don't iterate over this map, but if we do in the future,
6156
/// switch it back to `FxIndexMap` to avoid query stability hazards.
6257
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
63-
/// Tracks which BCBs have a counter associated with some incoming edge.
64-
/// Only used by assertions, to verify that BCBs with incoming edge
65-
/// counters do not have their own physical counters (expressions are allowed).
66-
bcb_has_incoming_edge_counters: BitSet<BasicCoverageBlock>,
6758
/// Table of expression data, associating each expression ID with its
6859
/// corresponding operator (+ or -) and its LHS/RHS operands.
6960
expressions: IndexVec<ExpressionId, Expression>,
@@ -83,7 +74,6 @@ impl CoverageCounters {
8374
counter_increment_sites: IndexVec::new(),
8475
bcb_counters: IndexVec::from_elem_n(None, num_bcbs),
8576
bcb_edge_counters: FxHashMap::default(),
86-
bcb_has_incoming_edge_counters: BitSet::new_empty(num_bcbs),
8777
expressions: IndexVec::new(),
8878
};
8979

@@ -122,14 +112,6 @@ impl CoverageCounters {
122112
}
123113

124114
fn set_bcb_counter(&mut self, bcb: BasicCoverageBlock, counter_kind: BcbCounter) -> BcbCounter {
125-
assert!(
126-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
127-
// have an expression (to be injected into an existing `BasicBlock` represented by this
128-
// `BasicCoverageBlock`).
129-
counter_kind.is_expression() || !self.bcb_has_incoming_edge_counters.contains(bcb),
130-
"attempt to add a `Counter` to a BCB target with existing incoming edge counters"
131-
);
132-
133115
if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) {
134116
bug!(
135117
"attempt to set a BasicCoverageBlock coverage counter more than once; \
@@ -146,19 +128,6 @@ impl CoverageCounters {
146128
to_bcb: BasicCoverageBlock,
147129
counter_kind: BcbCounter,
148130
) -> BcbCounter {
149-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
150-
// have an expression (to be injected into an existing `BasicBlock` represented by this
151-
// `BasicCoverageBlock`).
152-
if let Some(node_counter) = self.bcb_counter(to_bcb)
153-
&& !node_counter.is_expression()
154-
{
155-
bug!(
156-
"attempt to add an incoming edge counter from {from_bcb:?} \
157-
when the target BCB already has {node_counter:?}"
158-
);
159-
}
160-
161-
self.bcb_has_incoming_edge_counters.insert(to_bcb);
162131
if let Some(replaced) = self.bcb_edge_counters.insert((from_bcb, to_bcb), counter_kind) {
163132
bug!(
164133
"attempt to set an edge counter more than once; from_bcb: \

tests/coverage/let_else_loop.coverage

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
LL| |#![feature(coverage_attribute)]
22
LL| |//@ edition: 2021
3-
LL| |//@ ignore-test
3+
LL| |
44
LL| |// Regression test for <https://github.com/rust-lang/rust/issues/122738>.
55
LL| |// These code patterns should not trigger an ICE when allocating a physical
66
LL| |// counter to a node and also one of its in-edges, because that is allowed

tests/coverage/let_else_loop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
3-
//@ ignore-test
3+
44
// Regression test for <https://github.com/rust-lang/rust/issues/122738>.
55
// These code patterns should not trigger an ICE when allocating a physical
66
// counter to a node and also one of its in-edges, because that is allowed

0 commit comments

Comments
 (0)