Skip to content

Commit 1b198b3

Browse files
committed
Auto merge of #114786 - GuillaumeGomez:rollup-0cos5gn, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - #94667 (Add `Iterator::map_windows`) - #114069 (Allow using external builds of the compiler-rt profile lib) - #114354 (coverage: Store BCB counter info externally, not directly in the BCB graph) - #114625 (CI: use smaller machines in PR runs) - #114777 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2 parents ebbd715 + be6cda1 commit 1b198b3

File tree

19 files changed

+1034
-296
lines changed

19 files changed

+1034
-296
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ jobs:
5050
matrix:
5151
include:
5252
- name: mingw-check
53-
os: ubuntu-20.04-16core-64gb
53+
os: ubuntu-20.04-4core-16gb
5454
env: {}
5555
- name: mingw-check-tidy
56-
os: ubuntu-20.04-16core-64gb
56+
os: ubuntu-20.04-4core-16gb
5757
env: {}
5858
- name: x86_64-gnu-llvm-15
5959
os: ubuntu-20.04-16core-64gb

compiler/rustc_mir_transform/src/coverage/counters.rs

+151-81
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/coverage/debug.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
//! recursively, generating labels with nested operations, enclosed in parentheses
109109
//! (for example: `bcb2 + (bcb0 - bcb1)`).
110110
111+
use super::counters::CoverageCounters;
111112
use super::graph::{BasicCoverageBlock, BasicCoverageBlockData, CoverageGraph};
112113
use super::spans::CoverageSpan;
113114

@@ -659,18 +660,21 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
659660
mir_body: &mir::Body<'tcx>,
660661
pass_name: &str,
661662
basic_coverage_blocks: &CoverageGraph,
662-
debug_counters: &DebugCounters,
663+
coverage_counters: &CoverageCounters,
663664
graphviz_data: &GraphvizData,
664665
intermediate_expressions: &[CoverageKind],
665666
debug_used_expressions: &UsedExpressions,
666667
) {
668+
let debug_counters = &coverage_counters.debug_counters;
669+
667670
let mir_source = mir_body.source;
668671
let def_id = mir_source.def_id();
669672
let node_content = |bcb| {
670673
bcb_to_string_sections(
671674
tcx,
672675
mir_body,
673-
debug_counters,
676+
coverage_counters,
677+
bcb,
674678
&basic_coverage_blocks[bcb],
675679
graphviz_data.get_bcb_coverage_spans_with_counters(bcb),
676680
graphviz_data.get_bcb_dependency_counters(bcb),
@@ -736,12 +740,15 @@ pub(super) fn dump_coverage_graphviz<'tcx>(
736740
fn bcb_to_string_sections<'tcx>(
737741
tcx: TyCtxt<'tcx>,
738742
mir_body: &mir::Body<'tcx>,
739-
debug_counters: &DebugCounters,
743+
coverage_counters: &CoverageCounters,
744+
bcb: BasicCoverageBlock,
740745
bcb_data: &BasicCoverageBlockData,
741746
some_coverage_spans_with_counters: Option<&[(CoverageSpan, CoverageKind)]>,
742747
some_dependency_counters: Option<&[CoverageKind]>,
743748
some_intermediate_expressions: Option<&[CoverageKind]>,
744749
) -> Vec<String> {
750+
let debug_counters = &coverage_counters.debug_counters;
751+
745752
let len = bcb_data.basic_blocks.len();
746753
let mut sections = Vec::new();
747754
if let Some(collect_intermediate_expressions) = some_intermediate_expressions {
@@ -777,7 +784,7 @@ fn bcb_to_string_sections<'tcx>(
777784
.join(" \n"),
778785
));
779786
}
780-
if let Some(counter_kind) = &bcb_data.counter_kind {
787+
if let Some(counter_kind) = coverage_counters.bcb_counter(bcb) {
781788
sections.push(format!("{counter_kind:?}"));
782789
}
783790
let non_term_blocks = bcb_data.basic_blocks[0..len - 1]

compiler/rustc_mir_transform/src/coverage/graph.rs

+2-103
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
use super::Error;
2-
31
use itertools::Itertools;
4-
use rustc_data_structures::fx::FxHashMap;
52
use rustc_data_structures::graph::dominators::{self, Dominators};
63
use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode};
74
use rustc_index::bit_set::BitSet;
85
use rustc_index::{IndexSlice, IndexVec};
9-
use rustc_middle::mir::coverage::*;
106
use rustc_middle::mir::{self, BasicBlock, BasicBlockData, Terminator, TerminatorKind};
117

128
use std::cmp::Ordering;
@@ -15,10 +11,7 @@ use std::ops::{Index, IndexMut};
1511
const ID_SEPARATOR: &str = ",";
1612

1713
/// A coverage-specific simplification of the MIR control flow graph (CFG). The `CoverageGraph`s
18-
/// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s, plus a
19-
/// `CoverageKind` counter (to be added by `CoverageCounters::make_bcb_counters`), and an optional
20-
/// set of additional counters--if needed--to count incoming edges, if there are more than one.
21-
/// (These "edge counters" are eventually converted into new MIR `BasicBlock`s.)
14+
/// nodes are `BasicCoverageBlock`s, which encompass one or more MIR `BasicBlock`s.
2215
#[derive(Debug)]
2316
pub(super) struct CoverageGraph {
2417
bcbs: IndexVec<BasicCoverageBlock, BasicCoverageBlockData>,
@@ -195,13 +188,6 @@ impl CoverageGraph {
195188
self.bcbs.iter_enumerated()
196189
}
197190

198-
#[inline(always)]
199-
pub fn iter_enumerated_mut(
200-
&mut self,
201-
) -> impl Iterator<Item = (BasicCoverageBlock, &mut BasicCoverageBlockData)> {
202-
self.bcbs.iter_enumerated_mut()
203-
}
204-
205191
#[inline(always)]
206192
pub fn bcb_from_bb(&self, bb: BasicBlock) -> Option<BasicCoverageBlock> {
207193
if bb.index() < self.bb_to_bcb.len() { self.bb_to_bcb[bb] } else { None }
@@ -320,14 +306,12 @@ rustc_index::newtype_index! {
320306
#[derive(Debug, Clone)]
321307
pub(super) struct BasicCoverageBlockData {
322308
pub basic_blocks: Vec<BasicBlock>,
323-
pub counter_kind: Option<CoverageKind>,
324-
edge_from_bcbs: Option<FxHashMap<BasicCoverageBlock, CoverageKind>>,
325309
}
326310

327311
impl BasicCoverageBlockData {
328312
pub fn from(basic_blocks: Vec<BasicBlock>) -> Self {
329313
assert!(basic_blocks.len() > 0);
330-
Self { basic_blocks, counter_kind: None, edge_from_bcbs: None }
314+
Self { basic_blocks }
331315
}
332316

333317
#[inline(always)]
@@ -345,80 +329,6 @@ impl BasicCoverageBlockData {
345329
&mir_body[self.last_bb()].terminator()
346330
}
347331

348-
pub fn set_counter(&mut self, counter_kind: CoverageKind) -> Result<Operand, Error> {
349-
debug_assert!(
350-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
351-
// have an expression (to be injected into an existing `BasicBlock` represented by this
352-
// `BasicCoverageBlock`).
353-
self.edge_from_bcbs.is_none() || counter_kind.is_expression(),
354-
"attempt to add a `Counter` to a BCB target with existing incoming edge counters"
355-
);
356-
let operand = counter_kind.as_operand();
357-
if let Some(replaced) = self.counter_kind.replace(counter_kind) {
358-
Error::from_string(format!(
359-
"attempt to set a BasicCoverageBlock coverage counter more than once; \
360-
{self:?} already had counter {replaced:?}",
361-
))
362-
} else {
363-
Ok(operand)
364-
}
365-
}
366-
367-
#[inline(always)]
368-
pub fn counter(&self) -> Option<&CoverageKind> {
369-
self.counter_kind.as_ref()
370-
}
371-
372-
#[inline(always)]
373-
pub fn take_counter(&mut self) -> Option<CoverageKind> {
374-
self.counter_kind.take()
375-
}
376-
377-
pub fn set_edge_counter_from(
378-
&mut self,
379-
from_bcb: BasicCoverageBlock,
380-
counter_kind: CoverageKind,
381-
) -> Result<Operand, Error> {
382-
if level_enabled!(tracing::Level::DEBUG) {
383-
// If the BCB has an edge counter (to be injected into a new `BasicBlock`), it can also
384-
// have an expression (to be injected into an existing `BasicBlock` represented by this
385-
// `BasicCoverageBlock`).
386-
if self.counter_kind.as_ref().is_some_and(|c| !c.is_expression()) {
387-
return Error::from_string(format!(
388-
"attempt to add an incoming edge counter from {from_bcb:?} when the target BCB already \
389-
has a `Counter`"
390-
));
391-
}
392-
}
393-
let operand = counter_kind.as_operand();
394-
if let Some(replaced) =
395-
self.edge_from_bcbs.get_or_insert_default().insert(from_bcb, counter_kind)
396-
{
397-
Error::from_string(format!(
398-
"attempt to set an edge counter more than once; from_bcb: \
399-
{from_bcb:?} already had counter {replaced:?}",
400-
))
401-
} else {
402-
Ok(operand)
403-
}
404-
}
405-
406-
#[inline]
407-
pub fn edge_counter_from(&self, from_bcb: BasicCoverageBlock) -> Option<&CoverageKind> {
408-
if let Some(edge_from_bcbs) = &self.edge_from_bcbs {
409-
edge_from_bcbs.get(&from_bcb)
410-
} else {
411-
None
412-
}
413-
}
414-
415-
#[inline]
416-
pub fn take_edge_counters(
417-
&mut self,
418-
) -> Option<impl Iterator<Item = (BasicCoverageBlock, CoverageKind)>> {
419-
self.edge_from_bcbs.take().map(|m| m.into_iter())
420-
}
421-
422332
pub fn id(&self) -> String {
423333
format!("@{}", self.basic_blocks.iter().map(|bb| bb.index().to_string()).join(ID_SEPARATOR))
424334
}
@@ -448,17 +358,6 @@ impl BcbBranch {
448358
Self { edge_from_bcb, target_bcb: to_bcb }
449359
}
450360

451-
pub fn counter<'a>(
452-
&self,
453-
basic_coverage_blocks: &'a CoverageGraph,
454-
) -> Option<&'a CoverageKind> {
455-
if let Some(from_bcb) = self.edge_from_bcb {
456-
basic_coverage_blocks[self.target_bcb].edge_counter_from(from_bcb)
457-
} else {
458-
basic_coverage_blocks[self.target_bcb].counter()
459-
}
460-
}
461-
462361
pub fn is_only_path_to_target(&self) -> bool {
463362
self.edge_from_bcb.is_none()
464363
}

0 commit comments

Comments
 (0)