diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2023-06-29 12:14:04 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2023-08-01 11:29:55 +1000 |
| commit | f103db894fdcf94822d57cf28e30bc498c042631 (patch) | |
| tree | 461dacc5e3344fe5662639681a58d54f84c3b1ee /compiler/rustc_mir_transform/src/coverage/counters.rs | |
| parent | 1a014d42f45de1b829ca7916d8f639fda6e0770a (diff) | |
| download | rust-f103db894fdcf94822d57cf28e30bc498c042631.tar.gz rust-f103db894fdcf94822d57cf28e30bc498c042631.zip | |
Make coverage expression IDs count up from 0, not down from `u32::MAX`
Operand types are now tracked explicitly, so there is no need for expression IDs to avoid counter IDs by descending from `u32::MAX`. Instead they can just count up from 0, and can be used directly as indices when necessary.
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/counters.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/counters.rs | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 9d168404264..cd2539a5e66 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::coverage::*; pub(super) struct CoverageCounters { function_source_hash: u64, next_counter_id: u32, - num_expressions: u32, + next_expression_id: ExpressionId, pub debug_counters: DebugCounters, } @@ -26,7 +26,7 @@ impl CoverageCounters { Self { function_source_hash, next_counter_id: CounterValueReference::START.as_u32(), - num_expressions: 0, + next_expression_id: ExpressionId::START, debug_counters: DebugCounters::new(), } } @@ -94,20 +94,17 @@ impl CoverageCounters { /// Counter IDs start from one and go up. fn next_counter(&mut self) -> CounterValueReference { - assert!(self.next_counter_id < u32::MAX - self.num_expressions); let next = self.next_counter_id; self.next_counter_id += 1; CounterValueReference::from(next) } - /// Expression IDs start from u32::MAX and go down because an Expression can reference - /// (add or subtract counts) of both Counter regions and Expression regions. The counter - /// expression operand IDs must be unique across both types. - fn next_expression(&mut self) -> InjectedExpressionId { - assert!(self.next_counter_id < u32::MAX - self.num_expressions); - let next = u32::MAX - self.num_expressions; - self.num_expressions += 1; - InjectedExpressionId::from(next) + /// Expression IDs start from 0 and go up. + /// (Counter IDs and Expression IDs are distinguished by the `Operand` enum.) + fn next_expression(&mut self) -> ExpressionId { + let next = self.next_expression_id; + self.next_expression_id = next.next_id(); + next } } |
