coverage: Split CoverageSpan
into several distinct structs
This requires some extra boilerplate, but in exchange it becomes much easier to see how each field and method is actually used.
This commit is contained in:
parent
5a569b1b80
commit
a6183216d8
2 changed files with 139 additions and 83 deletions
|
@ -9,7 +9,6 @@ use rustc_span::{ExpnKind, MacroKind, Span, Symbol};
|
|||
use crate::coverage::graph::{
|
||||
BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph, START_BCB,
|
||||
};
|
||||
use crate::coverage::spans::CoverageSpan;
|
||||
use crate::coverage::ExtractedHirInfo;
|
||||
|
||||
/// Traverses the MIR body to produce an initial collection of coverage-relevant
|
||||
|
@ -22,7 +21,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
|
|||
mir_body: &mir::Body<'_>,
|
||||
hir_info: &ExtractedHirInfo,
|
||||
basic_coverage_blocks: &CoverageGraph,
|
||||
) -> Vec<CoverageSpan> {
|
||||
) -> Vec<SpanFromMir> {
|
||||
let &ExtractedHirInfo { body_span, .. } = hir_info;
|
||||
|
||||
let mut initial_spans = vec![];
|
||||
|
@ -61,7 +60,7 @@ pub(super) fn mir_to_initial_sorted_coverage_spans(
|
|||
.then_with(|| Ord::cmp(&a.is_closure, &b.is_closure).reverse())
|
||||
});
|
||||
|
||||
initial_spans.into_iter().map(SpanFromMir::into_coverage_span).collect::<Vec<_>>()
|
||||
initial_spans
|
||||
}
|
||||
|
||||
/// Macros that expand into branches (e.g. `assert!`, `trace!`) tend to generate
|
||||
|
@ -119,10 +118,10 @@ fn split_visible_macro_spans(initial_spans: &mut Vec<SpanFromMir>) {
|
|||
initial_spans.extend(extra_spans);
|
||||
}
|
||||
|
||||
// Generate a set of `CoverageSpan`s from the filtered set of `Statement`s and `Terminator`s of
|
||||
// the `BasicBlock`(s) in the given `BasicCoverageBlockData`. One `CoverageSpan` is generated
|
||||
// Generate a set of coverage spans from the filtered set of `Statement`s and `Terminator`s of
|
||||
// the `BasicBlock`(s) in the given `BasicCoverageBlockData`. One coverage span is generated
|
||||
// for each `Statement` and `Terminator`. (Note that subsequent stages of coverage analysis will
|
||||
// merge some `CoverageSpan`s, at which point a `CoverageSpan` may represent multiple
|
||||
// merge some coverage spans, at which point a coverage span may represent multiple
|
||||
// `Statement`s and/or `Terminator`s.)
|
||||
fn bcb_to_initial_coverage_spans<'a, 'tcx>(
|
||||
mir_body: &'a mir::Body<'tcx>,
|
||||
|
@ -316,7 +315,7 @@ fn unexpand_into_body_span_with_prev(
|
|||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SpanFromMir {
|
||||
pub(super) struct SpanFromMir {
|
||||
/// A span that has been extracted from MIR and then "un-expanded" back to
|
||||
/// within the current function's `body_span`. After various intermediate
|
||||
/// processing steps, this span is emitted as part of the final coverage
|
||||
|
@ -324,10 +323,10 @@ struct SpanFromMir {
|
|||
///
|
||||
/// With the exception of `fn_sig_span`, this should always be contained
|
||||
/// within `body_span`.
|
||||
span: Span,
|
||||
pub(super) span: Span,
|
||||
visible_macro: Option<Symbol>,
|
||||
bcb: BasicCoverageBlock,
|
||||
is_closure: bool,
|
||||
pub(super) bcb: BasicCoverageBlock,
|
||||
pub(super) is_closure: bool,
|
||||
}
|
||||
|
||||
impl SpanFromMir {
|
||||
|
@ -343,9 +342,4 @@ impl SpanFromMir {
|
|||
) -> Self {
|
||||
Self { span, visible_macro, bcb, is_closure }
|
||||
}
|
||||
|
||||
fn into_coverage_span(self) -> CoverageSpan {
|
||||
let Self { span, visible_macro: _, bcb, is_closure } = self;
|
||||
CoverageSpan::new(span, bcb, is_closure)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue