Skip to content

Commit 10348f5

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 6da87e2 commit 10348f5

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
@@ -571,26 +571,27 @@ impl<'a> CoverageSpansGenerator<'a> {
571571
/// until their disposition is determined. In this latter case, the `prev` dup is moved into
572572
/// `pending_dups` so the new `curr` dup can be moved to `prev` for the next iteration.
573573
fn update_pending_dups(&mut self) {
574+
let prev_bcb = self.prev().bcb;
575+
let curr_bcb = self.curr().bcb;
576+
574577
// Equal coverage spans are ordered by dominators before dominated (if any), so it should be
575578
// impossible for `curr` to dominate any previous `CoverageSpan`.
576-
debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev()));
579+
debug_assert!(!self.basic_coverage_blocks.dominates(curr_bcb, prev_bcb));
577580

578581
let initial_pending_count = self.pending_dups.len();
579582
if initial_pending_count > 0 {
580-
let mut pending_dups = self.pending_dups.split_off(0);
581-
let curr = self.curr();
582-
pending_dups.retain(|dup| !self.span_bcb_dominates(dup, curr));
583-
self.pending_dups.append(&mut pending_dups);
584-
if self.pending_dups.len() < initial_pending_count {
583+
self.pending_dups
584+
.retain(|dup| !self.basic_coverage_blocks.dominates(dup.bcb, curr_bcb));
585+
586+
let n_discarded = initial_pending_count - self.pending_dups.len();
587+
if n_discarded > 0 {
585588
debug!(
586-
" discarded {} of {} pending_dups that dominated curr",
587-
initial_pending_count - self.pending_dups.len(),
588-
initial_pending_count
589+
" discarded {n_discarded} of {initial_pending_count} pending_dups that dominated curr",
589590
);
590591
}
591592
}
592593

593-
if self.span_bcb_dominates(self.prev(), self.curr()) {
594+
if self.basic_coverage_blocks.dominates(prev_bcb, curr_bcb) {
594595
debug!(
595596
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
596597
self.prev()
@@ -655,8 +656,4 @@ impl<'a> CoverageSpansGenerator<'a> {
655656
self.pending_dups.clear();
656657
}
657658
}
658-
659-
fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
660-
self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
661-
}
662659
}

0 commit comments

Comments
 (0)