Skip to content

Commit 3291d28

Browse files
committed
Adds coverage graphviz
1 parent b502064 commit 3291d28

File tree

9 files changed

+657
-10
lines changed

9 files changed

+657
-10
lines changed

compiler/rustc_mir/src/transform/coverage/counters.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
use super::debug;
2+
3+
use debug::DebugCounters;
4+
15
use rustc_middle::mir::coverage::*;
26

37
/// Manages the counter and expression indexes/IDs to generate `CoverageKind` components for MIR
@@ -6,6 +10,7 @@ pub(crate) struct CoverageCounters {
610
function_source_hash: u64,
711
next_counter_id: u32,
812
num_expressions: u32,
13+
pub debug_counters: DebugCounters,
914
}
1015

1116
impl CoverageCounters {
@@ -14,24 +19,46 @@ impl CoverageCounters {
1419
function_source_hash,
1520
next_counter_id: CounterValueReference::START.as_u32(),
1621
num_expressions: 0,
22+
debug_counters: DebugCounters::new(),
1723
}
1824
}
1925

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 {
2237
function_source_hash: self.function_source_hash,
2338
id: self.next_counter(),
39+
};
40+
if self.debug_counters.is_enabled() {
41+
self.debug_counters.add_counter(&counter, (debug_block_label_fn)());
2442
}
43+
counter
2544
}
2645

27-
pub fn make_expression(
46+
pub fn make_expression<F>(
2847
&mut self,
2948
lhs: ExpressionOperandId,
3049
op: Op,
3150
rhs: ExpressionOperandId,
32-
) -> CoverageKind {
51+
debug_block_label_fn: F,
52+
) -> CoverageKind
53+
where
54+
F: Fn() -> Option<String>,
55+
{
3356
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
3562
}
3663

3764
/// Counter IDs start from one and go up.

0 commit comments

Comments
 (0)