Unbox and unwrap the contents of StatementKind::Coverage
The payload of coverage statements was historically a structure with several fields, so it was boxed to avoid bloating `StatementKind`. Now that the payload is a single relatively-small enum, we can replace `Box<Coverage>` with just `CoverageKind`. This patch also adds a size assertion for `StatementKind`, to avoid accidentally bloating it in the future.
This commit is contained in:
parent
c3b05c6e5b
commit
ab92699f4a
15 changed files with 44 additions and 68 deletions
|
@ -15,7 +15,7 @@ use crate::MirPass;
|
|||
|
||||
use rustc_middle::mir::coverage::*;
|
||||
use rustc_middle::mir::{
|
||||
self, BasicBlock, BasicBlockData, Coverage, SourceInfo, Statement, StatementKind, Terminator,
|
||||
self, BasicBlock, BasicBlockData, SourceInfo, Statement, StatementKind, Terminator,
|
||||
TerminatorKind,
|
||||
};
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
|
@ -230,10 +230,7 @@ fn inject_statement(mir_body: &mut mir::Body<'_>, counter_kind: CoverageKind, bb
|
|||
debug!(" injecting statement {counter_kind:?} for {bb:?}");
|
||||
let data = &mut mir_body[bb];
|
||||
let source_info = data.terminator().source_info;
|
||||
let statement = Statement {
|
||||
source_info,
|
||||
kind: StatementKind::Coverage(Box::new(Coverage { kind: counter_kind })),
|
||||
};
|
||||
let statement = Statement { source_info, kind: StatementKind::Coverage(counter_kind) };
|
||||
data.statements.insert(0, statement);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::mir::coverage::{CounterId, CoverageKind};
|
||||
use rustc_middle::mir::{Body, Coverage, CoverageIdsInfo, Statement, StatementKind};
|
||||
use rustc_middle::mir::{Body, CoverageIdsInfo, Statement, StatementKind};
|
||||
use rustc_middle::query::TyCtxtAt;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_middle::util::Providers;
|
||||
|
@ -54,7 +54,7 @@ fn coverage_ids_info<'tcx>(
|
|||
let mir_body = tcx.instance_mir(instance_def);
|
||||
|
||||
let max_counter_id = all_coverage_in_mir_body(mir_body)
|
||||
.filter_map(|coverage| match coverage.kind {
|
||||
.filter_map(|kind| match *kind {
|
||||
CoverageKind::CounterIncrement { id } => Some(id),
|
||||
_ => None,
|
||||
})
|
||||
|
@ -66,12 +66,10 @@ fn coverage_ids_info<'tcx>(
|
|||
|
||||
fn all_coverage_in_mir_body<'a, 'tcx>(
|
||||
body: &'a Body<'tcx>,
|
||||
) -> impl Iterator<Item = &'a Coverage> + Captures<'tcx> {
|
||||
) -> impl Iterator<Item = &'a CoverageKind> + Captures<'tcx> {
|
||||
body.basic_blocks.iter().flat_map(|bb_data| &bb_data.statements).filter_map(|statement| {
|
||||
match statement.kind {
|
||||
StatementKind::Coverage(box ref coverage) if !is_inlined(body, statement) => {
|
||||
Some(coverage)
|
||||
}
|
||||
StatementKind::Coverage(ref kind) if !is_inlined(body, statement) => Some(kind),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
|
|
|
@ -187,9 +187,7 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
|
|||
// for their parent `BasicBlock`.
|
||||
StatementKind::StorageLive(_)
|
||||
| StatementKind::StorageDead(_)
|
||||
// Ignore `ConstEvalCounter`s
|
||||
| StatementKind::ConstEvalCounter
|
||||
// Ignore `Nop`s
|
||||
| StatementKind::Nop => None,
|
||||
|
||||
// FIXME(#78546): MIR InstrumentCoverage - Can the source_info.span for `FakeRead`
|
||||
|
@ -211,30 +209,28 @@ fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span> {
|
|||
StatementKind::FakeRead(box (FakeReadCause::ForGuardBinding, _)) => None,
|
||||
|
||||
// Retain spans from most other statements.
|
||||
StatementKind::FakeRead(box (_, _)) // Not including `ForGuardBinding`
|
||||
StatementKind::FakeRead(_)
|
||||
| StatementKind::Intrinsic(..)
|
||||
| StatementKind::Coverage(box mir::Coverage {
|
||||
| StatementKind::Coverage(
|
||||
// The purpose of `SpanMarker` is to be matched and accepted here.
|
||||
kind: CoverageKind::SpanMarker
|
||||
})
|
||||
CoverageKind::SpanMarker,
|
||||
)
|
||||
| StatementKind::Assign(_)
|
||||
| StatementKind::SetDiscriminant { .. }
|
||||
| StatementKind::Deinit(..)
|
||||
| StatementKind::Retag(_, _)
|
||||
| StatementKind::PlaceMention(..)
|
||||
| StatementKind::AscribeUserType(_, _) => {
|
||||
Some(statement.source_info.span)
|
||||
}
|
||||
| StatementKind::AscribeUserType(_, _) => Some(statement.source_info.span),
|
||||
|
||||
StatementKind::Coverage(box mir::Coverage {
|
||||
// Block markers are used for branch coverage, so ignore them here.
|
||||
kind: CoverageKind::BlockMarker {..}
|
||||
}) => None,
|
||||
// Block markers are used for branch coverage, so ignore them here.
|
||||
StatementKind::Coverage(CoverageKind::BlockMarker { .. }) => None,
|
||||
|
||||
StatementKind::Coverage(box mir::Coverage {
|
||||
// These coverage statements should not exist prior to coverage instrumentation.
|
||||
kind: CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. }
|
||||
}) => bug!("Unexpected coverage statement found during coverage instrumentation: {statement:?}"),
|
||||
// These coverage statements should not exist prior to coverage instrumentation.
|
||||
StatementKind::Coverage(
|
||||
CoverageKind::CounterIncrement { .. } | CoverageKind::ExpressionUsed { .. },
|
||||
) => bug!(
|
||||
"Unexpected coverage statement found during coverage instrumentation: {statement:?}"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,9 +378,7 @@ pub(super) fn extract_branch_mappings(
|
|||
// Fill out the mapping from block marker IDs to their enclosing blocks.
|
||||
for (bb, data) in mir_body.basic_blocks.iter_enumerated() {
|
||||
for statement in &data.statements {
|
||||
if let StatementKind::Coverage(coverage) = &statement.kind
|
||||
&& let CoverageKind::BlockMarker { id } = coverage.kind
|
||||
{
|
||||
if let StatementKind::Coverage(CoverageKind::BlockMarker { id }) = statement.kind {
|
||||
block_markers[id] = Some(bb);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue