1
Fork 0

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.
This commit is contained in:
Zalathar 2023-06-29 12:14:04 +10:00
parent 1a014d42f4
commit f103db894f
9 changed files with 49 additions and 71 deletions

View file

@ -26,19 +26,23 @@ impl CounterValueReference {
}
rustc_index::newtype_index! {
/// Values descend from u32::MAX.
/// ID of a coverage-counter expression. Values ascend from 0.
///
/// Note that LLVM handles expression IDs as `uint32_t`, so there is no need
/// to use a larger representation on the Rust side.
#[derive(HashStable)]
#[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionId({})"]
pub struct InjectedExpressionId {}
#[debug_format = "ExpressionId({})"]
pub struct ExpressionId {}
}
rustc_index::newtype_index! {
/// Values ascend from 0.
#[derive(HashStable)]
#[max = 0xFFFF_FFFF]
#[debug_format = "InjectedExpressionIndex({})"]
pub struct InjectedExpressionIndex {}
impl ExpressionId {
pub const START: Self = Self::from_u32(0);
#[inline(always)]
pub fn next_id(self) -> Self {
Self::from_u32(self.as_u32() + 1)
}
}
rustc_index::newtype_index! {
@ -60,7 +64,7 @@ rustc_index::newtype_index! {
pub enum Operand {
Zero,
Counter(CounterValueReference),
Expression(InjectedExpressionId),
Expression(ExpressionId),
}
impl Debug for Operand {
@ -84,7 +88,7 @@ pub enum CoverageKind {
Expression {
/// ID of this coverage-counter expression within its enclosing function.
/// Other expressions in the same function can refer to it as an operand.
id: InjectedExpressionId,
id: ExpressionId,
lhs: Operand,
op: Op,
rhs: Operand,

View file

@ -471,8 +471,7 @@ TrivialTypeTraversalAndLiftImpls! {
::rustc_target::asm::InlineAsmRegOrRegClass,
::rustc_target::spec::abi::Abi,
crate::mir::coverage::CounterValueReference,
crate::mir::coverage::InjectedExpressionId,
crate::mir::coverage::InjectedExpressionIndex,
crate::mir::coverage::ExpressionId,
crate::mir::coverage::MappedExpressionIndex,
crate::mir::Local,
crate::mir::Promoted,