Skip to content

Commit e64bf57

Browse files
committed
coverage: Pull function source hash out of map_data.rs
1 parent c337f2a commit e64bf57

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
use rustc_middle::mir::coverage::{CoverageIdsInfo, FunctionCoverageInfo};
22

33
pub(crate) struct FunctionCoverage<'tcx> {
4-
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
54
/// If `None`, the corresponding function is unused.
65
ids_info: Option<&'tcx CoverageIdsInfo>,
76
}
87

98
impl<'tcx> FunctionCoverage<'tcx> {
109
pub(crate) fn new_used(
11-
function_coverage_info: &'tcx FunctionCoverageInfo,
10+
_function_coverage_info: &'tcx FunctionCoverageInfo,
1211
ids_info: &'tcx CoverageIdsInfo,
1312
) -> Self {
14-
Self { function_coverage_info, ids_info: Some(ids_info) }
13+
Self { ids_info: Some(ids_info) }
1514
}
1615

17-
pub(crate) fn new_unused(function_coverage_info: &'tcx FunctionCoverageInfo) -> Self {
18-
Self { function_coverage_info, ids_info: None }
16+
pub(crate) fn new_unused(_function_coverage_info: &'tcx FunctionCoverageInfo) -> Self {
17+
Self { ids_info: None }
1918
}
2019

2120
/// Returns true for a used (called) function, and false for an unused function.
2221
pub(crate) fn is_used(&self) -> bool {
2322
self.ids_info.is_some()
2423
}
25-
26-
/// Return the source hash, generated from the HIR node structure, and used to indicate whether
27-
/// or not the source code structure changed between different compilations.
28-
pub(crate) fn source_hash(&self) -> u64 {
29-
if self.is_used() { self.function_coverage_info.function_source_hash } else { 0 }
30-
}
3124
}

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
7171
let covfun_records = function_coverage_map
7272
.into_iter()
7373
.filter_map(|(instance, function_coverage)| {
74-
prepare_covfun_record(tcx, &mut global_file_table, instance, &function_coverage)
74+
let is_used = function_coverage.is_used();
75+
prepare_covfun_record(tcx, &mut global_file_table, instance, is_used)
7576
})
7677
.collect::<Vec<_>>();
7778

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use rustc_target::spec::HasTargetSpec;
1919
use tracing::debug;
2020

2121
use crate::common::CodegenCx;
22-
use crate::coverageinfo::map_data::FunctionCoverage;
2322
use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, span_file_name};
2423
use crate::coverageinfo::{ffi, llvm_cov};
2524
use crate::llvm;
@@ -49,17 +48,17 @@ pub(crate) fn prepare_covfun_record<'tcx>(
4948
tcx: TyCtxt<'tcx>,
5049
global_file_table: &mut GlobalFileTable,
5150
instance: Instance<'tcx>,
52-
function_coverage: &FunctionCoverage<'tcx>,
51+
is_used: bool,
5352
) -> Option<CovfunRecord<'tcx>> {
5453
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
5554
let ids_info = tcx.coverage_ids_info(instance.def);
5655

57-
let expressions = prepare_expressions(fn_cov_info, ids_info, function_coverage.is_used());
56+
let expressions = prepare_expressions(fn_cov_info, ids_info, is_used);
5857

5958
let mut covfun = CovfunRecord {
6059
mangled_function_name: tcx.symbol_name(instance).name,
61-
source_hash: function_coverage.source_hash(),
62-
is_used: function_coverage.is_used(),
60+
source_hash: if is_used { fn_cov_info.function_source_hash } else { 0 },
61+
is_used,
6362
virtual_file_mapping: VirtualFileMapping::default(),
6463
expressions,
6564
regions: ffi::Regions::default(),

0 commit comments

Comments
 (0)