Skip to content

Commit 9c931c0

Browse files
committed
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.
1 parent df96cba commit 9c931c0

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@ pub(super) fn extract_refined_covspans(
2020
basic_coverage_blocks: &CoverageGraph,
2121
code_mappings: &mut impl Extend<mappings::CodeMapping>,
2222
) {
23-
let sorted_spans =
23+
let sorted_span_buckets =
2424
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
25-
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
26-
code_mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
27-
// Each span produced by the generator represents an ordinary code region.
28-
mappings::CodeMapping { span, bcb }
29-
}));
25+
for bucket in sorted_span_buckets {
26+
let refined_spans = SpansRefiner::refine_sorted_spans(bucket);
27+
code_mappings.extend(refined_spans.into_iter().map(|covspan| {
28+
let RefinedCovspan { span, bcb, is_hole: _ } = covspan;
29+
// Each span produced by the refiner represents an ordinary code region.
30+
mappings::CodeMapping { span, bcb }
31+
}));
32+
}
3033
}
3134

3235
#[derive(Debug)]

compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
2323
mir_body: &mir::Body<'_>,
2424
hir_info: &ExtractedHirInfo,
2525
basic_coverage_blocks: &CoverageGraph,
26-
) -> Vec<SpanFromMir> {
26+
) -> Vec<Vec<SpanFromMir>> {
2727
let &ExtractedHirInfo { body_span, .. } = hir_info;
2828

2929
let mut initial_spans = vec![];
@@ -67,7 +67,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
6767
// requires a lot more complexity in the span refiner, for little benefit.)
6868
initial_spans.dedup_by(|b, a| a.span.source_equal(b.span));
6969

70-
initial_spans
70+
vec![initial_spans]
7171
}
7272

7373
/// Macros that expand into branches (e.g. `assert!`, `trace!`) tend to generate

0 commit comments

Comments
 (0)