coverage: Don't bother renumbering expressions on the Rust side
The LLVM API that we use to encode coverage mappings already has its own code for removing unused coverage expressions and renumbering the rest. This lets us get rid of our own complex renumbering code, making it easier to change our coverage code in other ways.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use rustc_middle::mir::coverage::{CounterId, MappedExpressionIndex};
|
||||
use rustc_middle::mir::coverage::{CounterId, ExpressionId, Operand};
|
||||
|
||||
/// Must match the layout of `LLVMRustCounterKind`.
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
@@ -39,20 +39,16 @@ impl Counter {
|
||||
}
|
||||
|
||||
/// Constructs a new `Counter` of kind `Expression`.
|
||||
pub fn expression(mapped_expression_index: MappedExpressionIndex) -> Self {
|
||||
Self { kind: CounterKind::Expression, id: mapped_expression_index.into() }
|
||||
pub(crate) fn expression(expression_id: ExpressionId) -> Self {
|
||||
Self { kind: CounterKind::Expression, id: expression_id.as_u32() }
|
||||
}
|
||||
|
||||
/// Returns true if the `Counter` kind is `Zero`.
|
||||
pub fn is_zero(&self) -> bool {
|
||||
matches!(self.kind, CounterKind::Zero)
|
||||
}
|
||||
|
||||
/// An explicitly-named function to get the ID value, making it more obvious
|
||||
/// that the stored value is now 0-based.
|
||||
pub fn zero_based_id(&self) -> u32 {
|
||||
debug_assert!(!self.is_zero(), "`id` is undefined for CounterKind::Zero");
|
||||
self.id
|
||||
pub(crate) fn from_operand(operand: Operand) -> Self {
|
||||
match operand {
|
||||
Operand::Zero => Self::ZERO,
|
||||
Operand::Counter(id) => Self::counter_value_reference(id),
|
||||
Operand::Expression(id) => Self::expression(id),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +74,11 @@ pub struct CounterExpression {
|
||||
}
|
||||
|
||||
impl CounterExpression {
|
||||
/// The dummy expression `(0 - 0)` has a representation of all zeroes,
|
||||
/// making it marginally more efficient to initialize than `(0 + 0)`.
|
||||
pub(crate) const DUMMY: Self =
|
||||
Self { lhs: Counter::ZERO, kind: ExprKind::Subtract, rhs: Counter::ZERO };
|
||||
|
||||
pub fn new(lhs: Counter, kind: ExprKind, rhs: Counter) -> Self {
|
||||
Self { kind, lhs, rhs }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user