Skip to content

Commit 7ecc677

Browse files
committed
coverage: Rename CounterIncrementSite to just Site
A "site" is a node or edge in the coverage graph.
1 parent 2a3b4a0 commit 7ecc677

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

compiler/rustc_mir_transform/src/coverage/counters.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ struct BcbExpression {
4343
rhs: BcbCounter,
4444
}
4545

46-
#[derive(Debug)]
47-
pub(super) enum CounterIncrementSite {
46+
/// Enum representing either a node or an edge in the coverage graph.
47+
#[derive(Clone, Copy, Debug)]
48+
pub(super) enum Site {
4849
Node { bcb: BasicCoverageBlock },
4950
Edge { from_bcb: BasicCoverageBlock, to_bcb: BasicCoverageBlock },
5051
}
@@ -54,7 +55,7 @@ pub(super) enum CounterIncrementSite {
5455
pub(super) struct CoverageCounters {
5556
/// List of places where a counter-increment statement should be injected
5657
/// into MIR, each with its corresponding counter ID.
57-
counter_increment_sites: IndexVec<CounterId, CounterIncrementSite>,
58+
counter_increment_sites: IndexVec<CounterId, Site>,
5859

5960
/// Coverage counters/expressions that are associated with individual BCBs.
6061
node_counters: IndexVec<BasicCoverageBlock, Option<BcbCounter>>,
@@ -98,14 +99,14 @@ impl CoverageCounters {
9899

99100
/// Shared helper used by [`Self::make_phys_node_counter`] and
100101
/// [`Self::make_phys_edge_counter`]. Don't call this directly.
101-
fn make_counter_inner(&mut self, site: CounterIncrementSite) -> BcbCounter {
102+
fn make_counter_inner(&mut self, site: Site) -> BcbCounter {
102103
let id = self.counter_increment_sites.push(site);
103104
BcbCounter::Counter { id }
104105
}
105106

106107
/// Creates a new physical counter for a BCB node.
107108
fn make_phys_node_counter(&mut self, bcb: BasicCoverageBlock) -> BcbCounter {
108-
self.make_counter_inner(CounterIncrementSite::Node { bcb })
109+
self.make_counter_inner(Site::Node { bcb })
109110
}
110111

111112
/// Creates a new physical counter for a BCB edge.
@@ -114,7 +115,7 @@ impl CoverageCounters {
114115
from_bcb: BasicCoverageBlock,
115116
to_bcb: BasicCoverageBlock,
116117
) -> BcbCounter {
117-
self.make_counter_inner(CounterIncrementSite::Edge { from_bcb, to_bcb })
118+
self.make_counter_inner(Site::Edge { from_bcb, to_bcb })
118119
}
119120

120121
fn make_expression(&mut self, lhs: BcbCounter, op: Op, rhs: BcbCounter) -> BcbCounter {
@@ -224,8 +225,8 @@ impl CoverageCounters {
224225
/// each site's corresponding counter ID.
225226
pub(super) fn counter_increment_sites(
226227
&self,
227-
) -> impl Iterator<Item = (CounterId, &CounterIncrementSite)> {
228-
self.counter_increment_sites.iter_enumerated()
228+
) -> impl Iterator<Item = (CounterId, Site)> + Captures<'_> {
229+
self.counter_increment_sites.iter_enumerated().map(|(id, &site)| (id, site))
229230
}
230231

231232
/// Returns an iterator over the subset of BCB nodes that have been associated

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_span::source_map::SourceMap;
2525
use rustc_span::{BytePos, Pos, SourceFile, Span};
2626
use tracing::{debug, debug_span, trace};
2727

28-
use crate::coverage::counters::{CounterIncrementSite, CoverageCounters};
28+
use crate::coverage::counters::{CoverageCounters, Site};
2929
use crate::coverage::graph::CoverageGraph;
3030
use crate::coverage::mappings::ExtractedMappings;
3131

@@ -265,13 +265,13 @@ fn inject_coverage_statements<'tcx>(
265265
coverage_counters: &CoverageCounters,
266266
) {
267267
// Inject counter-increment statements into MIR.
268-
for (id, counter_increment_site) in coverage_counters.counter_increment_sites() {
268+
for (id, site) in coverage_counters.counter_increment_sites() {
269269
// Determine the block to inject a counter-increment statement into.
270270
// For BCB nodes this is just their first block, but for edges we need
271271
// to create a new block between the two BCBs, and inject into that.
272-
let target_bb = match *counter_increment_site {
273-
CounterIncrementSite::Node { bcb } => basic_coverage_blocks[bcb].leader_bb(),
274-
CounterIncrementSite::Edge { from_bcb, to_bcb } => {
272+
let target_bb = match site {
273+
Site::Node { bcb } => basic_coverage_blocks[bcb].leader_bb(),
274+
Site::Edge { from_bcb, to_bcb } => {
275275
// Create a new block between the last block of `from_bcb` and
276276
// the first block of `to_bcb`.
277277
let from_bb = basic_coverage_blocks[from_bcb].last_bb();

0 commit comments

Comments
 (0)