mirror of https://github.com/rust-lang/rust.git
coverage: Store a copy of `num_bcbs` in `ExtractedMappings`
This makes it possible to allocate per-BCB data structures without needing access to the whole graph.
This commit is contained in:
parent
0da95bd869
commit
741ed01646
|
@ -56,6 +56,10 @@ pub(super) struct MCDCDecision {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub(super) struct ExtractedMappings {
|
pub(super) struct ExtractedMappings {
|
||||||
|
/// Store our own copy of [`CoverageGraph::num_nodes`], so that we don't
|
||||||
|
/// need access to the whole graph when allocating per-BCB data. This is
|
||||||
|
/// only public so that other code can still use exhaustive destructuring.
|
||||||
|
pub(super) num_bcbs: usize,
|
||||||
pub(super) code_mappings: Vec<CodeMapping>,
|
pub(super) code_mappings: Vec<CodeMapping>,
|
||||||
pub(super) branch_pairs: Vec<BranchPair>,
|
pub(super) branch_pairs: Vec<BranchPair>,
|
||||||
pub(super) mcdc_bitmap_bytes: u32,
|
pub(super) mcdc_bitmap_bytes: u32,
|
||||||
|
@ -106,6 +110,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
|
||||||
);
|
);
|
||||||
|
|
||||||
ExtractedMappings {
|
ExtractedMappings {
|
||||||
|
num_bcbs: basic_coverage_blocks.num_nodes(),
|
||||||
code_mappings,
|
code_mappings,
|
||||||
branch_pairs,
|
branch_pairs,
|
||||||
mcdc_bitmap_bytes,
|
mcdc_bitmap_bytes,
|
||||||
|
@ -115,12 +120,10 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ExtractedMappings {
|
impl ExtractedMappings {
|
||||||
pub(super) fn all_bcbs_with_counter_mappings(
|
pub(super) fn all_bcbs_with_counter_mappings(&self) -> BitSet<BasicCoverageBlock> {
|
||||||
&self,
|
|
||||||
basic_coverage_blocks: &CoverageGraph, // Only used for allocating a correctly-sized set
|
|
||||||
) -> BitSet<BasicCoverageBlock> {
|
|
||||||
// Fully destructure self to make sure we don't miss any fields that have mappings.
|
// Fully destructure self to make sure we don't miss any fields that have mappings.
|
||||||
let Self {
|
let Self {
|
||||||
|
num_bcbs,
|
||||||
code_mappings,
|
code_mappings,
|
||||||
branch_pairs,
|
branch_pairs,
|
||||||
mcdc_bitmap_bytes: _,
|
mcdc_bitmap_bytes: _,
|
||||||
|
@ -129,7 +132,7 @@ impl ExtractedMappings {
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
// Identify which BCBs have one or more mappings.
|
// Identify which BCBs have one or more mappings.
|
||||||
let mut bcbs_with_counter_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes());
|
let mut bcbs_with_counter_mappings = BitSet::new_empty(*num_bcbs);
|
||||||
let mut insert = |bcb| {
|
let mut insert = |bcb| {
|
||||||
bcbs_with_counter_mappings.insert(bcb);
|
bcbs_with_counter_mappings.insert(bcb);
|
||||||
};
|
};
|
||||||
|
|
|
@ -88,8 +88,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
|
||||||
// every coverage span has a `Counter` or `Expression` assigned to its `BasicCoverageBlock`
|
// every coverage span has a `Counter` or `Expression` assigned to its `BasicCoverageBlock`
|
||||||
// and all `Expression` dependencies (operands) are also generated, for any other
|
// and all `Expression` dependencies (operands) are also generated, for any other
|
||||||
// `BasicCoverageBlock`s not already associated with a coverage span.
|
// `BasicCoverageBlock`s not already associated with a coverage span.
|
||||||
let bcbs_with_counter_mappings =
|
let bcbs_with_counter_mappings = extracted_mappings.all_bcbs_with_counter_mappings();
|
||||||
extracted_mappings.all_bcbs_with_counter_mappings(&basic_coverage_blocks);
|
|
||||||
if bcbs_with_counter_mappings.is_empty() {
|
if bcbs_with_counter_mappings.is_empty() {
|
||||||
// No relevant spans were found in MIR, so skip instrumenting this function.
|
// No relevant spans were found in MIR, so skip instrumenting this function.
|
||||||
return;
|
return;
|
||||||
|
@ -163,6 +162,7 @@ fn create_mappings<'tcx>(
|
||||||
|
|
||||||
// Fully destructure the mappings struct to make sure we don't miss any kinds.
|
// Fully destructure the mappings struct to make sure we don't miss any kinds.
|
||||||
let ExtractedMappings {
|
let ExtractedMappings {
|
||||||
|
num_bcbs: _,
|
||||||
code_mappings,
|
code_mappings,
|
||||||
branch_pairs,
|
branch_pairs,
|
||||||
mcdc_bitmap_bytes: _,
|
mcdc_bitmap_bytes: _,
|
||||||
|
|
Loading…
Reference in New Issue