1
+ use super :: debug;
2
+
3
+ use debug:: DebugCounters ;
4
+
1
5
use rustc_middle:: mir:: coverage:: * ;
2
6
3
7
/// Manages the counter and expression indexes/IDs to generate `CoverageKind` components for MIR
@@ -6,6 +10,7 @@ pub(crate) struct CoverageCounters {
6
10
function_source_hash : u64 ,
7
11
next_counter_id : u32 ,
8
12
num_expressions : u32 ,
13
+ pub debug_counters : DebugCounters ,
9
14
}
10
15
11
16
impl CoverageCounters {
@@ -14,24 +19,46 @@ impl CoverageCounters {
14
19
function_source_hash,
15
20
next_counter_id : CounterValueReference :: START . as_u32 ( ) ,
16
21
num_expressions : 0 ,
22
+ debug_counters : DebugCounters :: new ( ) ,
17
23
}
18
24
}
19
25
20
- pub fn make_counter ( & mut self ) -> CoverageKind {
21
- CoverageKind :: Counter {
26
+ /// Activate the `DebugCounters` data structures, to provide additional debug formatting
27
+ /// features when formating `CoverageKind` (counter) values.
28
+ pub fn enable_debug ( & mut self ) {
29
+ self . debug_counters . enable ( ) ;
30
+ }
31
+
32
+ pub fn make_counter < F > ( & mut self , debug_block_label_fn : F ) -> CoverageKind
33
+ where
34
+ F : Fn ( ) -> Option < String > ,
35
+ {
36
+ let counter = CoverageKind :: Counter {
22
37
function_source_hash : self . function_source_hash ,
23
38
id : self . next_counter ( ) ,
39
+ } ;
40
+ if self . debug_counters . is_enabled ( ) {
41
+ self . debug_counters . add_counter ( & counter, ( debug_block_label_fn) ( ) ) ;
24
42
}
43
+ counter
25
44
}
26
45
27
- pub fn make_expression (
46
+ pub fn make_expression < F > (
28
47
& mut self ,
29
48
lhs : ExpressionOperandId ,
30
49
op : Op ,
31
50
rhs : ExpressionOperandId ,
32
- ) -> CoverageKind {
51
+ debug_block_label_fn : F ,
52
+ ) -> CoverageKind
53
+ where
54
+ F : Fn ( ) -> Option < String > ,
55
+ {
33
56
let id = self . next_expression ( ) ;
34
- CoverageKind :: Expression { id, lhs, op, rhs }
57
+ let expression = CoverageKind :: Expression { id, lhs, op, rhs } ;
58
+ if self . debug_counters . is_enabled ( ) {
59
+ self . debug_counters . add_counter ( & expression, ( debug_block_label_fn) ( ) ) ;
60
+ }
61
+ expression
35
62
}
36
63
37
64
/// Counter IDs start from one and go up.
0 commit comments