@@ -34,6 +34,13 @@ impl Debug for BcbCounter {
3434 }
3535}
3636
37+ #[ derive( Debug ) ]
38+ struct BcbExpression {
39+ lhs : BcbCounter ,
40+ op : Op ,
41+ rhs : BcbCounter ,
42+ }
43+
3744#[ derive( Debug ) ]
3845pub ( super ) enum CounterIncrementSite {
3946 Node { bcb : BasicCoverageBlock } ,
@@ -57,7 +64,7 @@ pub(super) struct CoverageCounters {
5764 bcb_edge_counters : FxHashMap < ( BasicCoverageBlock , BasicCoverageBlock ) , BcbCounter > ,
5865 /// Table of expression data, associating each expression ID with its
5966 /// corresponding operator (+ or -) and its LHS/RHS operands.
60- expressions : IndexVec < ExpressionId , Expression > ,
67+ expressions : IndexVec < ExpressionId , BcbExpression > ,
6168}
6269
6370impl CoverageCounters {
@@ -89,8 +96,7 @@ impl CoverageCounters {
8996 }
9097
9198 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 } ) ;
94100 BcbCounter :: Expression { id }
95101 }
96102
@@ -165,7 +171,21 @@ impl CoverageCounters {
165171 }
166172
167173 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
169189 }
170190}
171191
0 commit comments