[−][src]Struct rustc_mir::transform::coverage::spans::CoverageSpans

pub struct CoverageSpans<'a, 'tcx> {
    mir_body: &'a Body<'tcx>,
    body_span: Span,
    basic_coverage_blocks: &'a CoverageGraph,
    sorted_spans_iter: Option<IntoIter<CoverageSpan>>,
    some_curr: Option<CoverageSpan>,
    curr_original_span: Span,
    some_prev: Option<CoverageSpan>,
    prev_original_span: Span,
    pending_dups: Vec<CoverageSpan>,
    refined_spans: Vec<CoverageSpan>,
}

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

Fields

mir_body: &'a Body<'tcx>

The MIR, used to look up BasicBlockData.

body_span: Span

A Span covering the function body of the MIR (typically from left curly brace to right curly brace).

basic_coverage_blocks: &'a CoverageGraph

The BasicCoverageBlock Control Flow Graph (BCB CFG).

sorted_spans_iter: Option<IntoIter<CoverageSpan>>

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

some_curr: Option<CoverageSpan>

The current CoverageSpan 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.

curr_original_span: Span

The original span for curr, in case the curr span is modified.

some_prev: Option<CoverageSpan>

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

prev_original_span: Span

Assigned from curr_original_span from the previous iteration.

pending_dups: Vec<CoverageSpan>

One or more CoverageSpans 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 CoverageSpan 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<CoverageSpan>

The final CoverageSpans to add to the coverage map. A Counter or Expression will also be injected into the MIR for each CoverageSpan.

Implementations

impl<'a, 'tcx> CoverageSpans<'a, 'tcx>[src]

pub(in transform::coverage) fn generate_coverage_spans(
    mir_body: &'a Body<'tcx>,
    body_span: Span,
    basic_coverage_blocks: &'a CoverageGraph
) -> Vec<CoverageSpan>
[src]

pub(in transform::coverage::spans) fn mir_to_initial_sorted_coverage_spans(
    &self
) -> Vec<CoverageSpan>
[src]

Generate a minimal set of CoverageSpans, each representing a contiguous code region to be counted.

The basic steps are:

  1. Extract an initial set of spans from the Statements and Terminators of each BasicCoverageBlockData.

  2. Sort the spans by span.lo() (starting position). Spans that start at the same position are sorted with longer spans before shorter spans; and equal spans are sorted (deterministically) based on "dominator" relationship (if any).

  3. Traverse the spans in sorted order to identify spans that can be dropped (for instance, if another span or spans are already counting the same code region), or should be merged into a broader combined span (because it represents a contiguous, non-branching, and uninterrupted region of source code).

    Closures are exposed in their enclosing functions as Assign Rvalues, and since closures have their own MIR, their Span in their enclosing function should be left "uncovered".

Note the resulting vector of CoverageSpans does may not be fully sorted (and does not need to be).

pub(in transform::coverage::spans) fn to_refined_spans(
    self
) -> Vec<CoverageSpan>
[src]

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

pub(in transform::coverage::spans) fn bcb_to_initial_coverage_spans(
    &self,
    bcb: BasicCoverageBlock,
    bcb_data: &'a BasicCoverageBlockData
) -> Vec<CoverageSpan>
[src]

pub(in transform::coverage::spans) fn curr(
    &self
) -> &CoverageSpan
[src]

pub(in transform::coverage::spans) fn curr_mut(
    &mut self
) -> &mut CoverageSpan
[src]

pub(in transform::coverage::spans) fn prev(
    &self
) -> &CoverageSpan
[src]

pub(in transform::coverage::spans) fn prev_mut(
    &mut self
) -> &mut CoverageSpan
[src]

pub(in transform::coverage::spans) fn take_prev(
    &mut self
) -> CoverageSpan
[src]

pub(in transform::coverage::spans) fn check_pending_dups(
    &mut self
)
[src]

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.

pub(in transform::coverage::spans) fn next_coverage_span(
    &mut self
) -> bool
[src]

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

pub(in transform::coverage::spans) fn discard_curr(
    &mut self
)
[src]

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

pub(in transform::coverage::spans) fn prev_starts_after_next(
    &self,
    next_curr: &CoverageSpan
) -> bool
[src]

Returns true if the curr span should be skipped because prev has already advanced beyond the end of curr. This can only happen if a prior iteration updated prev to skip past a region of code, such as skipping past a closure.

pub(in transform::coverage::spans) fn prev_ends_before_curr(
    &self
) -> bool
[src]

Returns true if the curr span starts past the end of the prev span, which means they don't overlap, so we now know the prev can be added to the refined coverage spans.

pub(in transform::coverage::spans) fn carve_out_span_for_closure(
    &mut self
)
[src]

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.

pub(in transform::coverage::spans) fn hold_pending_dups_unless_dominated(
    &mut self
)
[src]

Called if curr.span equals prev_original_span (and potentially equal to all pending_dups spans, if any); but keep in mind, prev.span may start at a Span.lo() that is less than (further left of) prev_original_span.lo().

When two CoverageSpans have the same Span, dominated spans can be discarded; but if neither CoverageSpan 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.

pub(in transform::coverage::spans) fn cutoff_prev_at_overlapping_curr(
    &mut self
)
[src]

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.

pub(in transform::coverage::spans) fn span_bcb_is_dominated_by(
    &self,
    covspan: &CoverageSpan,
    dom_covspan: &CoverageSpan
) -> bool
[src]

Auto Trait Implementations

impl<'a, 'tcx> !RefUnwindSafe for CoverageSpans<'a, 'tcx>

impl<'a, 'tcx> !Send for CoverageSpans<'a, 'tcx>

impl<'a, 'tcx> !Sync for CoverageSpans<'a, 'tcx>

impl<'a, 'tcx> Unpin for CoverageSpans<'a, 'tcx> where
    'tcx: 'a, 

impl<'a, 'tcx> !UnwindSafe for CoverageSpans<'a, 'tcx>

Blanket Implementations

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

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]