Skip to content

Commit 1a3a54c

Browse files
committed
coverage: Store expression operands as BcbCounter
1 parent 9105c57 commit 1a3a54c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ impl Debug for BcbCounter {
3535
}
3636
}
3737

38+
#[derive(Debug)]
39+
struct BcbExpression {
40+
lhs: BcbCounter,
41+
op: Op,
42+
rhs: BcbCounter,
43+
}
44+
3845
#[derive(Debug)]
3946
pub(super) enum CounterIncrementSite {
4047
Node { bcb: BasicCoverageBlock },
@@ -58,7 +65,7 @@ pub(super) struct CoverageCounters {
5865
bcb_edge_counters: FxHashMap<(BasicCoverageBlock, BasicCoverageBlock), BcbCounter>,
5966
/// Table of expression data, associating each expression ID with its
6067
/// corresponding operator (+ or -) and its LHS/RHS operands.
61-
expressions: IndexVec<ExpressionId, Expression>,
68+
expressions: IndexVec<ExpressionId, BcbExpression>,
6269
}
6370

6471
impl CoverageCounters {
@@ -90,8 +97,7 @@ impl CoverageCounters {
9097
}
9198

9299
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 });
95101
BcbCounter::Expression { id }
96102
}
97103

@@ -166,7 +172,21 @@ impl CoverageCounters {
166172
}
167173

168174
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
170190
}
171191
}
172192

0 commit comments

Comments
 (0)