Skip to content

Commit 741ed01

Browse files
committed
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.
1 parent 0da95bd commit 741ed01

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

compiler/rustc_mir_transform/src/coverage/mappings.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ pub(super) struct MCDCDecision {
5656

5757
#[derive(Default)]
5858
pub(super) struct ExtractedMappings {
59+
/// Store our own copy of [`CoverageGraph::num_nodes`], so that we don't
60+
/// need access to the whole graph when allocating per-BCB data. This is
61+
/// only public so that other code can still use exhaustive destructuring.
62+
pub(super) num_bcbs: usize,
5963
pub(super) code_mappings: Vec<CodeMapping>,
6064
pub(super) branch_pairs: Vec<BranchPair>,
6165
pub(super) mcdc_bitmap_bytes: u32,
@@ -106,6 +110,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
106110
);
107111

108112
ExtractedMappings {
113+
num_bcbs: basic_coverage_blocks.num_nodes(),
109114
code_mappings,
110115
branch_pairs,
111116
mcdc_bitmap_bytes,
@@ -115,12 +120,10 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>(
115120
}
116121

117122
impl ExtractedMappings {
118-
pub(super) fn all_bcbs_with_counter_mappings(
119-
&self,
120-
basic_coverage_blocks: &CoverageGraph, // Only used for allocating a correctly-sized set
121-
) -> BitSet<BasicCoverageBlock> {
123+
pub(super) fn all_bcbs_with_counter_mappings(&self) -> BitSet<BasicCoverageBlock> {
122124
// Fully destructure self to make sure we don't miss any fields that have mappings.
123125
let Self {
126+
num_bcbs,
124127
code_mappings,
125128
branch_pairs,
126129
mcdc_bitmap_bytes: _,
@@ -129,7 +132,7 @@ impl ExtractedMappings {
129132
} = self;
130133

131134
// Identify which BCBs have one or more mappings.
132-
let mut bcbs_with_counter_mappings = BitSet::new_empty(basic_coverage_blocks.num_nodes());
135+
let mut bcbs_with_counter_mappings = BitSet::new_empty(*num_bcbs);
133136
let mut insert = |bcb| {
134137
bcbs_with_counter_mappings.insert(bcb);
135138
};

compiler/rustc_mir_transform/src/coverage/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ fn instrument_function_for_coverage<'tcx>(tcx: TyCtxt<'tcx>, mir_body: &mut mir:
8888
// every coverage span has a `Counter` or `Expression` assigned to its `BasicCoverageBlock`
8989
// and all `Expression` dependencies (operands) are also generated, for any other
9090
// `BasicCoverageBlock`s not already associated with a coverage span.
91-
let bcbs_with_counter_mappings =
92-
extracted_mappings.all_bcbs_with_counter_mappings(&basic_coverage_blocks);
91+
let bcbs_with_counter_mappings = extracted_mappings.all_bcbs_with_counter_mappings();
9392
if bcbs_with_counter_mappings.is_empty() {
9493
// No relevant spans were found in MIR, so skip instrumenting this function.
9594
return;
@@ -163,6 +162,7 @@ fn create_mappings<'tcx>(
163162

164163
// Fully destructure the mappings struct to make sure we don't miss any kinds.
165164
let ExtractedMappings {
165+
num_bcbs: _,
166166
code_mappings,
167167
branch_pairs,
168168
mcdc_bitmap_bytes: _,

0 commit comments

Comments
 (0)