Make coverage counter IDs count up from 0, not 1

Operand types are now tracked explicitly, so there is no need to reserve ID 0
for the special always-zero counter.

As part of the renumbering, this change fixes an off-by-one error in the way
counters were counted by the `coverageinfo` query. As a result, functions
should now have exactly the number of counters they actually need, instead of
always having an extra counter that is never used.
This commit is contained in:
Zalathar
2023-06-29 12:36:19 +10:00
parent f103db894f
commit 3920e07f0b
12 changed files with 43 additions and 61 deletions

View File

@@ -16,7 +16,7 @@ use rustc_middle::mir::coverage::*;
/// `Coverage` statements.
pub(super) struct CoverageCounters {
function_source_hash: u64,
next_counter_id: u32,
next_counter_id: CounterId,
next_expression_id: ExpressionId,
pub debug_counters: DebugCounters,
}
@@ -25,7 +25,7 @@ impl CoverageCounters {
pub fn new(function_source_hash: u64) -> Self {
Self {
function_source_hash,
next_counter_id: CounterValueReference::START.as_u32(),
next_counter_id: CounterId::START,
next_expression_id: ExpressionId::START,
debug_counters: DebugCounters::new(),
}
@@ -93,10 +93,10 @@ impl CoverageCounters {
}
/// Counter IDs start from one and go up.
fn next_counter(&mut self) -> CounterValueReference {
fn next_counter(&mut self) -> CounterId {
let next = self.next_counter_id;
self.next_counter_id += 1;
CounterValueReference::from(next)
self.next_counter_id = next.next_id();
next
}
/// Expression IDs start from 0 and go up.