Skip to content

Commit

Permalink
coverage: Return a nested vector from initial span extraction
Browse files Browse the repository at this point in the history
This will allow the span extractor to produce multiple separate buckets,
instead of just one flat list of spans.
  • Loading branch information
Zalathar committed Jun 3, 2024
1 parent d99a226 commit 4211ff9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/coverage/spans/from_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![];
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4211ff9

Please sign in to comment.