1
Fork 0

coverage: Use a query to find counters/expressions that must be zero

This query (`coverage_ids_info`) already determines which counter/expression
IDs are unused, so it only takes a little extra effort to also determine which
counters/expressions must have a value of zero.
This commit is contained in:
Zalathar 2024-12-06 22:33:24 +11:00
parent f3f7c20f7b
commit 2022ef7f12
3 changed files with 117 additions and 117 deletions

View file

@ -320,7 +320,7 @@ pub struct MCDCDecisionSpan {
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable)]
pub struct CoverageIdsInfo {
pub counters_seen: BitSet<CounterId>,
pub expressions_seen: BitSet<ExpressionId>,
pub zero_expressions: BitSet<ExpressionId>,
}
impl CoverageIdsInfo {
@ -337,4 +337,15 @@ impl CoverageIdsInfo {
// used. Fixing this would require adding a renumbering step somewhere.
self.counters_seen.last_set_in(..).map_or(0, |max| max.as_u32() + 1)
}
/// Returns `true` if the given term is known to have a value of zero, taking
/// into account knowledge of which counters are unused and which expressions
/// are always zero.
pub fn is_zero_term(&self, term: CovTerm) -> bool {
match term {
CovTerm::Zero => true,
CovTerm::Counter(id) => !self.counters_seen.contains(id),
CovTerm::Expression(id) => self.zero_expressions.contains(id),
}
}
}