Skip to content

Commit 4d2bfec

Browse files
committed
coverage: Remove FunctionCoverageCollector
The information that was being collected by this builder type is now collected by the `coverage_ids_info` query instead.
1 parent 2022ef7 commit 4d2bfec

File tree

3 files changed

+17
-70
lines changed

3 files changed

+17
-70
lines changed

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

+7-47
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,30 @@ use rustc_middle::mir::coverage::{
33
CovTerm, CoverageIdsInfo, Expression, FunctionCoverageInfo, Mapping, MappingKind, Op,
44
SourceRegion,
55
};
6-
use rustc_middle::ty::Instance;
7-
use tracing::debug;
86

97
use crate::coverageinfo::ffi::{Counter, CounterExpression, ExprKind};
108

11-
/// Holds all of the coverage mapping data associated with a function instance,
12-
/// collected during traversal of `Coverage` statements in the function's MIR.
13-
#[derive(Debug)]
14-
pub(crate) struct FunctionCoverageCollector<'tcx> {
15-
/// Coverage info that was attached to this function by the instrumentor.
16-
function_coverage_info: &'tcx FunctionCoverageInfo,
9+
pub(crate) struct FunctionCoverage<'tcx> {
10+
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
1711
ids_info: &'tcx CoverageIdsInfo,
1812
is_used: bool,
1913
}
2014

21-
impl<'tcx> FunctionCoverageCollector<'tcx> {
22-
/// Creates a new set of coverage data for a used (called) function.
23-
pub(crate) fn new(
24-
instance: Instance<'tcx>,
25-
function_coverage_info: &'tcx FunctionCoverageInfo,
26-
ids_info: &'tcx CoverageIdsInfo,
27-
) -> Self {
28-
Self::create(instance, function_coverage_info, ids_info, true)
29-
}
30-
31-
/// Creates a new set of coverage data for an unused (never called) function.
32-
pub(crate) fn unused(
33-
instance: Instance<'tcx>,
15+
impl<'tcx> FunctionCoverage<'tcx> {
16+
pub(crate) fn new_used(
3417
function_coverage_info: &'tcx FunctionCoverageInfo,
3518
ids_info: &'tcx CoverageIdsInfo,
3619
) -> Self {
37-
Self::create(instance, function_coverage_info, ids_info, false)
20+
Self { function_coverage_info, ids_info, is_used: true }
3821
}
3922

40-
fn create(
41-
instance: Instance<'tcx>,
23+
pub(crate) fn new_unused(
4224
function_coverage_info: &'tcx FunctionCoverageInfo,
4325
ids_info: &'tcx CoverageIdsInfo,
44-
is_used: bool,
4526
) -> Self {
46-
let num_counters = function_coverage_info.num_counters;
47-
let num_expressions = function_coverage_info.expressions.len();
48-
debug!(
49-
"FunctionCoverage::create(instance={instance:?}) has \
50-
num_counters={num_counters}, num_expressions={num_expressions}, is_used={is_used}"
51-
);
52-
53-
Self { function_coverage_info, ids_info, is_used }
54-
}
55-
56-
pub(crate) fn into_finished(self) -> FunctionCoverage<'tcx> {
57-
let FunctionCoverageCollector { function_coverage_info, ids_info, is_used, .. } = self;
58-
59-
FunctionCoverage { function_coverage_info, ids_info, is_used }
27+
Self { function_coverage_info, ids_info, is_used: false }
6028
}
61-
}
62-
63-
pub(crate) struct FunctionCoverage<'tcx> {
64-
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
65-
ids_info: &'tcx CoverageIdsInfo,
66-
is_used: bool,
67-
}
6829

69-
impl<'tcx> FunctionCoverage<'tcx> {
7030
/// Returns true for a used (called) function, and false for an unused function.
7131
pub(crate) fn is_used(&self) -> bool {
7232
self.is_used

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

+6-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_target::spec::HasTargetSpec;
2020
use tracing::debug;
2121

2222
use crate::common::CodegenCx;
23-
use crate::coverageinfo::map_data::{FunctionCoverage, FunctionCoverageCollector};
23+
use crate::coverageinfo::map_data::FunctionCoverage;
2424
use crate::coverageinfo::{ffi, llvm_cov};
2525
use crate::llvm;
2626

@@ -63,16 +63,11 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
6363
None => return,
6464
};
6565
if function_coverage_map.is_empty() {
66-
// This module has no functions with coverage instrumentation
66+
// This CGU has no functions with coverage instrumentation.
6767
return;
6868
}
6969

70-
let function_coverage_entries = function_coverage_map
71-
.into_iter()
72-
.map(|(instance, function_coverage)| (instance, function_coverage.into_finished()))
73-
.collect::<Vec<_>>();
74-
75-
let all_file_names = function_coverage_entries
70+
let all_file_names = function_coverage_map
7671
.iter()
7772
.map(|(_, fn_cov)| fn_cov.function_coverage_info.body_span)
7873
.map(|span| span_file_name(tcx, span));
@@ -92,7 +87,7 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
9287
let mut unused_function_names = Vec::new();
9388

9489
// Encode coverage mappings and generate function records
95-
for (instance, function_coverage) in function_coverage_entries {
90+
for (instance, function_coverage) in function_coverage_map {
9691
debug!("Generate function coverage for {}, {:?}", cx.codegen_unit.name(), instance);
9792

9893
let mangled_function_name = tcx.symbol_name(instance).name;
@@ -536,11 +531,7 @@ fn add_unused_function_coverage<'tcx>(
536531
);
537532

538533
// An unused function's mappings will all be rewritten to map to zero.
539-
let function_coverage = FunctionCoverageCollector::unused(
540-
instance,
541-
function_coverage_info,
542-
tcx.coverage_ids_info(instance.def),
543-
);
544-
534+
let function_coverage =
535+
FunctionCoverage::new_unused(function_coverage_info, tcx.coverage_ids_info(instance.def));
545536
cx.coverage_cx().function_coverage_map.borrow_mut().insert(instance, function_coverage);
546537
}

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tracing::{debug, instrument};
1313

1414
use crate::builder::Builder;
1515
use crate::common::CodegenCx;
16-
use crate::coverageinfo::map_data::FunctionCoverageCollector;
16+
use crate::coverageinfo::map_data::FunctionCoverage;
1717
use crate::llvm;
1818

1919
pub(crate) mod ffi;
@@ -24,8 +24,7 @@ mod mapgen;
2424
/// Extra per-CGU context/state needed for coverage instrumentation.
2525
pub(crate) struct CguCoverageContext<'ll, 'tcx> {
2626
/// Coverage data for each instrumented function identified by DefId.
27-
pub(crate) function_coverage_map:
28-
RefCell<FxIndexMap<Instance<'tcx>, FunctionCoverageCollector<'tcx>>>,
27+
pub(crate) function_coverage_map: RefCell<FxIndexMap<Instance<'tcx>, FunctionCoverage<'tcx>>>,
2928
pub(crate) pgo_func_name_var_map: RefCell<FxHashMap<Instance<'tcx>, &'ll llvm::Value>>,
3029
pub(crate) mcdc_condition_bitmap_map: RefCell<FxHashMap<Instance<'tcx>, Vec<&'ll llvm::Value>>>,
3130

@@ -42,9 +41,7 @@ impl<'ll, 'tcx> CguCoverageContext<'ll, 'tcx> {
4241
}
4342
}
4443

45-
fn take_function_coverage_map(
46-
&self,
47-
) -> FxIndexMap<Instance<'tcx>, FunctionCoverageCollector<'tcx>> {
44+
fn take_function_coverage_map(&self) -> FxIndexMap<Instance<'tcx>, FunctionCoverage<'tcx>> {
4845
self.function_coverage_map.replace(FxIndexMap::default())
4946
}
5047

@@ -161,8 +158,7 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
161158
// This includes functions that were not partitioned into this CGU,
162159
// but were MIR-inlined into one of this CGU's functions.
163160
coverage_cx.function_coverage_map.borrow_mut().entry(instance).or_insert_with(|| {
164-
FunctionCoverageCollector::new(
165-
instance,
161+
FunctionCoverage::new_used(
166162
function_coverage_info,
167163
bx.tcx.coverage_ids_info(instance.def),
168164
)

0 commit comments

Comments
 (0)