@@ -12,8 +12,6 @@ use rustc_middle::mir::coverage::*;
12
12
13
13
use std:: fmt:: { self , Debug } ;
14
14
15
- const NESTED_INDENT : & str = " " ;
16
-
17
15
/// The coverage counter or counter expression associated with a particular
18
16
/// BCB node or BCB edge.
19
17
#[ derive( Clone ) ]
@@ -347,22 +345,17 @@ impl<'a> MakeBcbCounters<'a> {
347
345
}
348
346
349
347
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)
351
349
}
352
350
351
+ #[ instrument( level = "debug" , skip( self ) ) ]
353
352
fn recursive_get_or_make_counter_operand (
354
353
& mut self ,
355
354
bcb : BasicCoverageBlock ,
356
- debug_indent_level : usize ,
357
355
) -> Result < CovTerm , Error > {
358
356
// If the BCB already has a counter, return it.
359
357
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:?}" ) ;
366
359
return Ok ( counter_kind. as_term ( ) ) ;
367
360
}
368
361
@@ -373,20 +366,12 @@ impl<'a> MakeBcbCounters<'a> {
373
366
if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
374
367
let counter_kind = self . coverage_counters . make_counter ( ) ;
375
368
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:?}" ) ;
382
370
} else {
383
371
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.)",
390
375
) ;
391
376
}
392
377
return self . coverage_counters . set_bcb_counter ( bcb, counter_kind) ;
@@ -397,23 +382,13 @@ impl<'a> MakeBcbCounters<'a> {
397
382
// counters for those incoming edges first, then call `make_expression()` to sum them up,
398
383
// with additional intermediate expressions as needed.
399
384
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) ?;
410
388
let mut some_sumup_edge_counter_operand = None ;
411
389
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) ?;
417
392
if let Some ( sumup_edge_counter_operand) =
418
393
some_sumup_edge_counter_operand. replace ( edge_counter_operand)
419
394
{
@@ -422,11 +397,7 @@ impl<'a> MakeBcbCounters<'a> {
422
397
Op :: Add ,
423
398
edge_counter_operand,
424
399
) ;
425
- debug ! (
426
- "{}new intermediate expression: {:?}" ,
427
- NESTED_INDENT . repeat( debug_indent_level) ,
428
- intermediate_expression
429
- ) ;
400
+ debug ! ( "new intermediate expression: {intermediate_expression:?}" ) ;
430
401
let intermediate_expression_operand = intermediate_expression. as_term ( ) ;
431
402
some_sumup_edge_counter_operand. replace ( intermediate_expression_operand) ;
432
403
}
@@ -436,12 +407,7 @@ impl<'a> MakeBcbCounters<'a> {
436
407
Op :: Add ,
437
408
some_sumup_edge_counter_operand. unwrap ( ) ,
438
409
) ;
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:?}" ) ;
445
411
self . coverage_counters . set_bcb_counter ( bcb, counter_kind)
446
412
}
447
413
@@ -450,45 +416,33 @@ impl<'a> MakeBcbCounters<'a> {
450
416
from_bcb : BasicCoverageBlock ,
451
417
to_bcb : BasicCoverageBlock ,
452
418
) -> 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)
454
420
}
455
421
422
+ #[ instrument( level = "debug" , skip( self ) ) ]
456
423
fn recursive_get_or_make_edge_counter_operand (
457
424
& mut self ,
458
425
from_bcb : BasicCoverageBlock ,
459
426
to_bcb : BasicCoverageBlock ,
460
- debug_indent_level : usize ,
461
427
) -> Result < CovTerm , Error > {
462
428
// If the source BCB has only one successor (assumed to be the given target), an edge
463
429
// counter is unnecessary. Just get or make a counter for the source BCB.
464
430
let successors = self . bcb_successors ( from_bcb) . iter ( ) ;
465
431
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) ;
467
433
}
468
434
469
435
// If the edge already has a counter, return it.
470
436
if let Some ( counter_kind) =
471
437
self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
472
438
{
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:?}" ) ;
480
440
return Ok ( counter_kind. as_term ( ) ) ;
481
441
}
482
442
483
443
// Make a new counter to count this edge.
484
444
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:?}" ) ;
492
446
self . coverage_counters . set_bcb_edge_counter ( from_bcb, to_bcb, counter_kind)
493
447
}
494
448
0 commit comments