Skip to content

Commit cdbbcda

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 72b401d commit cdbbcda

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

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

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

0 commit comments

Comments
 (0)