coverage: Pull function source hash out of map_data.rs

This commit is contained in:
Zalathar 2024-12-14 23:14:19 +11:00
parent 527f8127bb
commit d34c365eb0
3 changed files with 7 additions and 12 deletions

View file

@ -1,6 +1,7 @@
use rustc_middle::mir::coverage::{CoverageIdsInfo, FunctionCoverageInfo};
pub(crate) struct FunctionCoverage<'tcx> {
#[expect(unused)] // This whole file gets deleted later in the same PR.
pub(crate) function_coverage_info: &'tcx FunctionCoverageInfo,
/// If `None`, the corresponding function is unused.
ids_info: Option<&'tcx CoverageIdsInfo>,
@ -22,10 +23,4 @@ impl<'tcx> FunctionCoverage<'tcx> {
pub(crate) fn is_used(&self) -> bool {
self.ids_info.is_some()
}
/// 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.
pub(crate) fn source_hash(&self) -> u64 {
if self.is_used() { self.function_coverage_info.function_source_hash } else { 0 }
}
}

View file

@ -81,7 +81,8 @@ pub(crate) fn finalize(cx: &CodegenCx<'_, '_>) {
// instances were visited during codegen.
.sorted_by_cached_key(|&(instance, _)| tcx.symbol_name(instance).name)
.filter_map(|(instance, function_coverage)| {
prepare_covfun_record(tcx, &mut global_file_table, instance, &function_coverage)
let is_used = function_coverage.is_used();
prepare_covfun_record(tcx, &mut global_file_table, instance, is_used)
})
.collect::<Vec<_>>();

View file

@ -19,7 +19,6 @@ use rustc_target::spec::HasTargetSpec;
use tracing::debug;
use crate::common::CodegenCx;
use crate::coverageinfo::map_data::FunctionCoverage;
use crate::coverageinfo::mapgen::{GlobalFileTable, VirtualFileMapping, span_file_name};
use crate::coverageinfo::{ffi, llvm_cov};
use crate::llvm;
@ -49,17 +48,17 @@ pub(crate) fn prepare_covfun_record<'tcx>(
tcx: TyCtxt<'tcx>,
global_file_table: &mut GlobalFileTable,
instance: Instance<'tcx>,
function_coverage: &FunctionCoverage<'tcx>,
is_used: bool,
) -> Option<CovfunRecord<'tcx>> {
let fn_cov_info = tcx.instance_mir(instance.def).function_coverage_info.as_deref()?;
let ids_info = tcx.coverage_ids_info(instance.def);
let expressions = prepare_expressions(fn_cov_info, ids_info, function_coverage.is_used());
let expressions = prepare_expressions(fn_cov_info, ids_info, is_used);
let mut covfun = CovfunRecord {
mangled_function_name: tcx.symbol_name(instance).name,
source_hash: function_coverage.source_hash(),
is_used: function_coverage.is_used(),
source_hash: if is_used { fn_cov_info.function_source_hash } else { 0 },
is_used,
virtual_file_mapping: VirtualFileMapping::default(),
expressions,
regions: ffi::Regions::default(),