1
Fork 0

coverage: Unused functions don't need to store CoverageIdsInfo

This commit is contained in:
Zalathar 2024-12-08 20:49:28 +11:00
parent 4d2bfece41
commit 3a35fb6938
2 changed files with 13 additions and 13 deletions

View file

@ -8,8 +8,8 @@ use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
pub(crate) struct FunctionCoverage<'tcx> { pub(crate) struct FunctionCoverage<'tcx> {
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo, pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
ids_info: &'tcx CoverageIdsInfo, /// If `None`, the corresponding function is unused.
is_used: bool, ids_info: Option<&'tcx CoverageIdsInfo>,
} }
impl<'tcx> FunctionCoverage<'tcx> { impl<'tcx> FunctionCoverage<'tcx> {
@ -17,25 +17,22 @@ impl<'tcx> FunctionCoverage<'tcx> {
function_coverage_info: &'tcx FunctionCoverageInfo, function_coverage_info: &'tcx FunctionCoverageInfo,
ids_info: &'tcx CoverageIdsInfo, ids_info: &'tcx CoverageIdsInfo,
) -> Self { ) -> Self {
Self { function_coverage_info, ids_info, is_used: true } Self { function_coverage_info, ids_info: Some(ids_info) }
} }
pub(crate) fn new_unused( pub(crate) fn new_unused(function_coverage_info: &'tcx FunctionCoverageInfo) -> Self {
function_coverage_info: &'tcx FunctionCoverageInfo, Self { function_coverage_info, ids_info: None }
ids_info: &'tcx CoverageIdsInfo,
) -> Self {
Self { function_coverage_info, ids_info, is_used: false }
} }
/// Returns true for a used (called) function, and false for an unused function. /// Returns true for a used (called) function, and false for an unused function.
pub(crate) fn is_used(&self) -> bool { pub(crate) fn is_used(&self) -> bool {
self.is_used self.ids_info.is_some()
} }
/// Return the source hash, generated from the HIR node structure, and used to indicate whether /// Return the source hash, generated from the HIR node structure, and used to indicate whether
/// or not the source code structure changed between different compilations. /// or not the source code structure changed between different compilations.
pub(crate) fn source_hash(&self) -> u64 { pub(crate) fn source_hash(&self) -> u64 {
if self.is_used { self.function_coverage_info.function_source_hash } else { 0 } if self.is_used() { self.function_coverage_info.function_source_hash } else { 0 }
} }
/// Convert this function's coverage expression data into a form that can be /// Convert this function's coverage expression data into a form that can be
@ -78,6 +75,10 @@ impl<'tcx> FunctionCoverage<'tcx> {
} }
fn is_zero_term(&self, term: CovTerm) -> bool { fn is_zero_term(&self, term: CovTerm) -> bool {
!self.is_used || self.ids_info.is_zero_term(term) match self.ids_info {
Some(ids_info) => ids_info.is_zero_term(term),
// This function is unused, so all coverage counters/expressions are zero.
None => true,
}
} }
} }

View file

@ -531,7 +531,6 @@ fn add_unused_function_coverage<'tcx>(
); );
// An unused function's mappings will all be rewritten to map to zero. // An unused function's mappings will all be rewritten to map to zero.
let function_coverage = let function_coverage = FunctionCoverage::new_unused(function_coverage_info);
FunctionCoverage::new_unused(function_coverage_info, tcx.coverage_ids_info(instance.def));
cx.coverage_cx().function_coverage_map.borrow_mut().insert(instance, function_coverage); cx.coverage_cx().function_coverage_map.borrow_mut().insert(instance, function_coverage);
} }