struct SpansRefiner<'a> {
    basic_coverage_blocks: &'a CoverageGraph,
    sorted_spans_iter: IntoIter<SpanFromMir>,
    some_curr: Option<CurrCovspan>,
    some_prev: Option<PrevCovspan>,
    pending_dups: Vec<DuplicateCovspan>,
    refined_spans: Vec<RefinedCovspan>,
}
Expand description

Converts the initial set of coverage spans (one per MIR Statement or Terminator) into a minimal set of coverage spans, using the BCB CFG to determine where it is safe and useful to:

  • Remove duplicate source code coverage regions
  • Merge spans that represent continuous (both in source code and control flow), non-branching execution
  • Carve out (leave uncovered) any span that will be counted by another MIR (notably, closures)

Fields§

§basic_coverage_blocks: &'a CoverageGraph

The BasicCoverageBlock Control Flow Graph (BCB CFG).

§sorted_spans_iter: IntoIter<SpanFromMir>

The initial set of coverage spans, sorted by Span (lo and hi) and by relative dominance between the BasicCoverageBlocks of equal Spans.

§some_curr: Option<CurrCovspan>

The current coverage span to compare to its prev, to possibly merge, discard, force the discard of the prev (and or pending_dups), or keep both (with prev moved to pending_dups). If curr is not discarded or merged, it becomes prev for the next iteration.

§some_prev: Option<PrevCovspan>

The coverage span from a prior iteration; typically assigned from that iteration’s curr. If that curr was discarded, prev retains its value from the previous iteration.

§pending_dups: Vec<DuplicateCovspan>

One or more coverage spans with the same Span but different BasicCoverageBlocks, and no BasicCoverageBlock in this list dominates another BasicCoverageBlock in the list. If a new curr span also fits this criteria (compared to an existing list of pending_dups), that curr moves to prev before possibly being added to the pending_dups list, on the next iteration. As a result, if prev and pending_dups have the same Span, the criteria for pending_dups holds for prev as well: a prev with a matching Span does not dominate any pending_dup and no pending_dup dominates a prev with a matching Span)

§refined_spans: Vec<RefinedCovspan>

The final coverage spans to add to the coverage map. A Counter or Expression will also be injected into the MIR for each BCB that has associated spans.

Implementations§

source§

impl<'a> SpansRefiner<'a>

source

fn refine_sorted_spans( basic_coverage_blocks: &'a CoverageGraph, sorted_spans: Vec<SpanFromMir> ) -> Vec<RefinedCovspan>

Takes the initial list of (sorted) spans extracted from MIR, and “refines” them by merging compatible adjacent spans, removing redundant spans, and carving holes in spans when they overlap in unwanted ways.

source

fn to_refined_spans(self) -> Vec<RefinedCovspan>

Iterate through the sorted coverage spans, and return the refined list of merged and de-duplicated spans.

source

fn curr(&self) -> &CurrCovspan

source

fn take_curr(&mut self) -> CurrCovspan

If called, then the next call to next_coverage_span() will not update prev with the curr coverage span.

source

fn prev(&self) -> &PrevCovspan

source

fn prev_mut(&mut self) -> &mut PrevCovspan

source

fn take_prev(&mut self) -> PrevCovspan

source

fn maybe_flush_pending_dups(&mut self)

If there are pending_dups but prev is not a matching dup (prev.span doesn’t match the pending_dups spans), then one of the following two things happened during the previous iteration:

  • the previous curr span (which is now prev) was not a duplicate of the pending_dups (in which case there should be at least two spans in pending_dups); or
  • the span of prev was modified by curr_mut().merge_from(prev) (in which case pending_dups could have as few as one span) In either case, no more spans will match the span of pending_dups, so add the pending_dups if they don’t overlap curr, and clear the list.
source

fn next_coverage_span(&mut self) -> bool

Advance prev to curr (if any), and curr to the next coverage span in sorted order.

source

fn carve_out_span_for_closure(&mut self)

If prevs span extends left of the closure (curr), carve out the closure’s span from prev’s span. (The closure’s coverage counters will be injected when processing the closure’s own MIR.) Add the portion of the span to the left of the closure; and if the span extends to the right of the closure, update prev to that portion of the span. For any pending_dups, repeat the same process.

source

fn update_pending_dups(&mut self)

Called if curr.span equals prev.original_span (and potentially equal to all pending_dups spans, if any). Keep in mind, prev.span() may have been changed. If prev.span() was merged into other spans (with matching BCB, for instance), prev.span.hi() will be greater than (further right of) prev.original_span.hi(). If prev.span() was split off to the right of a closure, prev.span().lo() will be greater than prev.original_span.lo(). The actual span of prev.original_span is not as important as knowing that prev() used to have the same span as curr(), which means their sort order is still meaningful for determining the dominator relationship.

When two coverage spans have the same Span, dominated spans can be discarded; but if neither coverage span dominates the other, both (or possibly more than two) are held, 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.

source

fn cutoff_prev_at_overlapping_curr(&mut self)

curr overlaps prev. If prevs span extends left of currs span, keep only statements that end before curr.lo() (if any), and add the portion of the combined span for those statements. Any other statements have overlapping spans that can be ignored because curr and/or other upcoming statements/spans inside the overlap area will produce their own counters. This disambiguation process avoids injecting multiple counters for overlapping spans, and the potential for double-counting.

Auto Trait Implementations§

§

impl<'a> !DynSend for SpansRefiner<'a>

§

impl<'a> !DynSync for SpansRefiner<'a>

§

impl<'a> RefUnwindSafe for SpansRefiner<'a>

§

impl<'a> Send for SpansRefiner<'a>

§

impl<'a> Sync for SpansRefiner<'a>

§

impl<'a> Unpin for SpansRefiner<'a>

§

impl<'a> UnwindSafe for SpansRefiner<'a>

Blanket Implementations§

source§

impl<T> Aligned for T

source§

const ALIGN: Alignment = _

Alignment of Self.
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, R> CollectAndApply<T, R> for T

source§

fn collect_and_apply<I, F>(iter: I, f: F) -> R
where I: Iterator<Item = T>, F: FnOnce(&[T]) -> R,

Equivalent to f(&iter.collect::<Vec<_>>()).

§

type Output = R

§

impl<T> Filterable for T

§

fn filterable( self, filter_name: &'static str ) -> RequestFilterDataProvider<T, fn(_: DataRequest<'_>) -> bool>

Creates a filterable data provider with the given name for debugging. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<P> IntoQueryParam<P> for P

source§

impl<T> MaybeResult<T> for T

§

type Error = !

source§

fn from(_: Result<T, <T as MaybeResult<T>>::Error>) -> T

source§

fn to_result(self) -> Result<T, <T as MaybeResult<T>>::Error>

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<'tcx, T> ToPredicate<'tcx, T> for T

source§

fn to_predicate(self, _tcx: TyCtxt<'tcx>) -> T

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<Tcx, T> Value<Tcx> for T
where Tcx: DepContext,

source§

default fn from_cycle_error( tcx: Tcx, cycle_error: &CycleError, _guar: ErrorGuaranteed ) -> T

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

source§

impl<'a, T> Captures<'a> for T
where T: ?Sized,

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T
where T: Send + Sync,

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 152 bytes