Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
};

match *kind {
CoverageKind::Point { .. } | CoverageKind::BlockMarker { .. } => unreachable!(
CoverageKind::Point { .. } => unreachable!(
"marker statement {kind:?} should have been removed by CleanupPostBorrowck"
),
CoverageKind::VirtualCounter { bcb }
Expand Down
54 changes: 11 additions & 43 deletions compiler/rustc_middle/src/mir/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ use rustc_index::{Idx, IndexVec};
use rustc_macros::{StableHash, TyDecodable, TyEncodable};
use rustc_span::Span;

rustc_index::newtype_index! {
/// Used by [`CoverageKind::BlockMarker`] to mark blocks during THIR-to-MIR
/// lowering, so that those blocks can be identified later.
#[stable_hash]
#[encodable]
#[debug_format = "BlockMarkerId({})"]
pub struct BlockMarkerId {}
}

rustc_index::newtype_index! {
/// ID of a coverage counter. Values ascend from 0.
///
Expand Down Expand Up @@ -76,11 +67,21 @@ impl Debug for CovTerm {
pub enum PointKind {
/// Inserted just before evaluating an expression.
Expr,

/// Inserted when a one-sided `if` expression generates its synthetic `else {}`.
/// The absent `else` has no node, so [`HirId`] is the `if` expression.
ImplicitElse,

/// Inserted at the end of a function's body. [`HirId`] is the function itself.
FunctionEnd,

/// Inserted into the true-outcome and false-outcome blocks after branching on
/// a boolean condition or a fallible `let`.
///
/// [`HirId`] is one of:
/// - The boolean expression being tested
/// - The initializer expression (RHS) of a fallible `let`
BranchOutcome { outcome: bool },
}

#[derive(Clone, PartialEq, TyEncodable, TyDecodable, StableHash)]
Expand All @@ -90,12 +91,6 @@ pub enum CoverageKind {
/// indicated by [`PointKind`]. Injected during MIR building.
Point { point_kind: PointKind, hir_id: HirId },

/// Marks its enclosing basic block with an ID that can be referred to by
/// side data in [`CoverageEarlyInfo`].
///
/// Should be erased before codegen (at some point after `InstrumentCoverage`).
BlockMarker { id: BlockMarkerId },

/// Marks its enclosing basic block with the ID of the coverage graph node
/// that it was part of during the `InstrumentCoverage` MIR pass.
///
Expand All @@ -110,7 +105,6 @@ impl Debug for CoverageKind {
CoverageKind::Point { point_kind, hir_id } => {
write!(fmt, "Point({point_kind:?}, {hir_id:?}")
}
CoverageKind::BlockMarker { id } => write!(fmt, "BlockMarker({:?})", id.index()),
CoverageKind::VirtualCounter { bcb } => write!(fmt, "VirtualCounter({bcb:?})"),
}
}
Expand All @@ -122,7 +116,7 @@ impl CoverageKind {
/// no longer needed after that pass.
pub fn is_removed_after_analysis(&self) -> bool {
match self {
CoverageKind::Point { .. } | CoverageKind::BlockMarker { .. } => true,
CoverageKind::Point { .. } => true,
CoverageKind::VirtualCounter { .. } => false,
}
}
Expand Down Expand Up @@ -184,32 +178,6 @@ pub struct CoverageMirInfo {
pub mappings: Vec<Mapping>,
}

/// Coverage information for a function, collected in advance at the THIR/MIR
/// boundary during MIR building, and attached to the corresponding `mir::Body`.
///
/// This side-data is "early" in that it must be collected prior to the main
/// instrumentation step, in contrast to the main [`CoverageMirInfo`] produced
/// by instrumentation itself.
///
/// Used by the `InstrumentCoverage` MIR pass.
#[derive(Clone, Debug)]
#[derive(TyEncodable, TyDecodable, Hash, StableHash)]
pub struct CoverageEarlyInfo {
/// 1 more than the highest-numbered [`CoverageKind::BlockMarker`] that was
/// injected into the MIR body. This makes it possible to allocate per-ID
/// data structures without having to scan the entire body first.
pub num_block_markers: usize,
pub branch_spans: Vec<BranchSpan>,
}

#[derive(Clone, Debug)]
#[derive(TyEncodable, TyDecodable, Hash, StableHash)]
pub struct BranchSpan {
pub span: Span,
pub true_marker: BlockMarkerId,
pub false_marker: BlockMarkerId,
}

/// Contains information needed during codegen, obtained by inspecting the
/// function's MIR after MIR optimizations.
///
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,6 @@ pub struct Body<'tcx> {

pub tainted_by_errors: Option<ErrorGuaranteed>,

/// Coverage information collected at the THIR/MIR boundary during MIR
/// building, to be used by the `InstrumentCoverage` pass.
///
/// Only present if coverage is enabled and this function is eligible.
/// Boxed to limit space overhead in non-coverage builds.
#[type_foldable(identity)]
#[type_visitable(ignore)]
pub coverage_early_info: Option<Box<coverage::CoverageEarlyInfo>>,

/// Per-function coverage information added by the `InstrumentCoverage`
/// pass, to be used in conjunction with the coverage statements injected
/// into this body's blocks.
Expand Down Expand Up @@ -369,7 +360,6 @@ impl<'tcx> Body<'tcx> {
is_polymorphic: false,
injection_phase: None,
tainted_by_errors,
coverage_early_info: None,
coverage_mir_info: None,
};
body.is_polymorphic = body.has_non_region_param();
Expand Down Expand Up @@ -400,7 +390,6 @@ impl<'tcx> Body<'tcx> {
is_polymorphic: false,
injection_phase: None,
tainted_by_errors: None,
coverage_early_info: None,
coverage_mir_info: None,
};
body.is_polymorphic = body.has_non_region_param();
Expand Down
27 changes: 0 additions & 27 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,40 +630,13 @@ fn write_mir_intro<'tcx>(
// Add an empty line before the first block is printed.
writeln!(w)?;

if let Some(early_info) = &body.coverage_early_info {
write_coverage_early_info(early_info, w)?;
}
if let Some(mir_info) = &body.coverage_mir_info {
write_coverage_mir_info(mir_info, w)?;
}

Ok(())
}

fn write_coverage_early_info(
early_info: &coverage::CoverageEarlyInfo,
w: &mut dyn io::Write,
) -> io::Result<()> {
let coverage::CoverageEarlyInfo { num_block_markers: _, branch_spans } = early_info;

// Only add an extra trailing newline if we printed at least one thing.
let mut did_print = false;

for coverage::BranchSpan { span, true_marker, false_marker } in branch_spans {
writeln!(
w,
"{INDENT}coverage branch {{ true: {true_marker:?}, false: {false_marker:?} }} => {span:?}",
)?;
did_print = true;
}

if did_print {
writeln!(w)?;
}

Ok(())
}

fn write_coverage_mir_info(
mir_info: &coverage::CoverageMirInfo,
w: &mut dyn io::Write,
Expand Down
Loading
Loading