coverage: Return a nested vector from initial span extraction

This will allow the span extractor to produce multiple separate buckets,
instead of just one flat list of spans.
This commit is contained in:
Zalathar 2024-06-03 15:27:30 +10:00
parent df96cba432
commit 9c931c01f7
2 changed files with 11 additions and 8 deletions

View File

@ -20,13 +20,16 @@ pub(super) fn extract_refined_covspans(
basic_coverage_blocks: &CoverageGraph,
code_mappings: &mut impl Extend<mappings::CodeMapping>,
) {
let sorted_spans =
let sorted_span_buckets =
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
code_mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
// Each span produced by the generator represents an ordinary code region.
mappings::CodeMapping { span, bcb }
}));
for bucket in sorted_span_buckets {
let refined_spans = SpansRefiner::refine_sorted_spans(bucket);
code_mappings.extend(refined_spans.into_iter().map(|covspan| {
let RefinedCovspan { span, bcb, is_hole: _ } = covspan;
// Each span produced by the refiner represents an ordinary code region.
mappings::CodeMapping { span, bcb }
}));
}
}
#[derive(Debug)]

View File

@ -23,7 +23,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
mir_body: &mir::Body<'_>,
hir_info: &ExtractedHirInfo,
basic_coverage_blocks: &CoverageGraph,
) -> Vec<SpanFromMir> {
) -> Vec<Vec<SpanFromMir>> {
let &ExtractedHirInfo { body_span, .. } = hir_info;
let mut initial_spans = vec![];
@ -67,7 +67,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
// requires a lot more complexity in the span refiner, for little benefit.)
initial_spans.dedup_by(|b, a| a.span.source_equal(b.span));
initial_spans
vec![initial_spans]
}
/// Macros that expand into branches (e.g. `assert!`, `trace!`) tend to generate