coverage: Skip instrumenting a function if no spans were extracted
This commit is contained in:
parent
a96d57bdb6
commit
dfa6441354
@ -99,12 +99,15 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> {
|
|||||||
fn inject_counters(&'a mut self) {
|
fn inject_counters(&'a mut self) {
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// Compute coverage spans from the `CoverageGraph`.
|
// Compute coverage spans from the `CoverageGraph`.
|
||||||
let coverage_spans = CoverageSpans::generate_coverage_spans(
|
let Some(coverage_spans) = CoverageSpans::generate_coverage_spans(
|
||||||
self.mir_body,
|
self.mir_body,
|
||||||
self.fn_sig_span,
|
self.fn_sig_span,
|
||||||
self.body_span,
|
self.body_span,
|
||||||
&self.basic_coverage_blocks,
|
&self.basic_coverage_blocks,
|
||||||
);
|
) else {
|
||||||
|
// No relevant spans were found in MIR, so skip instrumenting this function.
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////
|
////////////////////////////////////////////////////
|
||||||
// Create an optimized mix of `Counter`s and `Expression`s for the `CoverageGraph`. Ensure
|
// Create an optimized mix of `Counter`s and `Expression`s for the `CoverageGraph`. Ensure
|
||||||
|
@ -15,12 +15,16 @@ pub(super) struct CoverageSpans {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CoverageSpans {
|
impl CoverageSpans {
|
||||||
|
/// Extracts coverage-relevant spans from MIR, and associates them with
|
||||||
|
/// their corresponding BCBs.
|
||||||
|
///
|
||||||
|
/// Returns `None` if no coverage-relevant spans could be extracted.
|
||||||
pub(super) fn generate_coverage_spans(
|
pub(super) fn generate_coverage_spans(
|
||||||
mir_body: &mir::Body<'_>,
|
mir_body: &mir::Body<'_>,
|
||||||
fn_sig_span: Span,
|
fn_sig_span: Span,
|
||||||
body_span: Span,
|
body_span: Span,
|
||||||
basic_coverage_blocks: &CoverageGraph,
|
basic_coverage_blocks: &CoverageGraph,
|
||||||
) -> Self {
|
) -> Option<Self> {
|
||||||
let coverage_spans = CoverageSpansGenerator::generate_coverage_spans(
|
let coverage_spans = CoverageSpansGenerator::generate_coverage_spans(
|
||||||
mir_body,
|
mir_body,
|
||||||
fn_sig_span,
|
fn_sig_span,
|
||||||
@ -28,13 +32,17 @@ impl CoverageSpans {
|
|||||||
basic_coverage_blocks,
|
basic_coverage_blocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if coverage_spans.is_empty() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
// Group the coverage spans by BCB, with the BCBs in sorted order.
|
// Group the coverage spans by BCB, with the BCBs in sorted order.
|
||||||
let mut bcb_to_spans = IndexVec::from_elem_n(Vec::new(), basic_coverage_blocks.num_nodes());
|
let mut bcb_to_spans = IndexVec::from_elem_n(Vec::new(), basic_coverage_blocks.num_nodes());
|
||||||
for CoverageSpan { bcb, span, .. } in coverage_spans {
|
for CoverageSpan { bcb, span, .. } in coverage_spans {
|
||||||
bcb_to_spans[bcb].push(span);
|
bcb_to_spans[bcb].push(span);
|
||||||
}
|
}
|
||||||
|
|
||||||
Self { bcb_to_spans }
|
Some(Self { bcb_to_spans })
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn bcb_has_coverage_spans(&self, bcb: BasicCoverageBlock) -> bool {
|
pub(super) fn bcb_has_coverage_spans(&self, bcb: BasicCoverageBlock) -> bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user