1
1
use super :: Error ;
2
2
3
- use super :: debug;
4
3
use super :: graph;
5
4
use super :: spans;
6
5
7
- use debug:: { DebugCounters , NESTED_INDENT } ;
8
6
use graph:: { BasicCoverageBlock , BcbBranch , CoverageGraph , TraverseCoverageGraphWithLoops } ;
9
7
use spans:: CoverageSpan ;
10
8
@@ -16,6 +14,8 @@ use rustc_middle::mir::coverage::*;
16
14
17
15
use std:: fmt:: { self , Debug } ;
18
16
17
+ const NESTED_INDENT : & str = " " ;
18
+
19
19
/// The coverage counter or counter expression associated with a particular
20
20
/// BCB node or BCB edge.
21
21
#[ derive( Clone ) ]
@@ -75,8 +75,6 @@ pub(super) struct CoverageCounters {
75
75
/// BCB/edge, but are needed as operands to more complex expressions.
76
76
/// These are always [`BcbCounter::Expression`].
77
77
pub ( super ) intermediate_expressions : Vec < BcbCounter > ,
78
-
79
- pub debug_counters : DebugCounters ,
80
78
}
81
79
82
80
impl CoverageCounters {
@@ -91,17 +89,9 @@ impl CoverageCounters {
91
89
bcb_edge_counters : FxHashMap :: default ( ) ,
92
90
bcb_has_incoming_edge_counters : BitSet :: new_empty ( num_bcbs) ,
93
91
intermediate_expressions : Vec :: new ( ) ,
94
-
95
- debug_counters : DebugCounters :: new ( ) ,
96
92
}
97
93
}
98
94
99
- /// Activate the `DebugCounters` data structures, to provide additional debug formatting
100
- /// features when formatting [`BcbCounter`] (counter) values.
101
- pub fn enable_debug ( & mut self ) {
102
- self . debug_counters . enable ( ) ;
103
- }
104
-
105
95
/// Makes [`BcbCounter`] `Counter`s and `Expressions` for the `BasicCoverageBlock`s directly or
106
96
/// indirectly associated with `CoverageSpans`, and accumulates additional `Expression`s
107
97
/// representing intermediate values.
@@ -113,44 +103,18 @@ impl CoverageCounters {
113
103
MakeBcbCounters :: new ( self , basic_coverage_blocks) . make_bcb_counters ( coverage_spans)
114
104
}
115
105
116
- fn make_counter < F > ( & mut self , debug_block_label_fn : F ) -> BcbCounter
117
- where
118
- F : Fn ( ) -> Option < String > ,
119
- {
120
- let counter = BcbCounter :: Counter { id : self . next_counter ( ) } ;
121
- if self . debug_counters . is_enabled ( ) {
122
- self . debug_counters . add_counter ( & counter, ( debug_block_label_fn) ( ) ) ;
123
- }
124
- counter
106
+ fn make_counter ( & mut self ) -> BcbCounter {
107
+ let id = self . next_counter ( ) ;
108
+ BcbCounter :: Counter { id }
125
109
}
126
110
127
- fn make_expression < F > (
128
- & mut self ,
129
- lhs : Operand ,
130
- op : Op ,
131
- rhs : Operand ,
132
- debug_block_label_fn : F ,
133
- ) -> BcbCounter
134
- where
135
- F : Fn ( ) -> Option < String > ,
136
- {
111
+ fn make_expression ( & mut self , lhs : Operand , op : Op , rhs : Operand ) -> BcbCounter {
137
112
let id = self . next_expression ( ) ;
138
- let expression = BcbCounter :: Expression { id, lhs, op, rhs } ;
139
- if self . debug_counters . is_enabled ( ) {
140
- self . debug_counters . add_counter ( & expression, ( debug_block_label_fn) ( ) ) ;
141
- }
142
- expression
113
+ BcbCounter :: Expression { id, lhs, op, rhs }
143
114
}
144
115
145
116
pub fn make_identity_counter ( & mut self , counter_operand : Operand ) -> BcbCounter {
146
- let some_debug_block_label = if self . debug_counters . is_enabled ( ) {
147
- self . debug_counters . some_block_label ( counter_operand) . cloned ( )
148
- } else {
149
- None
150
- } ;
151
- self . make_expression ( counter_operand, Op :: Add , Operand :: Zero , || {
152
- some_debug_block_label. clone ( )
153
- } )
117
+ self . make_expression ( counter_operand, Op :: Add , Operand :: Zero )
154
118
}
155
119
156
120
/// Counter IDs start from one and go up.
@@ -367,12 +331,8 @@ impl<'a> MakeBcbCounters<'a> {
367
331
branch_counter_operand,
368
332
Op :: Add ,
369
333
sumup_counter_operand,
370
- || None ,
371
- ) ;
372
- debug ! (
373
- " [new intermediate expression: {}]" ,
374
- self . format_counter( & intermediate_expression)
375
334
) ;
335
+ debug ! ( " [new intermediate expression: {:?}]" , intermediate_expression) ;
376
336
let intermediate_expression_operand = intermediate_expression. as_operand ( ) ;
377
337
self . coverage_counters . intermediate_expressions . push ( intermediate_expression) ;
378
338
some_sumup_counter_operand. replace ( intermediate_expression_operand) ;
@@ -394,9 +354,8 @@ impl<'a> MakeBcbCounters<'a> {
394
354
branching_counter_operand,
395
355
Op :: Subtract ,
396
356
sumup_counter_operand,
397
- || Some ( format ! ( "{expression_branch:?}" ) ) ,
398
357
) ;
399
- debug ! ( "{:?} gets an expression: {}" , expression_branch, self . format_counter ( & expression) ) ;
358
+ debug ! ( "{:?} gets an expression: {:? }" , expression_branch, expression) ;
400
359
let bcb = expression_branch. target_bcb ;
401
360
if expression_branch. is_only_path_to_target ( ) {
402
361
self . coverage_counters . set_bcb_counter ( bcb, expression) ?;
@@ -418,10 +377,10 @@ impl<'a> MakeBcbCounters<'a> {
418
377
// If the BCB already has a counter, return it.
419
378
if let Some ( counter_kind) = & self . coverage_counters . bcb_counters [ bcb] {
420
379
debug ! (
421
- "{}{:?} already has a counter: {}" ,
380
+ "{}{:?} already has a counter: {:? }" ,
422
381
NESTED_INDENT . repeat( debug_indent_level) ,
423
382
bcb,
424
- self . format_counter ( counter_kind) ,
383
+ counter_kind,
425
384
) ;
426
385
return Ok ( counter_kind. as_operand ( ) ) ;
427
386
}
@@ -431,22 +390,22 @@ impl<'a> MakeBcbCounters<'a> {
431
390
// program results in a tight infinite loop, but it should still compile.
432
391
let one_path_to_target = self . bcb_has_one_path_to_target ( bcb) ;
433
392
if one_path_to_target || self . bcb_predecessors ( bcb) . contains ( & bcb) {
434
- let counter_kind = self . coverage_counters . make_counter ( || Some ( format ! ( "{bcb:?}" ) ) ) ;
393
+ let counter_kind = self . coverage_counters . make_counter ( ) ;
435
394
if one_path_to_target {
436
395
debug ! (
437
- "{}{:?} gets a new counter: {}" ,
396
+ "{}{:?} gets a new counter: {:? }" ,
438
397
NESTED_INDENT . repeat( debug_indent_level) ,
439
398
bcb,
440
- self . format_counter ( & counter_kind) ,
399
+ counter_kind,
441
400
) ;
442
401
} else {
443
402
debug ! (
444
403
"{}{:?} has itself as its own predecessor. It can't be part of its own \
445
- Expression sum, so it will get its own new counter: {}. (Note, the compiled \
404
+ Expression sum, so it will get its own new counter: {:? }. (Note, the compiled \
446
405
code will generate an infinite loop.)",
447
406
NESTED_INDENT . repeat( debug_indent_level) ,
448
407
bcb,
449
- self . format_counter ( & counter_kind) ,
408
+ counter_kind,
450
409
) ;
451
410
}
452
411
return self . coverage_counters . set_bcb_counter ( bcb, counter_kind) ;
@@ -481,12 +440,11 @@ impl<'a> MakeBcbCounters<'a> {
481
440
sumup_edge_counter_operand,
482
441
Op :: Add ,
483
442
edge_counter_operand,
484
- || None ,
485
443
) ;
486
444
debug ! (
487
- "{}new intermediate expression: {}" ,
445
+ "{}new intermediate expression: {:? }" ,
488
446
NESTED_INDENT . repeat( debug_indent_level) ,
489
- self . format_counter ( & intermediate_expression)
447
+ intermediate_expression
490
448
) ;
491
449
let intermediate_expression_operand = intermediate_expression. as_operand ( ) ;
492
450
self . coverage_counters . intermediate_expressions . push ( intermediate_expression) ;
@@ -497,13 +455,12 @@ impl<'a> MakeBcbCounters<'a> {
497
455
first_edge_counter_operand,
498
456
Op :: Add ,
499
457
some_sumup_edge_counter_operand. unwrap ( ) ,
500
- || Some ( format ! ( "{bcb:?}" ) ) ,
501
458
) ;
502
459
debug ! (
503
- "{}{:?} gets a new counter (sum of predecessor counters): {}" ,
460
+ "{}{:?} gets a new counter (sum of predecessor counters): {:? }" ,
504
461
NESTED_INDENT . repeat( debug_indent_level) ,
505
462
bcb,
506
- self . format_counter ( & counter_kind)
463
+ counter_kind
507
464
) ;
508
465
self . coverage_counters . set_bcb_counter ( bcb, counter_kind)
509
466
}
@@ -534,24 +491,23 @@ impl<'a> MakeBcbCounters<'a> {
534
491
self . coverage_counters . bcb_edge_counters . get ( & ( from_bcb, to_bcb) )
535
492
{
536
493
debug ! (
537
- "{}Edge {:?}->{:?} already has a counter: {}" ,
494
+ "{}Edge {:?}->{:?} already has a counter: {:? }" ,
538
495
NESTED_INDENT . repeat( debug_indent_level) ,
539
496
from_bcb,
540
497
to_bcb,
541
- self . format_counter ( counter_kind)
498
+ counter_kind
542
499
) ;
543
500
return Ok ( counter_kind. as_operand ( ) ) ;
544
501
}
545
502
546
503
// Make a new counter to count this edge.
547
- let counter_kind =
548
- self . coverage_counters . make_counter ( || Some ( format ! ( "{from_bcb:?}->{to_bcb:?}" ) ) ) ;
504
+ let counter_kind = self . coverage_counters . make_counter ( ) ;
549
505
debug ! (
550
- "{}Edge {:?}->{:?} gets a new counter: {}" ,
506
+ "{}Edge {:?}->{:?} gets a new counter: {:? }" ,
551
507
NESTED_INDENT . repeat( debug_indent_level) ,
552
508
from_bcb,
553
509
to_bcb,
554
- self . format_counter ( & counter_kind)
510
+ counter_kind
555
511
) ;
556
512
self . coverage_counters . set_bcb_edge_counter ( from_bcb, to_bcb, counter_kind)
557
513
}
@@ -710,9 +666,4 @@ impl<'a> MakeBcbCounters<'a> {
710
666
fn bcb_dominates ( & self , dom : BasicCoverageBlock , node : BasicCoverageBlock ) -> bool {
711
667
self . basic_coverage_blocks . dominates ( dom, node)
712
668
}
713
-
714
- #[ inline]
715
- fn format_counter ( & self , counter_kind : & BcbCounter ) -> String {
716
- self . coverage_counters . debug_counters . format_counter ( counter_kind)
717
- }
718
669
}
0 commit comments