coverage: Flatten BcbMappingKind
into mappings::CodeMapping
Now that branch and MC/DC mappings have been split out into separate types and vectors, this enum is no longer needed, since it only represents ordinary "code" regions. (We can revisit this decision if we ever add support for other region kinds, such as skipped regions or expansion regions. But at that point, we might just add new structs/vectors for those kinds as well.)
This commit is contained in:
parent
cf2d741d40
commit
76d8d01604
@ -13,22 +13,14 @@ use crate::coverage::spans::{
|
|||||||
};
|
};
|
||||||
use crate::coverage::ExtractedHirInfo;
|
use crate::coverage::ExtractedHirInfo;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
|
||||||
pub(super) enum BcbMappingKind {
|
|
||||||
/// Associates an ordinary executable code span with its corresponding BCB.
|
/// Associates an ordinary executable code span with its corresponding BCB.
|
||||||
Code(BasicCoverageBlock),
|
|
||||||
//
|
|
||||||
// Branch and MC/DC mappings are more complex, so they are represented
|
|
||||||
// separately.
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(super) struct BcbMapping {
|
pub(super) struct CodeMapping {
|
||||||
pub(super) kind: BcbMappingKind,
|
|
||||||
pub(super) span: Span,
|
pub(super) span: Span,
|
||||||
|
pub(super) bcb: BasicCoverageBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This is separate from [`BcbMappingKind`] to help prepare for larger changes
|
/// This is separate from [`MCDCBranch`] to help prepare for larger changes
|
||||||
/// that will be needed for improved branch coverage in the future.
|
/// that will be needed for improved branch coverage in the future.
|
||||||
/// (See <https://github.com/rust-lang/rust/pull/124217>.)
|
/// (See <https://github.com/rust-lang/rust/pull/124217>.)
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -62,7 +54,7 @@ pub(super) struct MCDCDecision {
|
|||||||
|
|
||||||
pub(super) struct CoverageSpans {
|
pub(super) struct CoverageSpans {
|
||||||
bcb_has_mappings: BitSet<BasicCoverageBlock>,
|
bcb_has_mappings: BitSet<BasicCoverageBlock>,
|
||||||
pub(super) mappings: Vec<BcbMapping>,
|
pub(super) code_mappings: Vec<CodeMapping>,
|
||||||
pub(super) branch_pairs: Vec<BcbBranchPair>,
|
pub(super) branch_pairs: Vec<BcbBranchPair>,
|
||||||
test_vector_bitmap_bytes: u32,
|
test_vector_bitmap_bytes: u32,
|
||||||
pub(super) mcdc_branches: Vec<MCDCBranch>,
|
pub(super) mcdc_branches: Vec<MCDCBranch>,
|
||||||
@ -88,7 +80,7 @@ pub(super) fn generate_coverage_spans(
|
|||||||
hir_info: &ExtractedHirInfo,
|
hir_info: &ExtractedHirInfo,
|
||||||
basic_coverage_blocks: &CoverageGraph,
|
basic_coverage_blocks: &CoverageGraph,
|
||||||
) -> Option<CoverageSpans> {
|
) -> Option<CoverageSpans> {
|
||||||
let mut mappings = vec![];
|
let mut code_mappings = vec![];
|
||||||
let mut branch_pairs = vec![];
|
let mut branch_pairs = vec![];
|
||||||
let mut mcdc_branches = vec![];
|
let mut mcdc_branches = vec![];
|
||||||
let mut mcdc_decisions = vec![];
|
let mut mcdc_decisions = vec![];
|
||||||
@ -99,10 +91,10 @@ pub(super) fn generate_coverage_spans(
|
|||||||
// outer function will be unhelpful, so just keep the signature span
|
// outer function will be unhelpful, so just keep the signature span
|
||||||
// and ignore all of the spans in the MIR body.
|
// and ignore all of the spans in the MIR body.
|
||||||
if let Some(span) = hir_info.fn_sig_span_extended {
|
if let Some(span) = hir_info.fn_sig_span_extended {
|
||||||
mappings.push(BcbMapping { kind: BcbMappingKind::Code(START_BCB), span });
|
code_mappings.push(CodeMapping { span, bcb: START_BCB });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
extract_refined_covspans(mir_body, hir_info, basic_coverage_blocks, &mut mappings);
|
extract_refined_covspans(mir_body, hir_info, basic_coverage_blocks, &mut code_mappings);
|
||||||
|
|
||||||
branch_pairs.extend(extract_branch_pairs(mir_body, hir_info, basic_coverage_blocks));
|
branch_pairs.extend(extract_branch_pairs(mir_body, hir_info, basic_coverage_blocks));
|
||||||
|
|
||||||
@ -115,7 +107,7 @@ pub(super) fn generate_coverage_spans(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if mappings.is_empty()
|
if code_mappings.is_empty()
|
||||||
&& branch_pairs.is_empty()
|
&& branch_pairs.is_empty()
|
||||||
&& mcdc_branches.is_empty()
|
&& mcdc_branches.is_empty()
|
||||||
&& mcdc_decisions.is_empty()
|
&& mcdc_decisions.is_empty()
|
||||||
@ -129,10 +121,8 @@ pub(super) fn generate_coverage_spans(
|
|||||||
bcb_has_mappings.insert(bcb);
|
bcb_has_mappings.insert(bcb);
|
||||||
};
|
};
|
||||||
|
|
||||||
for &BcbMapping { kind, span: _ } in &mappings {
|
for &CodeMapping { span: _, bcb } in &code_mappings {
|
||||||
match kind {
|
insert(bcb);
|
||||||
BcbMappingKind::Code(bcb) => insert(bcb),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for &BcbBranchPair { true_bcb, false_bcb, .. } in &branch_pairs {
|
for &BcbBranchPair { true_bcb, false_bcb, .. } in &branch_pairs {
|
||||||
insert(true_bcb);
|
insert(true_bcb);
|
||||||
@ -154,7 +144,7 @@ pub(super) fn generate_coverage_spans(
|
|||||||
|
|
||||||
Some(CoverageSpans {
|
Some(CoverageSpans {
|
||||||
bcb_has_mappings,
|
bcb_has_mappings,
|
||||||
mappings,
|
code_mappings,
|
||||||
branch_pairs,
|
branch_pairs,
|
||||||
test_vector_bitmap_bytes,
|
test_vector_bitmap_bytes,
|
||||||
mcdc_branches,
|
mcdc_branches,
|
||||||
|
@ -9,7 +9,7 @@ mod tests;
|
|||||||
|
|
||||||
use self::counters::{CounterIncrementSite, CoverageCounters};
|
use self::counters::{CounterIncrementSite, CoverageCounters};
|
||||||
use self::graph::{BasicCoverageBlock, CoverageGraph};
|
use self::graph::{BasicCoverageBlock, CoverageGraph};
|
||||||
use self::mappings::{BcbBranchPair, BcbMapping, BcbMappingKind, CoverageSpans};
|
use self::mappings::{BcbBranchPair, CoverageSpans};
|
||||||
|
|
||||||
use crate::MirPass;
|
use crate::MirPass;
|
||||||
|
|
||||||
@ -150,12 +150,10 @@ fn create_mappings<'tcx>(
|
|||||||
|
|
||||||
let mut mappings = Vec::new();
|
let mut mappings = Vec::new();
|
||||||
|
|
||||||
mappings.extend(coverage_spans.mappings.iter().filter_map(
|
mappings.extend(coverage_spans.code_mappings.iter().filter_map(
|
||||||
|&BcbMapping { kind: bcb_mapping_kind, span }| {
|
|&mappings::CodeMapping { span, bcb }| {
|
||||||
let kind = match bcb_mapping_kind {
|
|
||||||
BcbMappingKind::Code(bcb) => MappingKind::Code(term_for_bcb(bcb)),
|
|
||||||
};
|
|
||||||
let code_region = region_for_span(span)?;
|
let code_region = region_for_span(span)?;
|
||||||
|
let kind = MappingKind::Code(term_for_bcb(bcb));
|
||||||
Some(Mapping { kind, code_region })
|
Some(Mapping { kind, code_region })
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -2,7 +2,7 @@ use rustc_middle::mir;
|
|||||||
use rustc_span::{BytePos, Span};
|
use rustc_span::{BytePos, Span};
|
||||||
|
|
||||||
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
|
use crate::coverage::graph::{BasicCoverageBlock, CoverageGraph};
|
||||||
use crate::coverage::mappings::{BcbMapping, BcbMappingKind};
|
use crate::coverage::mappings;
|
||||||
use crate::coverage::spans::from_mir::SpanFromMir;
|
use crate::coverage::spans::from_mir::SpanFromMir;
|
||||||
use crate::coverage::ExtractedHirInfo;
|
use crate::coverage::ExtractedHirInfo;
|
||||||
|
|
||||||
@ -17,14 +17,14 @@ pub(super) fn extract_refined_covspans(
|
|||||||
mir_body: &mir::Body<'_>,
|
mir_body: &mir::Body<'_>,
|
||||||
hir_info: &ExtractedHirInfo,
|
hir_info: &ExtractedHirInfo,
|
||||||
basic_coverage_blocks: &CoverageGraph,
|
basic_coverage_blocks: &CoverageGraph,
|
||||||
mappings: &mut impl Extend<BcbMapping>,
|
code_mappings: &mut impl Extend<mappings::CodeMapping>,
|
||||||
) {
|
) {
|
||||||
let sorted_spans =
|
let sorted_spans =
|
||||||
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
|
from_mir::mir_to_initial_sorted_coverage_spans(mir_body, hir_info, basic_coverage_blocks);
|
||||||
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
|
let coverage_spans = SpansRefiner::refine_sorted_spans(sorted_spans);
|
||||||
mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
|
code_mappings.extend(coverage_spans.into_iter().map(|RefinedCovspan { bcb, span, .. }| {
|
||||||
// Each span produced by the generator represents an ordinary code region.
|
// Each span produced by the generator represents an ordinary code region.
|
||||||
BcbMapping { kind: BcbMappingKind::Code(bcb), span }
|
mappings::CodeMapping { span, bcb }
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user