about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src/coverage/spans.rs
diff options
context:
space:
mode:
authorZalathar <Zalathar@users.noreply.github.com>2024-06-15 23:39:04 +1000
committerZalathar <Zalathar@users.noreply.github.com>2024-06-16 13:47:32 +1000
commit2d3e6c88048fd19921346c9e945ccdf64fe97939 (patch)
tree6d10b1578b42024d87aea8fb2cd711e6f722a92c /compiler/rustc_mir_transform/src/coverage/spans.rs
parent118f66c237acee3f4a1fd4a773d4b2ccabd93851 (diff)
downloadrust-2d3e6c88048fd19921346c9e945ccdf64fe97939.tar.gz
rust-2d3e6c88048fd19921346c9e945ccdf64fe97939.zip
coverage: Split span refinement into two separate steps
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/spans.rs')
-rw-r--r--compiler/rustc_mir_transform/src/coverage/spans.rs22
1 files changed, 12 insertions, 10 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/spans.rs b/compiler/rustc_mir_transform/src/coverage/spans.rs
index dbc6718636f..84a70d1f02d 100644
--- a/compiler/rustc_mir_transform/src/coverage/spans.rs
+++ b/compiler/rustc_mir_transform/src/coverage/spans.rs
@@ -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 }
@@ -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![];
@@ -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
 }