Skip to content

Commit

Permalink
coverage: Split span refinement into two separate steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Jun 16, 2024
1 parent 118f66c commit 2d3e6c8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,15 @@ pub(super) fn extract_refined_covspans(
for mut covspans in buckets {
// Make sure each individual bucket is internally sorted.
covspans.sort_by(compare_covspans);
let _span = debug_span!("processing bucket", ?covspans).entered();

let mut covspans = remove_unwanted_overlapping_spans(covspans);
debug!(?covspans, "after removing overlaps");

// Do one last merge pass, to simplify the output.
covspans.dedup_by(|b, a| a.merge_if_eligible(b));
debug!(?covspans, "after merge");

let covspans = refine_sorted_spans(covspans);
code_mappings.extend(covspans.into_iter().map(|Covspan { span, bcb }| {
// Each span produced by the refiner represents an ordinary code region.
mappings::CodeMapping { span, bcb }
Expand Down Expand Up @@ -177,10 +184,11 @@ fn drain_front_while<'a, T>(
}

/// Takes one of the buckets of (sorted) spans extracted from MIR, and "refines"
/// those spans by removing spans that overlap in unwanted ways, and by merging
/// compatible adjacent spans.
/// those spans by removing spans that overlap in unwanted ways.
#[instrument(level = "debug")]
fn refine_sorted_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {
fn remove_unwanted_overlapping_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {
debug_assert!(sorted_spans.is_sorted_by(|a, b| compare_spans(a.span, b.span).is_le()));

// Holds spans that have been read from the input vector, but haven't yet
// been committed to the output vector.
let mut pending = vec![];
Expand All @@ -205,12 +213,6 @@ fn refine_sorted_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {

// Drain the rest of the pending list into the refined list.
refined.extend(pending);

// Do one last merge pass, to simplify the output.
debug!(?refined, "before merge");
refined.dedup_by(|b, a| a.merge_if_eligible(b));
debug!(?refined, "after merge");

refined
}

Expand Down

0 comments on commit 2d3e6c8

Please sign in to comment.