Skip to content

Commit fbb277c

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 c2dd72c commit fbb277c

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

575578
let initial_pending_count = self.pending_dups.len();
576579
if initial_pending_count > 0 {
577-
let mut pending_dups = self.pending_dups.split_off(0);
578-
let curr = self.curr();
579-
pending_dups.retain(|dup| !self.span_bcb_dominates(dup, curr));
580-
self.pending_dups.append(&mut pending_dups);
581-
if self.pending_dups.len() < initial_pending_count {
580+
self.pending_dups
581+
.retain(|dup| !self.basic_coverage_blocks.dominates(dup.bcb, curr_bcb));
582+
583+
let n_discarded = initial_pending_count - self.pending_dups.len();
584+
if n_discarded > 0 {
582585
debug!(
583-
" discarded {} of {} pending_dups that dominated curr",
584-
initial_pending_count - self.pending_dups.len(),
585-
initial_pending_count
586+
" discarded {n_discarded} of {initial_pending_count} pending_dups that dominated curr",
586587
);
587588
}
588589
}
589590

590-
if self.span_bcb_dominates(self.prev(), self.curr()) {
591+
if self.basic_coverage_blocks.dominates(prev_bcb, curr_bcb) {
591592
debug!(
592593
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
593594
self.prev()
@@ -652,8 +653,4 @@ impl<'a> CoverageSpansGenerator<'a> {
652653
self.pending_dups.clear();
653654
}
654655
}
655-
656-
fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
657-
self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
658-
}
659656
}

0 commit comments

Comments
 (0)