Skip to content

Commit

Permalink
coverage: Inline span_bcb_dominates
Browse files Browse the repository at this point in the history
Interacting with `basic_coverage_blocks` directly makes it easier to satisfy
the borrow checker when mutating `pending_dups` while reading other fields.
  • Loading branch information
Zalathar committed Oct 15, 2023
1 parent e0eb47c commit 889ceab
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,26 +570,27 @@ impl<'a> CoverageSpansGenerator<'a> {
/// until their disposition is determined. In this latter case, the `prev` dup is moved into
/// `pending_dups` so the new `curr` dup can be moved to `prev` for the next iteration.
fn update_pending_dups(&mut self) {
let prev_bcb = self.prev().bcb;
let curr_bcb = self.curr().bcb;

// Equal coverage spans are ordered by dominators before dominated (if any), so it should be
// impossible for `curr` to dominate any previous `CoverageSpan`.
debug_assert!(!self.span_bcb_dominates(self.curr(), self.prev()));
debug_assert!(!self.basic_coverage_blocks.dominates(curr_bcb, prev_bcb));

let initial_pending_count = self.pending_dups.len();
if initial_pending_count > 0 {
let mut pending_dups = self.pending_dups.split_off(0);
let curr = self.curr();
pending_dups.retain(|dup| !self.span_bcb_dominates(dup, curr));
self.pending_dups.append(&mut pending_dups);
if self.pending_dups.len() < initial_pending_count {
self.pending_dups
.retain(|dup| !self.basic_coverage_blocks.dominates(dup.bcb, curr_bcb));

let n_discarded = initial_pending_count - self.pending_dups.len();
if n_discarded > 0 {
debug!(
" discarded {} of {} pending_dups that dominated curr",
initial_pending_count - self.pending_dups.len(),
initial_pending_count
" discarded {n_discarded} of {initial_pending_count} pending_dups that dominated curr",
);
}
}

if self.span_bcb_dominates(self.prev(), self.curr()) {
if self.basic_coverage_blocks.dominates(prev_bcb, curr_bcb) {
debug!(
" different bcbs but SAME spans, and prev dominates curr. Discard prev={:?}",
self.prev()
Expand Down Expand Up @@ -654,8 +655,4 @@ impl<'a> CoverageSpansGenerator<'a> {
self.pending_dups.clear();
}
}

fn span_bcb_dominates(&self, dom_covspan: &CoverageSpan, covspan: &CoverageSpan) -> bool {
self.basic_coverage_blocks.dominates(dom_covspan.bcb, covspan.bcb)
}
}

0 comments on commit 889ceab

Please sign in to comment.