Skip to content

Commit 6a8a9c7

Browse files
committed
coverage: Inline span_bcb_dominates
Interacting with `basic_coverage_blocks` directly makes it easier to satisfy the borrow checker when mutating `pending_dups` while reading other fields.
1 parent 7b9c644 commit 6a8a9c7

File tree

1 file changed

+11
-14
lines changed
  • compiler/rustc_mir_transform/src/coverage

1 file changed

+11
-14
lines changed

compiler/rustc_mir_transform/src/coverage/spans.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -573,26 +573,27 @@ impl<'a> CoverageSpansGenerator<'a> {
573573
/// until their disposition is determined. In this latter case, the `prev` dup is moved into
574574
/// `pending_dups` so the new `curr` dup can be moved to `prev` for the next iteration.
575575
fn update_pending_dups(&mut self) {
576+
let prev_bcb = self.prev().bcb;
577+
let curr_bcb = self.curr().bcb;
578+
576579
// Equal coverage spans are ordered by dominators before dominated (if any), so it should be
577580
// impossible for `curr` to dominate any previous `CoverageSpan`.
578-
debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev()));
581+
debug_assert!(!self.basic_coverage_blocks.dominates(curr_bcb, prev_bcb));
579582

580583
let initial_pending_count = self.pending_dups.len();
581584
if initial_pending_count > 0 {
582-
let mut pending_dups = self.pending_dups.split_off(0);
583-
let curr = self.curr();
584-
pending_dups.retain(|dup| !self.span_bcb_dominates(dup, curr));
585-
self.pending_dups.append(&mut pending_dups);
586-
if self.pending_dups.len() < initial_pending_count {
585+
self.pending_dups
586+
.retain(|dup| !self.basic_coverage_blocks.dominates(dup.bcb, curr_bcb));
587+
588+
let n_discarded = initial_pending_count - self.pending_dups.len();
589+
if n_discarded > 0 {
587590
debug!(
588-
" discarded {} of {} pending_dups that dominated curr",
589-
initial_pending_count - self.pending_dups.len(),
590-
initial_pending_count
591+
" discarded {n_discarded} of {initial_pending_count} pending_dups that dominated curr",
591592
);
592593
}
593594
}
594595

595-
if self.span_bcb_dominates(self.prev(), self.curr()) {
596+
if self.basic_coverage_blocks.dominates(prev_bcb, curr_bcb) {
596597
debug!(
597598
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
598599
self.prev()
@@ -657,8 +658,4 @@ impl<'a> CoverageSpansGenerator<'a> {
657658
self.pending_dups.clear();
658659
}
659660
}
660-
661-
fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
662-
self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
663-
}
664661
}

0 commit comments

Comments
 (0)