@@ -12,8 +12,6 @@ use rustc_middle::mir::coverage::*;
1212
1313use std:: fmt:: { self , Debug } ;
1414
15- const NESTED_INDENT : & str = " " ;
16-
1715/// The coverage counter or counter expression associated with a particular
1816/// BCB node or BCB edge.
1917#[ derive( Clone ) ]
@@ -347,22 +345,17 @@ impl<'a> MakeBcbCounters<'a> {
347345 }
348346
349347 fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> Result < CovTerm , Error > {
350- self . recursive_get_or_make_counter_operand ( bcb, 1 )
348+ self . recursive_get_or_make_counter_operand ( bcb)
351349 }
352350
351+ #[ instrument( level = "debug" , skip( self ) ) ]
353352 fn recursive_get_or_make_counter_operand (
354353 & mut self ,
355354 bcb : BasicCoverageBlock ,
356- debug_indent_level : usize ,
357355 ) -> Result < CovTerm , Error > {
358356 // If the BCB already has a counter, return it.
359357 if let Some ( counter_kind) = & self . coverage_counters . bcb_counters [ bcb] {
360- debug ! (
361- "{}{:?} already has a counter: {:?}" ,
362- NESTED_INDENT . repeat( debug_indent_level) ,
363- bcb,
364- counter_kind,
365- ) ;
358+ debug ! ( "{bcb:?} already has a counter: {counter_kind:?}" ) ;
366359 return Ok ( counter_kind. as_term ( ) ) ;
367360 }
368361
@@ -373,20 +366,12 @@ impl<'a> MakeBcbCounters<'a> {
373366 if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
374367 let counter_kind = self . coverage_counters . make_counter ( ) ;
375368 if one_path_to_target {
376- debug ! (
377- "{}{:?} gets a new counter: {:?}" ,
378- NESTED_INDENT . repeat( debug_indent_level) ,
379- bcb,
380- counter_kind,
381- ) ;
369+ debug ! ( "{bcb:?} gets a new counter: {counter_kind:?}" ) ;
382370 } else {
383371 debug ! (
384- "{}{:?} has itself as its own predecessor. It can't be part of its own \
385- Expression sum, so it will get its own new counter: {:?}. (Note, the compiled \
386- code will generate an infinite loop.)",
387- NESTED_INDENT . repeat( debug_indent_level) ,
388- bcb,
389- counter_kind,
372+ "{bcb:?} has itself as its own predecessor. It can't be part of its own \
373+ Expression sum, so it will get its own new counter: {counter_kind:?}. \
374+ (Note, the compiled code will generate an infinite loop.)",
390375 ) ;
391376 }
392377 return self . coverage_counters . set_bcb_counter ( bcb, counter_kind) ;
@@ -397,23 +382,13 @@ impl<'a> MakeBcbCounters<'a> {
397382 // counters for those incoming edges first, then call `make_expression()` to sum them up,
398383 // with additional intermediate expressions as needed.
399384 let mut predecessors = self . bcb_predecessors ( bcb) . to_owned ( ) . into_iter ( ) ;
400- debug ! (
401- "{}{:?} has multiple incoming edges and will get an expression that sums them up..." ,
402- NESTED_INDENT . repeat( debug_indent_level) ,
403- bcb,
404- ) ;
405- let first_edge_counter_operand = self . recursive_get_or_make_edge_counter_operand (
406- predecessors. next ( ) . unwrap ( ) ,
407- bcb,
408- debug_indent_level + 1 ,
409- ) ?;
385+ debug ! ( "{bcb:?} has multiple incoming edges and will need a sum-up expression" ) ;
386+ let first_edge_counter_operand =
387+ self . recursive_get_or_make_edge_counter_operand ( predecessors. next ( ) . unwrap ( ) , bcb) ?;
410388 let mut some_sumup_edge_counter_operand = None ;
411389 for predecessor in predecessors {
412- let edge_counter_operand = self . recursive_get_or_make_edge_counter_operand (
413- predecessor,
414- bcb,
415- debug_indent_level + 1 ,
416- ) ?;
390+ let edge_counter_operand =
391+ self . recursive_get_or_make_edge_counter_operand ( predecessor, bcb) ?;
417392 if let Some ( sumup_edge_counter_operand) =
418393 some_sumup_edge_counter_operand. replace ( edge_counter_operand)
419394 {
@@ -422,11 +397,7 @@ impl<'a> MakeBcbCounters<'a> {
422397 Op :: Add ,
423398 edge_counter_operand,
424399 ) ;
425- debug ! (
426- "{}new intermediate expression: {:?}" ,
427- NESTED_INDENT . repeat( debug_indent_level) ,
428- intermediate_expression
429- ) ;
400+ debug ! ( "new intermediate expression: {intermediate_expression:?}" ) ;
430401 let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
431402 some_sumup_edge_counter_operand. replace ( intermediate_expression_operand) ;
432403 }
@@ -436,12 +407,7 @@ impl<'a> MakeBcbCounters<'a> {
436407 Op :: Add ,
437408 some_sumup_edge_counter_operand. unwrap ( ) ,
438409 ) ;
439- debug ! (
440- "{}{:?} gets a new counter (sum of predecessor counters): {:?}" ,
441- NESTED_INDENT . repeat( debug_indent_level) ,
442- bcb,
443- counter_kind
444- ) ;
410+ debug ! ( "{bcb:?} gets a new counter (sum of predecessor counters): {counter_kind:?}" ) ;
445411 self . coverage_counters . set_bcb_counter ( bcb, counter_kind)
446412 }
447413
@@ -450,45 +416,33 @@ impl<'a> MakeBcbCounters<'a> {
450416 from_bcb : BasicCoverageBlock ,
451417 to_bcb : BasicCoverageBlock ,
452418 ) -> Result < CovTerm , Error > {
453- self . recursive_get_or_make_edge_counter_operand ( from_bcb, to_bcb, 1 )
419+ self . recursive_get_or_make_edge_counter_operand ( from_bcb, to_bcb)
454420 }
455421
422+ #[ instrument( level = "debug" , skip( self ) ) ]
456423 fn recursive_get_or_make_edge_counter_operand (
457424 & mut self ,
458425 from_bcb : BasicCoverageBlock ,
459426 to_bcb : BasicCoverageBlock ,
460- debug_indent_level : usize ,
461427 ) -> Result < CovTerm , Error > {
462428 // If the source BCB has only one successor (assumed to be the given target), an edge
463429 // counter is unnecessary. Just get or make a counter for the source BCB.
464430 let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
465431 if successors. len ( ) == 1 {
466- return self . recursive_get_or_make_counter_operand ( from_bcb, debug_indent_level + 1 ) ;
432+ return self . recursive_get_or_make_counter_operand ( from_bcb) ;
467433 }
468434
469435 // If the edge already has a counter, return it.
470436 if let Some ( counter_kind) =
471437 self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
472438 {
473- debug ! (
474- "{}Edge {:?}->{:?} already has a counter: {:?}" ,
475- NESTED_INDENT . repeat( debug_indent_level) ,
476- from_bcb,
477- to_bcb,
478- counter_kind
479- ) ;
439+ debug ! ( "Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}" ) ;
480440 return Ok ( counter_kind. as_term ( ) ) ;
481441 }
482442
483443 // Make a new counter to count this edge.
484444 let counter_kind = self . coverage_counters . make_counter ( ) ;
485- debug ! (
486- "{}Edge {:?}->{:?} gets a new counter: {:?}" ,
487- NESTED_INDENT . repeat( debug_indent_level) ,
488- from_bcb,
489- to_bcb,
490- counter_kind
491- ) ;
445+ debug ! ( "Edge {from_bcb:?}->{to_bcb:?} gets a new counter: {counter_kind:?}" ) ;
492446 self . coverage_counters . set_bcb_edge_counter ( from_bcb, to_bcb, counter_kind)
493447 }
494448
0 commit comments