@@ -5,32 +5,6 @@ use rustc_span::Symbol;
5
5
6
6
use std:: fmt:: { self , Debug , Formatter } ;
7
7
8
- rustc_index:: newtype_index! {
9
- /// An ExpressionOperandId value is assigned directly from either a
10
- /// CounterValueReference.as_u32() (which ascend from 1) or an ExpressionOperandId.as_u32()
11
- /// (which _*descend*_ from u32::MAX). Id value `0` (zero) represents a virtual counter with a
12
- /// constant value of `0`.
13
- #[ derive( HashStable ) ]
14
- #[ max = 0xFFFF_FFFF ]
15
- #[ debug_format = "ExpressionOperandId({})" ]
16
- pub struct ExpressionOperandId {
17
- }
18
- }
19
-
20
- impl ExpressionOperandId {
21
- /// An expression operand for a "zero counter", as described in the following references:
22
- ///
23
- /// * <https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#counter>
24
- /// * <https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#tag>
25
- /// * <https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#counter-expressions>
26
- ///
27
- /// This operand can be used to count two or more separate code regions with a single counter,
28
- /// if they run sequentially with no branches, by injecting the `Counter` in a `BasicBlock` for
29
- /// one of the code regions, and inserting `CounterExpression`s ("add ZERO to the counter") in
30
- /// the coverage map for the other code regions.
31
- pub const ZERO : Self = Self :: from_u32 ( 0 ) ;
32
- }
33
-
34
8
rustc_index:: newtype_index! {
35
9
#[ derive( HashStable ) ]
36
10
#[ max = 0xFFFF_FFFF ]
@@ -39,7 +13,7 @@ rustc_index::newtype_index! {
39
13
}
40
14
41
15
impl CounterValueReference {
42
- /// Counters start at 1 to reserve 0 for ExpressionOperandId::ZERO .
16
+ /// Counters start at 1 for historical reasons .
43
17
pub const START : Self = Self :: from_u32 ( 1 ) ;
44
18
45
19
/// Returns explicitly-requested zero-based version of the counter id, used
@@ -52,8 +26,6 @@ impl CounterValueReference {
52
26
}
53
27
54
28
rustc_index:: newtype_index! {
55
- /// InjectedExpressionId.as_u32() converts to ExpressionOperandId.as_u32()
56
- ///
57
29
/// Values descend from u32::MAX.
58
30
#[ derive( HashStable ) ]
59
31
#[ max = 0xFFFF_FFFF ]
@@ -62,8 +34,6 @@ rustc_index::newtype_index! {
62
34
}
63
35
64
36
rustc_index:: newtype_index! {
65
- /// InjectedExpressionIndex.as_u32() translates to u32::MAX - ExpressionOperandId.as_u32()
66
- ///
67
37
/// Values ascend from 0.
68
38
#[ derive( HashStable ) ]
69
39
#[ max = 0xFFFF_FFFF ]
@@ -81,17 +51,25 @@ rustc_index::newtype_index! {
81
51
pub struct MappedExpressionIndex { }
82
52
}
83
53
84
- impl From < CounterValueReference > for ExpressionOperandId {
85
- #[ inline]
86
- fn from ( v : CounterValueReference ) -> ExpressionOperandId {
87
- ExpressionOperandId :: from ( v. as_u32 ( ) )
88
- }
54
+ /// Operand of a coverage-counter expression.
55
+ ///
56
+ /// Operands can be a constant zero value, an actual coverage counter, or another
57
+ /// expression. Counter/expression operands are referred to by ID.
58
+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
59
+ #[ derive( TyEncodable , TyDecodable , Hash , HashStable , TypeFoldable , TypeVisitable ) ]
60
+ pub enum Operand {
61
+ Zero ,
62
+ Counter ( CounterValueReference ) ,
63
+ Expression ( InjectedExpressionId ) ,
89
64
}
90
65
91
- impl From < InjectedExpressionId > for ExpressionOperandId {
92
- #[ inline]
93
- fn from ( v : InjectedExpressionId ) -> ExpressionOperandId {
94
- ExpressionOperandId :: from ( v. as_u32 ( ) )
66
+ impl Debug for Operand {
67
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
68
+ match self {
69
+ Self :: Zero => write ! ( f, "Zero" ) ,
70
+ Self :: Counter ( id) => f. debug_tuple ( "Counter" ) . field ( & id. as_u32 ( ) ) . finish ( ) ,
71
+ Self :: Expression ( id) => f. debug_tuple ( "Expression" ) . field ( & id. as_u32 ( ) ) . finish ( ) ,
72
+ }
95
73
}
96
74
}
97
75
@@ -107,19 +85,19 @@ pub enum CoverageKind {
107
85
/// ID of this coverage-counter expression within its enclosing function.
108
86
/// Other expressions in the same function can refer to it as an operand.
109
87
id : InjectedExpressionId ,
110
- lhs : ExpressionOperandId ,
88
+ lhs : Operand ,
111
89
op : Op ,
112
- rhs : ExpressionOperandId ,
90
+ rhs : Operand ,
113
91
} ,
114
92
Unreachable ,
115
93
}
116
94
117
95
impl CoverageKind {
118
- pub fn as_operand_id ( & self ) -> ExpressionOperandId {
96
+ pub fn as_operand ( & self ) -> Operand {
119
97
use CoverageKind :: * ;
120
98
match * self {
121
- Counter { id, .. } => ExpressionOperandId :: from ( id) ,
122
- Expression { id, .. } => ExpressionOperandId :: from ( id) ,
99
+ Counter { id, .. } => Operand :: Counter ( id) ,
100
+ Expression { id, .. } => Operand :: Expression ( id) ,
123
101
Unreachable => bug ! ( "Unreachable coverage cannot be part of an expression" ) ,
124
102
}
125
103
}
@@ -136,14 +114,14 @@ impl Debug for CoverageKind {
136
114
Counter { id, .. } => write ! ( fmt, "Counter({:?})" , id. index( ) ) ,
137
115
Expression { id, lhs, op, rhs } => write ! (
138
116
fmt,
139
- "Expression({:?}) = {} {} {}" ,
117
+ "Expression({:?}) = {:? } {} {:? }" ,
140
118
id. index( ) ,
141
- lhs. index ( ) ,
119
+ lhs,
142
120
match op {
143
121
Op :: Add => "+" ,
144
122
Op :: Subtract => "-" ,
145
123
} ,
146
- rhs. index ( ) ,
124
+ rhs,
147
125
) ,
148
126
Unreachable => write ! ( fmt, "Unreachable" ) ,
149
127
}
0 commit comments