Skip to content

Commit

Permalink
coverage: Pull function source hash out of map_data.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zalathar committed Dec 17, 2024
1 parent 527f812 commit d34c365
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs
Original file line number Diff line number Diff line change
@@ -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>,
Expand All @@ -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 }
}
}
3 changes: 2 additions & 1 deletion compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>();

Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit d34c365

Please sign in to comment.