@@ -12,7 +12,7 @@ use std::fmt::{self, Debug};
1212
1313/// The coverage counter or counter expression associated with a particular
1414/// BCB node or BCB edge.
15- #[ derive( Clone ) ]
15+ #[ derive( Clone , Copy ) ]
1616pub ( super ) enum BcbCounter {
1717 Counter { id : CounterId } ,
1818 Expression { id : ExpressionId } ,
@@ -88,8 +88,9 @@ impl CoverageCounters {
8888 BcbCounter :: Counter { id }
8989 }
9090
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) ;
9394 BcbCounter :: Expression { id }
9495 }
9596
@@ -109,7 +110,7 @@ impl CoverageCounters {
109110 self . expressions . len ( )
110111 }
111112
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 {
113114 assert ! (
114115 // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
115116 // have an expression (to be injected into an existing `BasicBlock` represented by this
@@ -118,14 +119,13 @@ impl CoverageCounters {
118119 "attempt to add a `Counter` to a BCB target with existing incoming edge counters"
119120 ) ;
120121
121- let term = counter_kind. as_term ( ) ;
122122 if let Some ( replaced) = self . bcb_counters [ bcb] . replace ( counter_kind) {
123123 bug ! (
124124 "attempt to set a BasicCoverageBlock coverage counter more than once; \
125125 {bcb:?} already had counter {replaced:?}",
126126 ) ;
127127 } else {
128- term
128+ counter_kind
129129 }
130130 }
131131
@@ -134,7 +134,7 @@ impl CoverageCounters {
134134 from_bcb : BasicCoverageBlock ,
135135 to_bcb : BasicCoverageBlock ,
136136 counter_kind : BcbCounter ,
137- ) -> CovTerm {
137+ ) -> BcbCounter {
138138 // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
139139 // have an expression (to be injected into an existing `BasicBlock` represented by this
140140 // `BasicCoverageBlock`).
@@ -148,14 +148,13 @@ impl CoverageCounters {
148148 }
149149
150150 self . bcb_has_incoming_edge_counters . insert ( to_bcb) ;
151- let term = counter_kind. as_term ( ) ;
152151 if let Some ( replaced) = self . bcb_edge_counters . insert ( ( from_bcb, to_bcb) , counter_kind) {
153152 bug ! (
154153 "attempt to set an edge counter more than once; from_bcb: \
155154 {from_bcb:?} already had counter {replaced:?}",
156155 ) ;
157156 } else {
158- term
157+ counter_kind
159158 }
160159 }
161160
@@ -305,8 +304,7 @@ impl<'a> MakeBcbCounters<'a> {
305304 sumup_counter_operand,
306305 ) ;
307306 debug ! ( " [new intermediate expression: {:?}]" , intermediate_expression) ;
308- let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
309- some_sumup_counter_operand. replace ( intermediate_expression_operand) ;
307+ some_sumup_counter_operand. replace ( intermediate_expression) ;
310308 }
311309 }
312310 }
@@ -336,11 +334,11 @@ impl<'a> MakeBcbCounters<'a> {
336334 }
337335
338336 #[ instrument( level = "debug" , skip( self ) ) ]
339- fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> CovTerm {
337+ fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> BcbCounter {
340338 // If the BCB already has a counter, return it.
341- if let Some ( counter_kind) = & self . coverage_counters . bcb_counters [ bcb] {
339+ if let Some ( counter_kind) = self . coverage_counters . bcb_counters [ bcb] {
342340 debug ! ( "{bcb:?} already has a counter: {counter_kind:?}" ) ;
343- return counter_kind. as_term ( ) ;
341+ return counter_kind;
344342 }
345343
346344 // A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
@@ -382,8 +380,7 @@ impl<'a> MakeBcbCounters<'a> {
382380 edge_counter_operand,
383381 ) ;
384382 debug ! ( "new intermediate expression: {intermediate_expression:?}" ) ;
385- let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
386- some_sumup_edge_counter_operand. replace ( intermediate_expression_operand) ;
383+ some_sumup_edge_counter_operand. replace ( intermediate_expression) ;
387384 }
388385 }
389386 let counter_kind = self . coverage_counters . make_expression (
@@ -402,7 +399,7 @@ impl<'a> MakeBcbCounters<'a> {
402399 & mut self ,
403400 from_bcb : BasicCoverageBlock ,
404401 to_bcb : BasicCoverageBlock ,
405- ) -> CovTerm {
402+ ) -> BcbCounter {
406403 // If the source BCB has only one successor (assumed to be the given target), an edge
407404 // counter is unnecessary. Just get or make a counter for the source BCB.
408405 let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
@@ -411,11 +408,11 @@ impl<'a> MakeBcbCounters<'a> {
411408 }
412409
413410 // If the edge already has a counter, return it.
414- if let Some ( counter_kind) =
411+ if let Some ( & counter_kind) =
415412 self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
416413 {
417414 debug ! ( "Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}" ) ;
418- return counter_kind. as_term ( ) ;
415+ return counter_kind;
419416 }
420417
421418 // Make a new counter to count this edge.
0 commit comments