Skip to content

Commit da8c853

Browse files
committed
coverage: Split span refinement into two separate steps
1 parent 035b846 commit da8c853

File tree

1 file changed

+12
-10
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+12
-10
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,15 @@ pub(super) fn extract_refined_covspans(
5858
for mut covspans in buckets {
5959
// Make sure each individual bucket is internally sorted.
6060
covspans.sort_by(compare_covspans);
61+
let _span = debug_span!("processing bucket", ?covspans).entered();
62+
63+
let mut covspans = remove_unwanted_overlapping_spans(covspans);
64+
debug!(?covspans, "after removing overlaps");
65+
66+
// Do one last merge pass, to simplify the output.
67+
covspans.dedup_by(|b, a| a.merge_if_eligible(b));
68+
debug!(?covspans, "after merge");
6169

62-
let covspans = refine_sorted_spans(covspans);
6370
code_mappings.extend(covspans.into_iter().map(|Covspan { span, bcb }| {
6471
// Each span produced by the refiner represents an ordinary code region.
6572
mappings::CodeMapping { span, bcb }
@@ -176,10 +183,11 @@ fn drain_front_while<'a, T>(
176183
}
177184

178185
/// Takes one of the buckets of (sorted) spans extracted from MIR, and "refines"
179-
/// those spans by removing spans that overlap in unwanted ways, and by merging
180-
/// compatible adjacent spans.
186+
/// those spans by removing spans that overlap in unwanted ways.
181187
#[instrument(level = "debug")]
182-
fn refine_sorted_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {
188+
fn remove_unwanted_overlapping_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {
189+
debug_assert!(sorted_spans.is_sorted_by(|a, b| compare_spans(a.span, b.span).is_le()));
190+
183191
// Holds spans that have been read from the input vector, but haven't yet
184192
// been committed to the output vector.
185193
let mut pending = vec![];
@@ -204,12 +212,6 @@ fn refine_sorted_spans(sorted_spans: Vec<Covspan>) -> Vec<Covspan> {
204212

205213
// Drain the rest of the pending list into the refined list.
206214
refined.extend(pending);
207-
208-
// Do one last merge pass, to simplify the output.
209-
debug!(?refined, "before merge");
210-
refined.dedup_by(|b, a| a.merge_if_eligible(b));
211-
debug!(?refined, "after merge");
212-
213215
refined
214216
}
215217

0 commit comments

Comments
 (0)