coverage: Replace manual debug indents with nested tracing spans
This commit is contained in:
parent
608e9682f0
commit
6d69eb1f2e
@ -12,8 +12,6 @@ use rustc_middle::mir::coverage::*;
|
|||||||
|
|
||||||
use std::fmt::{self, Debug};
|
use std::fmt::{self, Debug};
|
||||||
|
|
||||||
const NESTED_INDENT: &str = " ";
|
|
||||||
|
|
||||||
/// The coverage counter or counter expression associated with a particular
|
/// The coverage counter or counter expression associated with a particular
|
||||||
/// BCB node or BCB edge.
|
/// BCB node or BCB edge.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@ -347,22 +345,17 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_or_make_counter_operand(&mut self, bcb: BasicCoverageBlock) -> Result<CovTerm, Error> {
|
fn get_or_make_counter_operand(&mut self, bcb: BasicCoverageBlock) -> Result<CovTerm, Error> {
|
||||||
self.recursive_get_or_make_counter_operand(bcb, 1)
|
self.recursive_get_or_make_counter_operand(bcb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn recursive_get_or_make_counter_operand(
|
fn recursive_get_or_make_counter_operand(
|
||||||
&mut self,
|
&mut self,
|
||||||
bcb: BasicCoverageBlock,
|
bcb: BasicCoverageBlock,
|
||||||
debug_indent_level: usize,
|
|
||||||
) -> Result<CovTerm, Error> {
|
) -> Result<CovTerm, Error> {
|
||||||
// If the BCB already has a counter, return it.
|
// If the BCB already has a counter, return it.
|
||||||
if let Some(counter_kind) = &self.coverage_counters.bcb_counters[bcb] {
|
if let Some(counter_kind) = &self.coverage_counters.bcb_counters[bcb] {
|
||||||
debug!(
|
debug!("{bcb:?} already has a counter: {counter_kind:?}");
|
||||||
"{}{:?} already has a counter: {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
bcb,
|
|
||||||
counter_kind,
|
|
||||||
);
|
|
||||||
return Ok(counter_kind.as_term());
|
return Ok(counter_kind.as_term());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,20 +366,12 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
if one_path_to_target || self.bcb_predecessors(bcb).contains(&bcb) {
|
if one_path_to_target || self.bcb_predecessors(bcb).contains(&bcb) {
|
||||||
let counter_kind = self.coverage_counters.make_counter();
|
let counter_kind = self.coverage_counters.make_counter();
|
||||||
if one_path_to_target {
|
if one_path_to_target {
|
||||||
debug!(
|
debug!("{bcb:?} gets a new counter: {counter_kind:?}");
|
||||||
"{}{:?} gets a new counter: {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
bcb,
|
|
||||||
counter_kind,
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
debug!(
|
debug!(
|
||||||
"{}{:?} has itself as its own predecessor. It can't be part of its own \
|
"{bcb:?} has itself as its own predecessor. It can't be part of its own \
|
||||||
Expression sum, so it will get its own new counter: {:?}. (Note, the compiled \
|
Expression sum, so it will get its own new counter: {counter_kind:?}. \
|
||||||
code will generate an infinite loop.)",
|
(Note, the compiled code will generate an infinite loop.)",
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
bcb,
|
|
||||||
counter_kind,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return self.coverage_counters.set_bcb_counter(bcb, counter_kind);
|
return self.coverage_counters.set_bcb_counter(bcb, counter_kind);
|
||||||
@ -397,23 +382,13 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
// counters for those incoming edges first, then call `make_expression()` to sum them up,
|
// counters for those incoming edges first, then call `make_expression()` to sum them up,
|
||||||
// with additional intermediate expressions as needed.
|
// with additional intermediate expressions as needed.
|
||||||
let mut predecessors = self.bcb_predecessors(bcb).to_owned().into_iter();
|
let mut predecessors = self.bcb_predecessors(bcb).to_owned().into_iter();
|
||||||
debug!(
|
debug!("{bcb:?} has multiple incoming edges and will need a sum-up expression");
|
||||||
"{}{:?} has multiple incoming edges and will get an expression that sums them up...",
|
let first_edge_counter_operand =
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
self.recursive_get_or_make_edge_counter_operand(predecessors.next().unwrap(), bcb)?;
|
||||||
bcb,
|
|
||||||
);
|
|
||||||
let first_edge_counter_operand = self.recursive_get_or_make_edge_counter_operand(
|
|
||||||
predecessors.next().unwrap(),
|
|
||||||
bcb,
|
|
||||||
debug_indent_level + 1,
|
|
||||||
)?;
|
|
||||||
let mut some_sumup_edge_counter_operand = None;
|
let mut some_sumup_edge_counter_operand = None;
|
||||||
for predecessor in predecessors {
|
for predecessor in predecessors {
|
||||||
let edge_counter_operand = self.recursive_get_or_make_edge_counter_operand(
|
let edge_counter_operand =
|
||||||
predecessor,
|
self.recursive_get_or_make_edge_counter_operand(predecessor, bcb)?;
|
||||||
bcb,
|
|
||||||
debug_indent_level + 1,
|
|
||||||
)?;
|
|
||||||
if let Some(sumup_edge_counter_operand) =
|
if let Some(sumup_edge_counter_operand) =
|
||||||
some_sumup_edge_counter_operand.replace(edge_counter_operand)
|
some_sumup_edge_counter_operand.replace(edge_counter_operand)
|
||||||
{
|
{
|
||||||
@ -422,11 +397,7 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
Op::Add,
|
Op::Add,
|
||||||
edge_counter_operand,
|
edge_counter_operand,
|
||||||
);
|
);
|
||||||
debug!(
|
debug!("new intermediate expression: {intermediate_expression:?}");
|
||||||
"{}new intermediate expression: {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
intermediate_expression
|
|
||||||
);
|
|
||||||
let intermediate_expression_operand = intermediate_expression.as_term();
|
let intermediate_expression_operand = intermediate_expression.as_term();
|
||||||
some_sumup_edge_counter_operand.replace(intermediate_expression_operand);
|
some_sumup_edge_counter_operand.replace(intermediate_expression_operand);
|
||||||
}
|
}
|
||||||
@ -436,12 +407,7 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
Op::Add,
|
Op::Add,
|
||||||
some_sumup_edge_counter_operand.unwrap(),
|
some_sumup_edge_counter_operand.unwrap(),
|
||||||
);
|
);
|
||||||
debug!(
|
debug!("{bcb:?} gets a new counter (sum of predecessor counters): {counter_kind:?}");
|
||||||
"{}{:?} gets a new counter (sum of predecessor counters): {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
bcb,
|
|
||||||
counter_kind
|
|
||||||
);
|
|
||||||
self.coverage_counters.set_bcb_counter(bcb, counter_kind)
|
self.coverage_counters.set_bcb_counter(bcb, counter_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,45 +416,33 @@ impl<'a> MakeBcbCounters<'a> {
|
|||||||
from_bcb: BasicCoverageBlock,
|
from_bcb: BasicCoverageBlock,
|
||||||
to_bcb: BasicCoverageBlock,
|
to_bcb: BasicCoverageBlock,
|
||||||
) -> Result<CovTerm, Error> {
|
) -> Result<CovTerm, Error> {
|
||||||
self.recursive_get_or_make_edge_counter_operand(from_bcb, to_bcb, 1)
|
self.recursive_get_or_make_edge_counter_operand(from_bcb, to_bcb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[instrument(level = "debug", skip(self))]
|
||||||
fn recursive_get_or_make_edge_counter_operand(
|
fn recursive_get_or_make_edge_counter_operand(
|
||||||
&mut self,
|
&mut self,
|
||||||
from_bcb: BasicCoverageBlock,
|
from_bcb: BasicCoverageBlock,
|
||||||
to_bcb: BasicCoverageBlock,
|
to_bcb: BasicCoverageBlock,
|
||||||
debug_indent_level: usize,
|
|
||||||
) -> Result<CovTerm, Error> {
|
) -> Result<CovTerm, Error> {
|
||||||
// If the source BCB has only one successor (assumed to be the given target), an edge
|
// If the source BCB has only one successor (assumed to be the given target), an edge
|
||||||
// counter is unnecessary. Just get or make a counter for the source BCB.
|
// counter is unnecessary. Just get or make a counter for the source BCB.
|
||||||
let successors = self.bcb_successors(from_bcb).iter();
|
let successors = self.bcb_successors(from_bcb).iter();
|
||||||
if successors.len() == 1 {
|
if successors.len() == 1 {
|
||||||
return self.recursive_get_or_make_counter_operand(from_bcb, debug_indent_level + 1);
|
return self.recursive_get_or_make_counter_operand(from_bcb);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the edge already has a counter, return it.
|
// If the edge already has a counter, return it.
|
||||||
if let Some(counter_kind) =
|
if let Some(counter_kind) =
|
||||||
self.coverage_counters.bcb_edge_counters.get(&(from_bcb, to_bcb))
|
self.coverage_counters.bcb_edge_counters.get(&(from_bcb, to_bcb))
|
||||||
{
|
{
|
||||||
debug!(
|
debug!("Edge {from_bcb:?}->{to_bcb:?} already has a counter: {counter_kind:?}");
|
||||||
"{}Edge {:?}->{:?} already has a counter: {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
from_bcb,
|
|
||||||
to_bcb,
|
|
||||||
counter_kind
|
|
||||||
);
|
|
||||||
return Ok(counter_kind.as_term());
|
return Ok(counter_kind.as_term());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make a new counter to count this edge.
|
// Make a new counter to count this edge.
|
||||||
let counter_kind = self.coverage_counters.make_counter();
|
let counter_kind = self.coverage_counters.make_counter();
|
||||||
debug!(
|
debug!("Edge {from_bcb:?}->{to_bcb:?} gets a new counter: {counter_kind:?}");
|
||||||
"{}Edge {:?}->{:?} gets a new counter: {:?}",
|
|
||||||
NESTED_INDENT.repeat(debug_indent_level),
|
|
||||||
from_bcb,
|
|
||||||
to_bcb,
|
|
||||||
counter_kind
|
|
||||||
);
|
|
||||||
self.coverage_counters.set_bcb_edge_counter(from_bcb, to_bcb, counter_kind)
|
self.coverage_counters.set_bcb_edge_counter(from_bcb, to_bcb, counter_kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user