@@ -12,7 +12,7 @@ use std::fmt::{self, Debug};
12
12
13
13
/// The coverage counter or counter expression associated with a particular
14
14
/// BCB node or BCB edge.
15
- #[ derive( Clone ) ]
15
+ #[ derive( Clone , Copy ) ]
16
16
pub ( super ) enum BcbCounter {
17
17
Counter { id : CounterId } ,
18
18
Expression { id : ExpressionId } ,
@@ -88,8 +88,9 @@ impl CoverageCounters {
88
88
BcbCounter :: Counter { id }
89
89
}
90
90
91
- fn make_expression ( & mut self , lhs : CovTerm , op : Op , rhs : CovTerm ) -> BcbCounter {
92
- let id = self . expressions . push ( Expression { lhs, op, rhs } ) ;
91
+ 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) ;
93
94
BcbCounter :: Expression { id }
94
95
}
95
96
@@ -109,7 +110,7 @@ impl CoverageCounters {
109
110
self . expressions . len ( )
110
111
}
111
112
112
- fn set_bcb_counter ( & mut self , bcb : BasicCoverageBlock , counter_kind : BcbCounter ) -> CovTerm {
113
+ fn set_bcb_counter ( & mut self , bcb : BasicCoverageBlock , counter_kind : BcbCounter ) -> BcbCounter {
113
114
assert ! (
114
115
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
115
116
// have an expression (to be injected into an existing `BasicBlock` represented by this
@@ -118,14 +119,13 @@ impl CoverageCounters {
118
119
"attempt to add a `Counter` to a BCB target with existing incoming edge counters"
119
120
) ;
120
121
121
- let term = counter_kind. as_term ( ) ;
122
122
if let Some ( replaced) = self . bcb_counters [ bcb] . replace ( counter_kind) {
123
123
bug ! (
124
124
"attempt to set a BasicCoverageBlock coverage counter more than once; \
125
125
{bcb:?} already had counter {replaced:?}",
126
126
) ;
127
127
} else {
128
- term
128
+ counter_kind
129
129
}
130
130
}
131
131
@@ -134,7 +134,7 @@ impl CoverageCounters {
134
134
from_bcb : BasicCoverageBlock ,
135
135
to_bcb : BasicCoverageBlock ,
136
136
counter_kind : BcbCounter ,
137
- ) -> CovTerm {
137
+ ) -> BcbCounter {
138
138
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
139
139
// have an expression (to be injected into an existing `BasicBlock` represented by this
140
140
// `BasicCoverageBlock`).
@@ -146,14 +146,13 @@ impl CoverageCounters {
146
146
}
147
147
148
148
self . bcb_has_incoming_edge_counters . insert ( to_bcb) ;
149
- let term = counter_kind. as_term ( ) ;
150
149
if let Some ( replaced) = self . bcb_edge_counters . insert ( ( from_bcb, to_bcb) , counter_kind) {
151
150
bug ! (
152
151
"attempt to set an edge counter more than once; from_bcb: \
153
152
{from_bcb:?} already had counter {replaced:?}",
154
153
) ;
155
154
} else {
156
- term
155
+ counter_kind
157
156
}
158
157
}
159
158
@@ -303,8 +302,7 @@ impl<'a> MakeBcbCounters<'a> {
303
302
sumup_counter_operand,
304
303
) ;
305
304
debug ! ( " [new intermediate expression: {:?}]" , intermediate_expression) ;
306
- let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
307
- some_sumup_counter_operand. replace ( intermediate_expression_operand) ;
305
+ some_sumup_counter_operand. replace ( intermediate_expression) ;
308
306
}
309
307
}
310
308
}
@@ -334,11 +332,11 @@ impl<'a> MakeBcbCounters<'a> {
334
332
}
335
333
336
334
#[ instrument( level = "debug" , skip( self ) ) ]
337
- fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> CovTerm {
335
+ fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> BcbCounter {
338
336
// If the BCB already has a counter, return it.
339
- if let Some ( counter_kind) = & self . coverage_counters . bcb_counters [ bcb] {
337
+ if let Some ( counter_kind) = self . coverage_counters . bcb_counters [ bcb] {
340
338
debug ! ( "{bcb:?} already has a counter: {counter_kind:?}" ) ;
341
- return counter_kind. as_term ( ) ;
339
+ return counter_kind;
342
340
}
343
341
344
342
// A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
@@ -380,8 +378,7 @@ impl<'a> MakeBcbCounters<'a> {
380
378
edge_counter_operand,
381
379
) ;
382
380
debug ! ( "new intermediate expression: {intermediate_expression:?}" ) ;
383
- let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
384
- some_sumup_edge_counter_operand. replace ( intermediate_expression_operand) ;
381
+ some_sumup_edge_counter_operand. replace ( intermediate_expression) ;
385
382
}
386
383
}
387
384
let counter_kind = self . coverage_counters . make_expression (
@@ -400,7 +397,7 @@ impl<'a> MakeBcbCounters<'a> {
400
397
& mut self ,
401
398
from_bcb : BasicCoverageBlock ,
402
399
to_bcb : BasicCoverageBlock ,
403
- ) -> CovTerm {
400
+ ) -> BcbCounter {
404
401
// If the source BCB has only one successor (assumed to be the given target), an edge
405
402
// counter is unnecessary. Just get or make a counter for the source BCB.
406
403
let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
@@ -409,11 +406,11 @@ impl<'a> MakeBcbCounters<'a> {
409
406
}
410
407
411
408
// If the edge already has a counter, return it.
412
- if let Some ( counter_kind) =
409
+ if let Some ( & counter_kind) =
413
410
self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
414
411
{
415
412
debug ! ( "Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}" ) ;
416
- return counter_kind. as_term ( ) ;
413
+ return counter_kind;
417
414
}
418
415
419
416
// Make a new counter to count this edge.
0 commit comments