coverage: Make query coverage_ids_info
return an Option
This reflects the fact that we can't compute meaningful info for a function that wasn't instrumented and therefore doesn't have `function_coverage_info`.
This commit is contained in:
parent
ec6fc95d6d
commit
ff48331588
4 changed files with 12 additions and 14 deletions
|
@ -51,7 +51,7 @@ pub(crate) fn prepare_covfun_record<'tcx>(
|
||||||
is_used: bool,
|
is_used: bool,
|
||||||
) -> Option<CovfunRecord<'tcx>> {
|
) -> Option<CovfunRecord<'tcx>> {
|
||||||
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
|
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
|
||||||
let ids_info = tcx.coverage_ids_info(instance.def);
|
let ids_info = tcx.coverage_ids_info(instance.def)?;
|
||||||
|
|
||||||
let expressions = prepare_expressions(fn_cov_info, ids_info, is_used);
|
let expressions = prepare_expressions(fn_cov_info, ids_info, is_used);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ use rustc_codegen_ssa::traits::{
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
|
||||||
use rustc_middle::mir::coverage::CoverageKind;
|
use rustc_middle::mir::coverage::CoverageKind;
|
||||||
use rustc_middle::ty::Instance;
|
use rustc_middle::ty::Instance;
|
||||||
use rustc_middle::ty::layout::HasTyCtxt;
|
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
use crate::builder::Builder;
|
use crate::builder::Builder;
|
||||||
|
@ -147,6 +146,10 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
debug!("function has a coverage statement but no coverage info");
|
debug!("function has a coverage statement but no coverage info");
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
let Some(ids_info) = bx.tcx.coverage_ids_info(instance.def) else {
|
||||||
|
debug!("function has a coverage statement but no IDs info");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
// Mark the instance as used in this CGU, for coverage purposes.
|
// Mark the instance as used in this CGU, for coverage purposes.
|
||||||
// This includes functions that were not partitioned into this CGU,
|
// This includes functions that were not partitioned into this CGU,
|
||||||
|
@ -162,8 +165,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
|
||||||
// be smaller than the number originally inserted by the instrumentor,
|
// be smaller than the number originally inserted by the instrumentor,
|
||||||
// if some high-numbered counters were removed by MIR optimizations.
|
// if some high-numbered counters were removed by MIR optimizations.
|
||||||
// If so, LLVM's profiler runtime will use fewer physical counters.
|
// If so, LLVM's profiler runtime will use fewer physical counters.
|
||||||
let num_counters =
|
let num_counters = ids_info.num_counters_after_mir_opts();
|
||||||
bx.tcx().coverage_ids_info(instance.def).num_counters_after_mir_opts();
|
|
||||||
assert!(
|
assert!(
|
||||||
num_counters as usize <= function_coverage_info.num_counters,
|
num_counters as usize <= function_coverage_info.num_counters,
|
||||||
"num_counters disagreement: query says {num_counters} but function info only has {}",
|
"num_counters disagreement: query says {num_counters} but function info only has {}",
|
||||||
|
|
|
@ -618,7 +618,9 @@ rustc_queries! {
|
||||||
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
|
/// Summarizes coverage IDs inserted by the `InstrumentCoverage` MIR pass
|
||||||
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
|
/// (for compiler option `-Cinstrument-coverage`), after MIR optimizations
|
||||||
/// have had a chance to potentially remove some of them.
|
/// 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()) }
|
desc { |tcx| "retrieving coverage IDs info from MIR for `{}`", tcx.def_path_str(key.def_id()) }
|
||||||
arena_cache
|
arena_cache
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,15 +87,9 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
|
||||||
fn coverage_ids_info<'tcx>(
|
fn coverage_ids_info<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
instance_def: ty::InstanceKind<'tcx>,
|
instance_def: ty::InstanceKind<'tcx>,
|
||||||
) -> CoverageIdsInfo {
|
) -> Option<CoverageIdsInfo> {
|
||||||
let mir_body = tcx.instance_mir(instance_def);
|
let mir_body = tcx.instance_mir(instance_def);
|
||||||
|
let fn_cov_info = mir_body.function_coverage_info.as_deref()?;
|
||||||
let Some(fn_cov_info) = mir_body.function_coverage_info.as_deref() else {
|
|
||||||
return CoverageIdsInfo {
|
|
||||||
counters_seen: DenseBitSet::new_empty(0),
|
|
||||||
zero_expressions: DenseBitSet::new_empty(0),
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut counters_seen = DenseBitSet::new_empty(fn_cov_info.num_counters);
|
let mut counters_seen = DenseBitSet::new_empty(fn_cov_info.num_counters);
|
||||||
let mut expressions_seen = DenseBitSet::new_filled(fn_cov_info.expressions.len());
|
let mut expressions_seen = DenseBitSet::new_filled(fn_cov_info.expressions.len());
|
||||||
|
@ -129,7 +123,7 @@ fn coverage_ids_info<'tcx>(
|
||||||
let zero_expressions =
|
let zero_expressions =
|
||||||
identify_zero_expressions(fn_cov_info, &counters_seen, &expressions_seen);
|
identify_zero_expressions(fn_cov_info, &counters_seen, &expressions_seen);
|
||||||
|
|
||||||
CoverageIdsInfo { counters_seen, zero_expressions }
|
Some(CoverageIdsInfo { counters_seen, zero_expressions })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_coverage_in_mir_body<'a, 'tcx>(
|
fn all_coverage_in_mir_body<'a, 'tcx>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue