Rollup merge of #135873 - Zalathar:be-prepared, r=oli-obk
coverage: Prepare for upcoming changes to counter creation This is a collection of smaller changes to coverage instrumentation code that have been extracted from a larger PR that I'm still working on, in order to hopefully make review easier. Each individual change should hopefully be mostly self-explanatory. One of the big goals of the upcoming PR will be to defer certain parts of counter-creation until codegen, via the query system, so that ends up being a recurring theme in these changes. Several of the changes are follow-ups to #135481. There should be no observable change in compiler output.
This commit is contained in:
commit
135cd69b57
15 changed files with 180 additions and 198 deletions
|
@ -4,7 +4,7 @@ use std::fmt::{self, Debug, Formatter};
|
|||
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_index::bit_set::DenseBitSet;
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
|
||||
use rustc_macros::{HashStable, TyDecodable, TyEncodable};
|
||||
use rustc_span::Span;
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
|
@ -72,7 +72,7 @@ impl ConditionId {
|
|||
/// Enum that can hold a constant zero value, the ID of an physical coverage
|
||||
/// counter, or the ID of a coverage-counter expression.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub enum CovTerm {
|
||||
Zero,
|
||||
Counter(CounterId),
|
||||
|
@ -89,7 +89,7 @@ impl Debug for CovTerm {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(Clone, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub enum CoverageKind {
|
||||
/// Marks a span that might otherwise not be represented in MIR, so that
|
||||
/// coverage instrumentation can associate it with its enclosing block/BCB.
|
||||
|
@ -151,7 +151,7 @@ impl Debug for CoverageKind {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, HashStable)]
|
||||
#[derive(TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable)]
|
||||
pub enum Op {
|
||||
Subtract,
|
||||
Add,
|
||||
|
@ -168,7 +168,7 @@ impl Op {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct Expression {
|
||||
pub lhs: CovTerm,
|
||||
pub op: Op,
|
||||
|
@ -176,7 +176,7 @@ pub struct Expression {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub enum MappingKind {
|
||||
/// Associates a normal region of code with a counter/expression/zero.
|
||||
Code(CovTerm),
|
||||
|
@ -208,7 +208,7 @@ impl MappingKind {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct Mapping {
|
||||
pub kind: MappingKind,
|
||||
pub span: Span,
|
||||
|
@ -218,7 +218,7 @@ pub struct Mapping {
|
|||
/// to be used in conjunction with the individual coverage statements injected
|
||||
/// into the function's basic blocks.
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct FunctionCoverageInfo {
|
||||
pub function_source_hash: u64,
|
||||
pub body_span: Span,
|
||||
|
@ -238,7 +238,7 @@ pub struct FunctionCoverageInfo {
|
|||
/// ("Hi" indicates that this is "high-level" information collected at the
|
||||
/// THIR/MIR boundary, before the MIR-based coverage instrumentation pass.)
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct CoverageInfoHi {
|
||||
/// 1 more than the highest-numbered [`CoverageKind::BlockMarker`] that was
|
||||
/// injected into the MIR body. This makes it possible to allocate per-ID
|
||||
|
@ -252,7 +252,7 @@ pub struct CoverageInfoHi {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct BranchSpan {
|
||||
pub span: Span,
|
||||
pub true_marker: BlockMarkerId,
|
||||
|
@ -260,7 +260,7 @@ pub struct BranchSpan {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct ConditionInfo {
|
||||
pub condition_id: ConditionId,
|
||||
pub true_next_id: Option<ConditionId>,
|
||||
|
@ -268,7 +268,7 @@ pub struct ConditionInfo {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct MCDCBranchSpan {
|
||||
pub span: Span,
|
||||
pub condition_info: ConditionInfo,
|
||||
|
@ -277,14 +277,14 @@ pub struct MCDCBranchSpan {
|
|||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct DecisionInfo {
|
||||
pub bitmap_idx: u32,
|
||||
pub num_conditions: u16,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable, TypeFoldable, TypeVisitable)]
|
||||
#[derive(TyEncodable, TyDecodable, Hash, HashStable)]
|
||||
pub struct MCDCDecisionSpan {
|
||||
pub span: Span,
|
||||
pub end_markers: Vec<BlockMarkerId>,
|
||||
|
|
|
@ -358,6 +358,8 @@ pub struct Body<'tcx> {
|
|||
///
|
||||
/// 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_info_hi: Option<Box<coverage::CoverageInfoHi>>,
|
||||
|
||||
/// Per-function coverage information added by the `InstrumentCoverage`
|
||||
|
@ -366,6 +368,8 @@ pub struct Body<'tcx> {
|
|||
///
|
||||
/// If `-Cinstrument-coverage` is not active, or if an individual function
|
||||
/// is not eligible for coverage, then this should always be `None`.
|
||||
#[type_foldable(identity)]
|
||||
#[type_visitable(ignore)]
|
||||
pub function_coverage_info: Option<Box<coverage::FunctionCoverageInfo>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -417,7 +417,14 @@ pub enum StatementKind<'tcx> {
|
|||
///
|
||||
/// Interpreters and codegen backends that don't support coverage instrumentation
|
||||
/// can usually treat this as a no-op.
|
||||
Coverage(CoverageKind),
|
||||
Coverage(
|
||||
// Coverage statements are unlikely to ever contain type information in
|
||||
// the foreseeable future, so excluding them from TypeFoldable/TypeVisitable
|
||||
// avoids some unhelpful derive boilerplate.
|
||||
#[type_foldable(identity)]
|
||||
#[type_visitable(ignore)]
|
||||
CoverageKind,
|
||||
),
|
||||
|
||||
/// Denotes a call to an intrinsic that does not require an unwind path and always returns.
|
||||
/// This avoids adding a new block and a terminator for simple intrinsics.
|
||||
|
|
|
@ -618,7 +618,9 @@ rustc_queries! {
|
|||
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
|
||||
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
|
||||
/// have had a chance to potentially remove some of them.
|
||||
query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> &'tcx mir::coverage::CoverageIdsInfo {
|
||||
///
|
||||
/// Returns `None` for functions that were not instrumented.
|
||||
query coverage_ids_info(key: ty::InstanceKind<'tcx>) -> Option<&'tcx mir::coverage::CoverageIdsInfo> {
|
||||
desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
|
||||
arena_cache
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue