Skip to content

Commit 8ef67d0

Browse files
committed
coverage: Promote some debug-only checks to always run
These checks should be cheap, so there's little reason for them to be debug-only.
1 parent ffb7ed9 commit 8ef67d0

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub(super) struct CoverageCounters {
5353
/// edge between two BCBs.
5454
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
5555
/// Tracks which BCBs have a counter associated with some incoming edge.
56-
/// Only used by debug assertions, to verify that BCBs with incoming edge
56+
/// Only used by assertions, to verify that BCBs with incoming edge
5757
/// counters do not have their own physical counters (expressions are allowed).
5858
bcb_has_incoming_edge_counters: BitSet<BasicCoverageBlock>,
5959
/// Table of expression data, associating each expression ID with its
@@ -116,13 +116,14 @@ impl CoverageCounters {
116116
bcb: BasicCoverageBlock,
117117
counter_kind: BcbCounter,
118118
) -> Result<CovTerm, Error> {
119-
debug_assert!(
119+
assert!(
120120
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
121121
// have an expression (to be injected into an existing `BasicBlock` represented by this
122122
// `BasicCoverageBlock`).
123123
counter_kind.is_expression() || !self.bcb_has_incoming_edge_counters.contains(bcb),
124124
"attempt to add a `Counter` to a BCB target with existing incoming edge counters"
125125
);
126+
126127
let term = counter_kind.as_term();
127128
if let Some(replaced) = self.bcb_counters[bcb].replace(counter_kind) {
128129
Error::from_string(format!(
@@ -140,17 +141,16 @@ impl CoverageCounters {
140141
to_bcb: BasicCoverageBlock,
141142
counter_kind: BcbCounter,
142143
) -> Result<CovTerm, Error> {
143-
if level_enabled!(tracing::Level::DEBUG) {
144-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
145-
// have an expression (to be injected into an existing `BasicBlock` represented by this
146-
// `BasicCoverageBlock`).
147-
if self.bcb_counter(to_bcb).is_some_and(|c| !c.is_expression()) {
148-
return Error::from_string(format!(
149-
"attempt to add an incoming edge counter from {from_bcb:?} when the target BCB already \
150-
has a `Counter`"
151-
));
152-
}
144+
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
145+
// have an expression (to be injected into an existing `BasicBlock` represented by this
146+
// `BasicCoverageBlock`).
147+
if let Some(node_counter) = self.bcb_counter(to_bcb) && !node_counter.is_expression() {
148+
return Error::from_string(format!(
149+
"attempt to add an incoming edge counter from {from_bcb:?} \
150+
when the target BCB already has {node_counter:?}"
151+
));
153152
}
153+
154154
self.bcb_has_incoming_edge_counters.insert(to_bcb);
155155
let term = counter_kind.as_term();
156156
if let Some(replaced) = self.bcb_edge_counters.insert((from_bcb, to_bcb), counter_kind) {

0 commit comments

Comments
 (0)