diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2025-01-18 22:12:30 +1100 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2025-01-18 22:14:16 +1100 |
| commit | ea0c86c434ae4cc306c0bf43f933bd7a018232a1 (patch) | |
| tree | 162efb3451bdadb77f20e31d0847c9888c0eaed7 | |
| parent | 6000d5c462b767e3c5871034824964d0b0897a26 (diff) | |
| download | rust-ea0c86c434ae4cc306c0bf43f933bd7a018232a1.tar.gz rust-ea0c86c434ae4cc306c0bf43f933bd7a018232a1.zip | |
coverage: Add a few more comments to counter creation
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/counters.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/counters.rs b/compiler/rustc_mir_transform/src/coverage/counters.rs index 7a5cea2b68c..8d397f63cc7 100644 --- a/compiler/rustc_mir_transform/src/coverage/counters.rs +++ b/compiler/rustc_mir_transform/src/coverage/counters.rs @@ -25,15 +25,21 @@ pub(super) fn make_bcb_counters( graph: &CoverageGraph, bcb_needs_counter: &DenseBitSet<BasicCoverageBlock>, ) -> CoverageCounters { + // Create the derived graphs that are necessary for subsequent steps. let balanced_graph = BalancedFlowGraph::for_graph(graph, |n| !graph[n].is_out_summable); let merged_graph = MergedNodeFlowGraph::for_balanced_graph(&balanced_graph); + // Use those graphs to determine which nodes get physical counters, and how + // to compute the execution counts of other nodes from those counters. let nodes = make_node_counter_priority_list(graph, balanced_graph); let node_counters = merged_graph.make_node_counters(&nodes); + // Convert the counters into a form suitable for embedding into MIR. transcribe_counters(&node_counters, bcb_needs_counter) } +/// Arranges the nodes in `balanced_graph` into a list, such that earlier nodes +/// take priority in being given a counter expression instead of a physical counter. fn make_node_counter_priority_list( graph: &CoverageGraph, balanced_graph: BalancedFlowGraph<&CoverageGraph>, @@ -67,6 +73,7 @@ fn make_node_counter_priority_list( nodes } +// Converts node counters into a form suitable for embedding into MIR. fn transcribe_counters( old: &NodeCounters<BasicCoverageBlock>, bcb_needs_counter: &DenseBitSet<BasicCoverageBlock>, @@ -74,6 +81,9 @@ fn transcribe_counters( let mut new = CoverageCounters::with_num_bcbs(bcb_needs_counter.domain_size()); for bcb in bcb_needs_counter.iter() { + // Our counter-creation algorithm doesn't guarantee that a counter + // expression starts or ends with a positive term, so partition the + // counters into "positive" and "negative" lists for easier handling. let (mut pos, mut neg): (Vec<_>, Vec<_>) = old.counter_expr(bcb).iter().partition_map(|&CounterTerm { node, op }| match op { Op::Add => Either::Left(node), @@ -89,6 +99,10 @@ fn transcribe_counters( neg = vec![]; } + // These intermediate sorts are not strictly necessary, but were helpful + // in reducing churn when switching to the current counter-creation scheme. + // They also help to slightly decrease the overall size of the expression + // table, due to more subexpressions being shared. pos.sort(); neg.sort(); @@ -98,6 +112,7 @@ fn transcribe_counters( let mut pos = new_counters_for_sites(pos); let mut neg = new_counters_for_sites(neg); + // These sorts are also not strictly necessary; see above. pos.sort(); neg.sort(); |
