@@ -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 ) ]
@@ -346,23 +344,11 @@ impl<'a> MakeBcbCounters<'a> {
346344 Ok ( ( ) )
347345 }
348346
347+ #[ instrument( level = "debug" , skip( self ) ) ]
349348 fn get_or_make_counter_operand ( & mut self , bcb : BasicCoverageBlock ) -> Result < CovTerm , Error > {
350- self . recursive_get_or_make_counter_operand ( bcb, 1 )
351- }
352-
353- fn recursive_get_or_make_counter_operand (
354- & mut self ,
355- bcb : BasicCoverageBlock ,
356- debug_indent_level : usize ,
357- ) -> Result < CovTerm , Error > {
358349 // If the BCB already has a counter, return it.
359350 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- ) ;
351+ debug ! ( "{bcb:?} already has a counter: {counter_kind:?}" ) ;
366352 return Ok ( counter_kind. as_term ( ) ) ;
367353 }
368354
@@ -373,20 +359,12 @@ impl<'a> MakeBcbCounters<'a> {
373359 if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
374360 let counter_kind = self . coverage_counters . make_counter ( ) ;
375361 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- ) ;
362+ debug ! ( "{bcb:?} gets a new counter: {counter_kind:?}" ) ;
382363 } else {
383364 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,
365+ "{bcb:?} has itself as its own predecessor. It can't be part of its own \
366+ Expression sum, so it will get its own new counter: {counter_kind:?}. \
367+ (Note, the compiled code will generate an infinite loop.)",
390368 ) ;
391369 }
392370 return self . coverage_counters . set_bcb_counter ( bcb, counter_kind) ;
@@ -396,24 +374,14 @@ impl<'a> MakeBcbCounters<'a> {
396374 // counters and/or expressions of its incoming edges. This will recursively get or create
397375 // counters for those incoming edges first, then call `make_expression()` to sum them up,
398376 // with additional intermediate expressions as needed.
377+ let _sumup_debug_span = debug_span ! ( "(preparing sum-up expression)" ) . entered ( ) ;
378+
399379 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- ) ?;
380+ let first_edge_counter_operand =
381+ self . get_or_make_edge_counter_operand ( predecessors. next ( ) . unwrap ( ) , bcb) ?;
410382 let mut some_sumup_edge_counter_operand = None ;
411383 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- ) ?;
384+ let edge_counter_operand = self . get_or_make_edge_counter_operand ( predecessor, bcb) ?;
417385 if let Some ( sumup_edge_counter_operand) =
418386 some_sumup_edge_counter_operand. replace ( edge_counter_operand)
419387 {
@@ -422,11 +390,7 @@ impl<'a> MakeBcbCounters<'a> {
422390 Op :: Add ,
423391 edge_counter_operand,
424392 ) ;
425- debug ! (
426- "{}new intermediate expression: {:?}" ,
427- NESTED_INDENT . repeat( debug_indent_level) ,
428- intermediate_expression
429- ) ;
393+ debug ! ( "new intermediate expression: {intermediate_expression:?}" ) ;
430394 let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
431395 some_sumup_edge_counter_operand. replace ( intermediate_expression_operand) ;
432396 }
@@ -436,59 +400,36 @@ impl<'a> MakeBcbCounters<'a> {
436400 Op :: Add ,
437401 some_sumup_edge_counter_operand. unwrap ( ) ,
438402 ) ;
439- debug ! (
440- "{}{:?} gets a new counter (sum of predecessor counters): {:?}" ,
441- NESTED_INDENT . repeat( debug_indent_level) ,
442- bcb,
443- counter_kind
444- ) ;
403+ drop ( _sumup_debug_span) ;
404+
405+ debug ! ( "{bcb:?} gets a new counter (sum of predecessor counters): {counter_kind:?}" ) ;
445406 self . coverage_counters . set_bcb_counter ( bcb, counter_kind)
446407 }
447408
409+ #[ instrument( level = "debug" , skip( self ) ) ]
448410 fn get_or_make_edge_counter_operand (
449411 & mut self ,
450412 from_bcb : BasicCoverageBlock ,
451413 to_bcb : BasicCoverageBlock ,
452- ) -> Result < CovTerm , Error > {
453- self . recursive_get_or_make_edge_counter_operand ( from_bcb, to_bcb, 1 )
454- }
455-
456- fn recursive_get_or_make_edge_counter_operand (
457- & mut self ,
458- from_bcb : BasicCoverageBlock ,
459- to_bcb : BasicCoverageBlock ,
460- debug_indent_level : usize ,
461414 ) -> Result < CovTerm , Error > {
462415 // If the source BCB has only one successor (assumed to be the given target), an edge
463416 // counter is unnecessary. Just get or make a counter for the source BCB.
464417 let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
465418 if successors. len ( ) == 1 {
466- return self . recursive_get_or_make_counter_operand ( from_bcb, debug_indent_level + 1 ) ;
419+ return self . get_or_make_counter_operand ( from_bcb) ;
467420 }
468421
469422 // If the edge already has a counter, return it.
470423 if let Some ( counter_kind) =
471424 self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
472425 {
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- ) ;
426+ debug ! ( "Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}" ) ;
480427 return Ok ( counter_kind. as_term ( ) ) ;
481428 }
482429
483430 // Make a new counter to count this edge.
484431 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- ) ;
432+ debug ! ( "Edge {from_bcb:?}->{to_bcb:?} gets a new counter: {counter_kind:?}" ) ;
492433 self . coverage_counters . set_bcb_edge_counter ( from_bcb, to_bcb, counter_kind)
493434 }
494435
0 commit comments