Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
de89ffc
CI: split i686-msvc job to two free runners
marcoieni Jan 17, 2025
ffc7b5d
ci: use ghcr ubuntu image for mingw-check-tidy
marcoieni Jan 17, 2025
dfb8162
Drop MIPS glibc 2.23 patches that reside in crosstool-ng now
Gelbpunkt Jan 14, 2025
067cac9
Fix ICE in resolving associated items as non-bindings
frank-king Jan 18, 2025
a14c35c
coverage: Remove the `Site` enum now that we only instrument nodes
Zalathar Jan 17, 2025
4839944
coverage: Move `phys_counter_for_node` into `CoverageCounters`
Zalathar Jan 17, 2025
4170b93
coverage: Flatten top-level counter creation into plain functions
Zalathar Jan 17, 2025
6000d5c
coverage: Remove `BcbCounter` and `BcbExpression`
Zalathar Jan 17, 2025
ea0c86c
coverage: Add a few more comments to counter creation
Zalathar Jan 18, 2025
2a180a9
Get rid of `ToPolyTraitRef`
compiler-errors Jan 18, 2025
ed5f631
use `Reverse` instead of manually doing reverse comparison
yotamofek Jan 18, 2025
a909520
use slice patterns for checking for elements of slice
yotamofek Jan 18, 2025
d4f41b3
Rollup merge of #135616 - marcoieni:split-i686-msvc-job, r=Kobzol
matthiaskrgr Jan 18, 2025
b78d597
Rollup merge of #135623 - marcoieni:mingw-check-tidy-dockerfile, r=Ko…
matthiaskrgr Jan 18, 2025
fd2ec9a
Rollup merge of #135640 - Gelbpunkt:drop-mips-glibc-patches, r=Kobzol
matthiaskrgr Jan 18, 2025
7c3e804
Rollup merge of #135663 - frank-king:fix/135614, r=compiler-errors
matthiaskrgr Jan 18, 2025
9d99f9c
Rollup merge of #135677 - yotamofek:resolve-cleanups2, r=compiler-errors
matthiaskrgr Jan 18, 2025
41ea084
Rollup merge of #135680 - Zalathar:counters-cleanup, r=compiler-errors
matthiaskrgr Jan 18, 2025
1cef579
Rollup merge of #135697 - compiler-errors:poly-trait-ref, r=lqd
matthiaskrgr Jan 18, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
coverage: Remove the Site enum now that we only instrument nodes
  • Loading branch information
Zalathar committed Jan 18, 2025
commit a14c35c507e760933cede5208ea12787c72f14d5
39 changes: 13 additions & 26 deletions compiler/rustc_mir_transform/src/coverage/counters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CounterId, Site>,
counter_increment_sites: IndexVec<CounterId, BasicCoverageBlock>,

/// Coverage counters/expressions that are associated with individual BCBs.
node_counters: IndexVec<BasicCoverageBlock, Option<BcbCounter>>,
Expand Down Expand Up @@ -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 }
}

Expand Down Expand Up @@ -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<Item = (CounterId, Site)> + Captures<'_> {
) -> impl Iterator<Item = (CounterId, BasicCoverageBlock)> + Captures<'_> {
self.counter_increment_sites.iter_enumerated().map(|(id, &site)| (id, site))
}

Expand Down Expand Up @@ -221,15 +212,15 @@ impl CoverageCounters {
struct Transcriber {
old: NodeCounters<BasicCoverageBlock>,
new: CoverageCounters,
phys_counter_for_site: FxHashMap<Site, BcbCounter>,
phys_counter_for_node: FxHashMap<BasicCoverageBlock, BcbCounter>,
}

impl Transcriber {
fn new(num_nodes: usize, old: NodeCounters<BasicCoverageBlock>) -> Self {
Self {
old,
new: CoverageCounters::with_num_bcbs(num_nodes),
phys_counter_for_site: FxHashMap::default(),
phys_counter_for_node: FxHashMap::default(),
}
}

Expand All @@ -238,7 +229,6 @@ impl Transcriber {
bcb_needs_counter: &DenseBitSet<BasicCoverageBlock>,
) -> 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 {
Expand All @@ -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![];
}
Expand All @@ -260,10 +250,7 @@ impl Transcriber {
neg.sort();

let mut new_counters_for_sites = |sites: Vec<BasicCoverageBlock>| {
sites
.into_iter()
.map(|node| self.ensure_phys_counter(Site::Node { bcb: node }))
.collect::<Vec<_>>()
sites.into_iter().map(|node| self.ensure_phys_counter(node)).collect::<Vec<_>>()
};
let mut pos = new_counters_for_sites(pos);
let mut neg = new_counters_for_sites(neg);
Expand All @@ -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))
}
}
12 changes: 3 additions & 9 deletions compiler/rustc_mir_transform/src/coverage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down