Skip to content

Commit 3a35fb6

Browse files
committed
coverage: Unused functions don't need to store CoverageIdsInfo
1 parent 4d2bfec commit 3a35fb6

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,31 @@ use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
88

99
pub(crate) struct FunctionCoverage<'tcx> {
1010
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
11-
ids_info: &'tcx CoverageIdsInfo,
12-
is_used: bool,
11+
/// If `None`, the corresponding function is unused.
12+
ids_info: Option<&'tcx CoverageIdsInfo>,
1313
}
1414

1515
impl<'tcx> FunctionCoverage<'tcx> {
1616
pub(crate) fn new_used(
1717
function_coverage_info: &'tcx FunctionCoverageInfo,
1818
ids_info: &'tcx CoverageIdsInfo,
1919
) -> Self {
20-
Self { function_coverage_info, ids_info, is_used: true }
20+
Self { function_coverage_info, ids_info: Some(ids_info) }
2121
}
2222

23-
pub(crate) fn new_unused(
24-
function_coverage_info: &'tcx FunctionCoverageInfo,
25-
ids_info: &'tcx CoverageIdsInfo,
26-
) -> Self {
27-
Self { function_coverage_info, ids_info, is_used: false }
23+
pub(crate) fn new_unused(function_coverage_info: &'tcx FunctionCoverageInfo) -> Self {
24+
Self { function_coverage_info, ids_info: None }
2825
}
2926

3027
/// Returns true for a used (called) function, and false for an unused function.
3128
pub(crate) fn is_used(&self) -> bool {
32-
self.is_used
29+
self.ids_info.is_some()
3330
}
3431

3532
/// Return the source hash, generated from the HIR node structure, and used to indicate whether
3633
/// or not the source code structure changed between different compilations.
3734
pub(crate) fn source_hash(&self) -> u64 {
38-
if self.is_used { self.function_coverage_info.function_source_hash } else { 0 }
35+
if self.is_used() { self.function_coverage_info.function_source_hash } else { 0 }
3936
}
4037

4138
/// Convert this function's coverage expression data into a form that can be
@@ -78,6 +75,10 @@ impl<'tcx> FunctionCoverage<'tcx> {
7875
}
7976

8077
fn is_zero_term(&self, term: CovTerm) -> bool {
81-
!self.is_used || self.ids_info.is_zero_term(term)
78+
match self.ids_info {
79+
Some(ids_info) => ids_info.is_zero_term(term),
80+
// This function is unused, so all coverage counters/expressions are zero.
81+
None => true,
82+
}
8283
}
8384
}

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,6 @@ fn add_unused_function_coverage<'tcx>(
531531
);
532532

533533
// An unused function's mappings will all be rewritten to map to zero.
534-
let function_coverage =
535-
FunctionCoverage::new_unused(function_coverage_info, tcx.coverage_ids_info(instance.def));
534+
let function_coverage = FunctionCoverage::new_unused(function_coverage_info);
536535
cx.coverage_cx().function_coverage_map.borrow_mut().insert(instance, function_coverage);
537536
}

0 commit comments

Comments
 (0)