From 1a014d42f45de1b829ca7916d8f639fda6e0770a Mon Sep 17 00:00:00 2001 From: Zalathar Date: Mon, 26 Jun 2023 22:28:48 +1000 Subject: Replace `ExpressionOperandId` with enum `Operand` Because the three kinds of operand are now distinguished explicitly, we no longer need fiddly code to disambiguate counter IDs and expression IDs based on the total number of counters/expressions in a function. This does increase the size of operands from 4 bytes to 8 bytes, but that shouldn't be a big deal since they are mostly stored inside boxed structures, and the current coverage code is not particularly size-optimized anyway. --- compiler/rustc_mir_transform/src/coverage/graph.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'compiler/rustc_mir_transform/src/coverage/graph.rs') diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 5d843f4ade0..f94dad4c8da 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -345,10 +345,7 @@ impl BasicCoverageBlockData { &mir_body[self.last_bb()].terminator() } - pub fn set_counter( - &mut self, - counter_kind: CoverageKind, - ) -> Result { + pub fn set_counter(&mut self, counter_kind: CoverageKind) -> Result { debug_assert!( // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also // have an expression (to be injected into an existing `BasicBlock` represented by this @@ -356,7 +353,7 @@ impl BasicCoverageBlockData { self.edge_from_bcbs.is_none() || counter_kind.is_expression(), "attempt to add a `Counter` to a BCB target with existing incoming edge counters" ); - let operand = counter_kind.as_operand_id(); + let operand = counter_kind.as_operand(); if let Some(replaced) = self.counter_kind.replace(counter_kind) { Error::from_string(format!( "attempt to set a BasicCoverageBlock coverage counter more than once; \ @@ -381,7 +378,7 @@ impl BasicCoverageBlockData { &mut self, from_bcb: BasicCoverageBlock, counter_kind: CoverageKind, - ) -> Result { + ) -> Result { if level_enabled!(tracing::Level::DEBUG) { // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also // have an expression (to be injected into an existing `BasicBlock` represented by this @@ -393,7 +390,7 @@ impl BasicCoverageBlockData { )); } } - let operand = counter_kind.as_operand_id(); + let operand = counter_kind.as_operand(); if let Some(replaced) = self.edge_from_bcbs.get_or_insert_default().insert(from_bcb, counter_kind) { -- cgit 1.4.1-3-g733a5