diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 1a9323329f6..eeb8f65fdf9 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -53,21 +53,12 @@ struct BcbExpression { rhs: BcbCounter, } -/// Enum representing either a node or an edge in the coverage graph. -/// -/// FIXME(#135481): This enum is no longer needed now that we only instrument -/// nodes and not edges. It can be removed in a subsequent PR. -#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub(super) enum Site { - Node { bcb: BasicCoverageBlock }, -} - /// Generates and stores coverage counter and coverage expression information -/// associated with nodes/edges in the BCB graph. +/// associated with nodes in the coverage graph. pub(super) struct CoverageCounters { /// List of places where a counter-increment statement should be injected /// into MIR, each with its corresponding counter ID. - counter_increment_sites: IndexVec, + counter_increment_sites: IndexVec, /// Coverage counters/expressions that are associated with individual BCBs. node_counters: IndexVec>, @@ -130,9 +121,9 @@ impl CoverageCounters { } } - /// Creates a new physical counter for a BCB node or edge. - fn make_phys_counter(&mut self, site: Site) -> BcbCounter { - let id = self.counter_increment_sites.push(site); + /// Creates a new physical counter for a BCB node. + fn make_phys_counter(&mut self, bcb: BasicCoverageBlock) -> BcbCounter { + let id = self.counter_increment_sites.push(bcb); BcbCounter::Counter { id } } @@ -177,12 +168,12 @@ impl CoverageCounters { self.node_counters[bcb].map(|counter| counter.as_term()) } - /// Returns an iterator over all the nodes/edges in the coverage graph that + /// Returns an iterator over all the nodes in the coverage graph that /// should have a counter-increment statement injected into MIR, along with /// each site's corresponding counter ID. pub(super) fn counter_increment_sites( &self, - ) -> impl Iterator + Captures<'_> { + ) -> impl Iterator + Captures<'_> { self.counter_increment_sites.iter_enumerated().map(|(id, &site)| (id, site)) } @@ -221,7 +212,7 @@ impl CoverageCounters { struct Transcriber { old: NodeCounters, new: CoverageCounters, - phys_counter_for_site: FxHashMap, + phys_counter_for_node: FxHashMap, } impl Transcriber { @@ -229,7 +220,7 @@ impl Transcriber { Self { old, new: CoverageCounters::with_num_bcbs(num_nodes), - phys_counter_for_site: FxHashMap::default(), + phys_counter_for_node: FxHashMap::default(), } } @@ -238,7 +229,6 @@ impl Transcriber { bcb_needs_counter: &DenseBitSet, ) -> CoverageCounters { for bcb in bcb_needs_counter.iter() { - let site = Site::Node { bcb }; let (mut pos, mut neg): (Vec<_>, Vec<_>) = self.old.counter_expr(bcb).iter().partition_map( |&CounterTerm { node, op }| match op { @@ -251,7 +241,7 @@ impl Transcriber { // If we somehow end up with no positive terms, fall back to // creating a physical counter. There's no known way for this // to happen, but we can avoid an ICE if it does. - debug_assert!(false, "{site:?} has no positive counter terms"); + debug_assert!(false, "{bcb:?} has no positive counter terms"); pos = vec![bcb]; neg = vec![]; } @@ -260,10 +250,7 @@ impl Transcriber { neg.sort(); let mut new_counters_for_sites = |sites: Vec| { - sites - .into_iter() - .map(|node| self.ensure_phys_counter(Site::Node { bcb: node })) - .collect::>() + sites.into_iter().map(|node| self.ensure_phys_counter(node)).collect::>() }; let mut pos = new_counters_for_sites(pos); let mut neg = new_counters_for_sites(neg); @@ -279,7 +266,7 @@ impl Transcriber { self.new } - fn ensure_phys_counter(&mut self, site: Site) -> BcbCounter { - *self.phys_counter_for_site.entry(site).or_insert_with(|| self.new.make_phys_counter(site)) + fn ensure_phys_counter(&mut self, bcb: BasicCoverageBlock) -> BcbCounter { + *self.phys_counter_for_node.entry(bcb).or_insert_with(|| self.new.make_phys_counter(bcb)) } } diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index b1b609595b7..cca444306ed 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -21,7 +21,7 @@ use rustc_span::Span; use rustc_span::def_id::LocalDefId; use tracing::{debug, debug_span, trace}; -use crate::coverage::counters::{CoverageCounters, Site}; +use crate::coverage::counters::CoverageCounters; use crate::coverage::graph::CoverageGraph; use crate::coverage::mappings::ExtractedMappings; @@ -239,14 +239,8 @@ fn inject_coverage_statements<'tcx>( coverage_counters: &CoverageCounters, ) { // Inject counter-increment statements into MIR. - for (id, site) in coverage_counters.counter_increment_sites() { - // Determine the block to inject a counter-increment statement into. - // For BCB nodes this is just their first block, but for edges we need - // to create a new block between the two BCBs, and inject into that. - let target_bb = match site { - Site::Node { bcb } => graph[bcb].leader_bb(), - }; - + for (id, bcb) in coverage_counters.counter_increment_sites() { + let target_bb = graph[bcb].leader_bb(); inject_statement(mir_body, CoverageKind::CounterIncrement { id }, target_bb); }