@@ -34,6 +34,13 @@ impl Debug for BcbCounter {
34
34
}
35
35
}
36
36
37
+ #[ derive( Debug ) ]
38
+ struct BcbExpression {
39
+ lhs : BcbCounter ,
40
+ op : Op ,
41
+ rhs : BcbCounter ,
42
+ }
43
+
37
44
#[ derive( Debug ) ]
38
45
pub ( super ) enum CounterIncrementSite {
39
46
Node { bcb : BasicCoverageBlock } ,
@@ -57,7 +64,7 @@ pub(super) struct CoverageCounters {
57
64
bcb_edge_counters : FxHashMap < ( BasicCoverageBlock , BasicCoverageBlock ) , BcbCounter > ,
58
65
/// Table of expression data, associating each expression ID with its
59
66
/// corresponding operator (+ or -) and its LHS/RHS operands.
60
- expressions : IndexVec < ExpressionId , Expression > ,
67
+ expressions : IndexVec < ExpressionId , BcbExpression > ,
61
68
}
62
69
63
70
impl CoverageCounters {
@@ -89,8 +96,7 @@ impl CoverageCounters {
89
96
}
90
97
91
98
fn make_expression ( & mut self , lhs : BcbCounter , op : Op , rhs : BcbCounter ) -> BcbCounter {
92
- let expression = Expression { lhs : lhs. as_term ( ) , op, rhs : rhs. as_term ( ) } ;
93
- let id = self . expressions . push ( expression) ;
99
+ let id = self . expressions . push ( BcbExpression { lhs, op, rhs } ) ;
94
100
BcbCounter :: Expression { id }
95
101
}
96
102
@@ -165,7 +171,21 @@ impl CoverageCounters {
165
171
}
166
172
167
173
pub ( super ) fn into_expressions ( self ) -> IndexVec < ExpressionId , Expression > {
168
- self . expressions
174
+ let old_len = self . expressions . len ( ) ;
175
+ let expressions = self
176
+ . expressions
177
+ . into_iter ( )
178
+ . map ( |BcbExpression { lhs, op, rhs } | Expression {
179
+ lhs : lhs. as_term ( ) ,
180
+ op,
181
+ rhs : rhs. as_term ( ) ,
182
+ } )
183
+ . collect :: < IndexVec < ExpressionId , _ > > ( ) ;
184
+
185
+ // Expression IDs are indexes into this vector, so make sure we didn't
186
+ // accidentally invalidate them by changing its length.
187
+ assert_eq ! ( old_len, expressions. len( ) ) ;
188
+ expressions
169
189
}
170
190
}
171
191
0 commit comments