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