1- use super :: Error ;
2-
31use super :: graph;
42
53use graph:: { BasicCoverageBlock , BcbBranch , CoverageGraph , TraverseCoverageGraphWithLoops } ;
@@ -81,7 +79,7 @@ impl CoverageCounters {
8179 & mut self ,
8280 basic_coverage_blocks : & CoverageGraph ,
8381 bcb_has_coverage_spans : impl Fn ( BasicCoverageBlock ) -> bool ,
84- ) -> Result < ( ) , Error > {
82+ ) {
8583 MakeBcbCounters :: new ( self , basic_coverage_blocks) . make_bcb_counters ( bcb_has_coverage_spans)
8684 }
8785
@@ -111,11 +109,7 @@ impl CoverageCounters {
111109 self . expressions . len ( )
112110 }
113111
114- fn set_bcb_counter (
115- & mut self ,
116- bcb : BasicCoverageBlock ,
117- counter_kind : BcbCounter ,
118- ) -> Result < CovTerm , Error > {
112+ fn set_bcb_counter ( & mut self , bcb : BasicCoverageBlock , counter_kind : BcbCounter ) -> CovTerm {
119113 assert ! (
120114 // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
121115 // have an expression (to be injected into an existing `BasicBlock` represented by this
@@ -126,12 +120,12 @@ impl CoverageCounters {
126120
127121 let term = counter_kind. as_term ( ) ;
128122 if let Some ( replaced) = self . bcb_counters [ bcb] . replace ( counter_kind) {
129- Error :: from_string ( format ! (
123+ bug ! (
130124 "attempt to set a BasicCoverageBlock coverage counter more than once; \
131125 {bcb:?} already had counter {replaced:?}",
132- ) )
126+ ) ;
133127 } else {
134- Ok ( term)
128+ term
135129 }
136130 }
137131
@@ -140,26 +134,26 @@ impl CoverageCounters {
140134 from_bcb : BasicCoverageBlock ,
141135 to_bcb : BasicCoverageBlock ,
142136 counter_kind : BcbCounter ,
143- ) -> Result < CovTerm , Error > {
137+ ) -> CovTerm {
144138 // If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
145139 // have an expression (to be injected into an existing `BasicBlock` represented by this
146140 // `BasicCoverageBlock`).
147- if let Some ( c ) = self . bcb_counter ( to_bcb) && !c . is_expression ( ) {
148- return Error :: from_string ( format ! (
141+ if let Some ( counter ) = self . bcb_counter ( to_bcb) && !counter . is_expression ( ) {
142+ bug ! (
149143 "attempt to add an incoming edge counter from {from_bcb:?} \
150- when the target BCB already has {c :?}"
151- ) ) ;
144+ when the target BCB already has {counter :?}"
145+ ) ;
152146 }
153147
154148 self . bcb_has_incoming_edge_counters . insert ( to_bcb) ;
155149 let term = counter_kind. as_term ( ) ;
156150 if let Some ( replaced) = self . bcb_edge_counters . insert ( ( from_bcb, to_bcb) , counter_kind) {
157- Error :: from_string ( format ! (
151+ bug ! (
158152 "attempt to set an edge counter more than once; from_bcb: \
159153 {from_bcb:?} already had counter {replaced:?}",
160- ) )
154+ ) ;
161155 } else {
162- Ok ( term)
156+ term
163157 }
164158 }
165159
@@ -213,14 +207,7 @@ impl<'a> MakeBcbCounters<'a> {
213207 /// One way to predict which branch executes the least is by considering loops. A loop is exited
214208 /// at a branch, so the branch that jumps to a `BasicCoverageBlock` outside the loop is almost
215209 /// always executed less than the branch that does not exit the loop.
216- ///
217- /// Returns any non-code-span expressions created to represent intermediate values (such as to
218- /// add two counters so the result can be subtracted from another counter), or an Error with
219- /// message for subsequent debugging.
220- fn make_bcb_counters (
221- & mut self ,
222- bcb_has_coverage_spans : impl Fn ( BasicCoverageBlock ) -> bool ,
223- ) -> Result < ( ) , Error > {
210+ fn make_bcb_counters ( & mut self , bcb_has_coverage_spans : impl Fn ( BasicCoverageBlock ) -> bool ) {
224211 debug ! ( "make_bcb_counters(): adding a counter or expression to each BasicCoverageBlock" ) ;
225212
226213 // Walk the `CoverageGraph`. For each `BasicCoverageBlock` node with an associated
@@ -237,10 +224,10 @@ impl<'a> MakeBcbCounters<'a> {
237224 while let Some ( bcb) = traversal. next ( ) {
238225 if bcb_has_coverage_spans ( bcb) {
239226 debug ! ( "{:?} has at least one coverage span. Get or make its counter" , bcb) ;
240- let branching_counter_operand = self . get_or_make_counter_operand ( bcb) ? ;
227+ let branching_counter_operand = self . get_or_make_counter_operand ( bcb) ;
241228
242229 if self . bcb_needs_branch_counters ( bcb) {
243- self . make_branch_counters ( & traversal, bcb, branching_counter_operand) ? ;
230+ self . make_branch_counters ( & traversal, bcb, branching_counter_operand) ;
244231 }
245232 } else {
246233 debug ! (
@@ -251,22 +238,19 @@ impl<'a> MakeBcbCounters<'a> {
251238 }
252239 }
253240
254- if traversal. is_complete ( ) {
255- Ok ( ( ) )
256- } else {
257- Error :: from_string ( format ! (
258- "`TraverseCoverageGraphWithLoops` missed some `BasicCoverageBlock`s: {:?}" ,
259- traversal. unvisited( ) ,
260- ) )
261- }
241+ assert ! (
242+ traversal. is_complete( ) ,
243+ "`TraverseCoverageGraphWithLoops` missed some `BasicCoverageBlock`s: {:?}" ,
244+ traversal. unvisited( ) ,
245+ ) ;
262246 }
263247
264248 fn make_branch_counters (
265249 & mut self ,
266250 traversal : & TraverseCoverageGraphWithLoops < ' _ > ,
267251 branching_bcb : BasicCoverageBlock ,
268252 branching_counter_operand : CovTerm ,
269- ) -> Result < ( ) , Error > {
253+ ) {
270254 let branches = self . bcb_branches ( branching_bcb) ;
271255 debug ! (
272256 "{:?} has some branch(es) without counters:\n {}" ,
@@ -299,10 +283,10 @@ impl<'a> MakeBcbCounters<'a> {
299283 counter",
300284 branch, branching_bcb
301285 ) ;
302- self . get_or_make_counter_operand ( branch. target_bcb ) ?
286+ self . get_or_make_counter_operand ( branch. target_bcb )
303287 } else {
304288 debug ! ( " {:?} has multiple incoming edges, so adding an edge counter" , branch) ;
305- self . get_or_make_edge_counter_operand ( branching_bcb, branch. target_bcb ) ?
289+ self . get_or_make_edge_counter_operand ( branching_bcb, branch. target_bcb )
306290 } ;
307291 if let Some ( sumup_counter_operand) =
308292 some_sumup_counter_operand. replace ( branch_counter_operand)
@@ -337,19 +321,18 @@ impl<'a> MakeBcbCounters<'a> {
337321 debug ! ( "{:?} gets an expression: {:?}" , expression_branch, expression) ;
338322 let bcb = expression_branch. target_bcb ;
339323 if expression_branch. is_only_path_to_target ( ) {
340- self . coverage_counters . set_bcb_counter ( bcb, expression) ? ;
324+ self . coverage_counters . set_bcb_counter ( bcb, expression) ;
341325 } else {
342- self . coverage_counters . set_bcb_edge_counter ( branching_bcb, bcb, expression) ? ;
326+ self . coverage_counters . set_bcb_edge_counter ( branching_bcb, bcb, expression) ;
343327 }
344- Ok ( ( ) )
345328 }
346329
347330 #[ instrument( level = "debug" , skip( self ) ) ]
348- fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> Result < CovTerm , Error > {
331+ fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> CovTerm {
349332 // If the BCB already has a counter, return it.
350333 if let Some ( counter_kind) = & self . coverage_counters . bcb_counters [ bcb] {
351334 debug ! ( "{bcb:?} already has a counter: {counter_kind:?}" ) ;
352- return Ok ( counter_kind. as_term ( ) ) ;
335+ return counter_kind. as_term ( ) ;
353336 }
354337
355338 // A BCB with only one incoming edge gets a simple `Counter` (via `make_counter()`).
@@ -378,10 +361,10 @@ impl<'a> MakeBcbCounters<'a> {
378361
379362 let mut predecessors = self . bcb_predecessors ( bcb) . to_owned ( ) . into_iter ( ) ;
380363 let first_edge_counter_operand =
381- self . get_or_make_edge_counter_operand ( predecessors. next ( ) . unwrap ( ) , bcb) ? ;
364+ self . get_or_make_edge_counter_operand ( predecessors. next ( ) . unwrap ( ) , bcb) ;
382365 let mut some_sumup_edge_counter_operand = None ;
383366 for predecessor in predecessors {
384- let edge_counter_operand = self . get_or_make_edge_counter_operand ( predecessor, bcb) ? ;
367+ let edge_counter_operand = self . get_or_make_edge_counter_operand ( predecessor, bcb) ;
385368 if let Some ( sumup_edge_counter_operand) =
386369 some_sumup_edge_counter_operand. replace ( edge_counter_operand)
387370 {
@@ -411,7 +394,7 @@ impl<'a> MakeBcbCounters<'a> {
411394 & mut self ,
412395 from_bcb : BasicCoverageBlock ,
413396 to_bcb : BasicCoverageBlock ,
414- ) -> Result < CovTerm , Error > {
397+ ) -> CovTerm {
415398 // If the source BCB has only one successor (assumed to be the given target), an edge
416399 // counter is unnecessary. Just get or make a counter for the source BCB.
417400 let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
@@ -424,7 +407,7 @@ impl<'a> MakeBcbCounters<'a> {
424407 self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
425408 {
426409 debug ! ( "Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}" ) ;
427- return Ok ( counter_kind. as_term ( ) ) ;
410+ return counter_kind. as_term ( ) ;
428411 }
429412
430413 // Make a new counter to count this edge.
0 commit comments