diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-07-15 21:11:50 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-15 21:11:50 +0200 |
| commit | e5d65e46ed2734b0c20aa9d8159c1b31121a72ef (patch) | |
| tree | 15f7d24652c8018ff2bd6fe83bb99067a13d19b9 /compiler/rustc_mir_transform/src/coverage/mappings.rs | |
| parent | cd25232656623fd956aff8b6af83638a7225ad27 (diff) | |
| parent | d4f1f9242624f007c48d358ae3f62d046dee8925 (diff) | |
| download | rust-e5d65e46ed2734b0c20aa9d8159c1b31121a72ef.tar.gz rust-e5d65e46ed2734b0c20aa9d8159c1b31121a72ef.zip | |
Rollup merge of #127758 - Zalathar:expression-used, r=oli-obk
coverage: Restrict `ExpressionUsed` simplification to `Code` mappings In the future, branch and MC/DC mappings might have expressions that don't correspond to any single point in the control-flow graph. That makes it trickier to keep track of which expressions should expect an `ExpressionUsed` node. We therefore sidestep that complexity by only performing `ExpressionUsed` simplification for expressions associated directly with ordinary `Code` mappings. (This simplification step is inherited from the original coverage implementation, which only supported `Code` mappings anyway, so there's no particular reason to extend it to other kinds of mappings unless we specifically choose to.) Relevant to: - #124154 - #126677 - #124278 ```@rustbot``` label +A-code-coverage
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/mappings.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/mappings.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/mappings.rs b/compiler/rustc_mir_transform/src/coverage/mappings.rs index 25297245172..2ac08ea85d2 100644 --- a/compiler/rustc_mir_transform/src/coverage/mappings.rs +++ b/compiler/rustc_mir_transform/src/coverage/mappings.rs @@ -56,6 +56,10 @@ pub(super) struct MCDCDecision { #[derive(Default)] 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) branch_pairs: Vec<BranchPair>, pub(super) mcdc_bitmap_bytes: u32, @@ -106,6 +110,7 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>( ); ExtractedMappings { + num_bcbs: basic_coverage_blocks.num_nodes(), code_mappings, branch_pairs, mcdc_bitmap_bytes, @@ -115,12 +120,10 @@ pub(super) fn extract_all_mapping_info_from_mir<'tcx>( } impl ExtractedMappings { - pub(super) fn all_bcbs_with_counter_mappings( - &self, - basic_coverage_blocks: &CoverageGraph, // Only used for allocating a correctly-sized set - ) -> BitSet<BasicCoverageBlock> { + pub(super) fn all_bcbs_with_counter_mappings(&self) -> BitSet<BasicCoverageBlock> { // Fully destructure self to make sure we don't miss any fields that have mappings. let Self { + num_bcbs, code_mappings, branch_pairs, mcdc_bitmap_bytes: _, @@ -129,7 +132,7 @@ impl ExtractedMappings { } = self; // 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| { bcbs_with_counter_mappings.insert(bcb); }; @@ -156,6 +159,15 @@ impl ExtractedMappings { bcbs_with_counter_mappings } + + /// Returns the set of BCBs that have one or more `Code` mappings. + pub(super) fn bcbs_with_ordinary_code_mappings(&self) -> BitSet<BasicCoverageBlock> { + let mut bcbs = BitSet::new_empty(self.num_bcbs); + for &CodeMapping { span: _, bcb } in &self.code_mappings { + bcbs.insert(bcb); + } + bcbs + } } fn resolve_block_markers( |
