From bf424c28d2fd9aa7480479c48b6414d6b07c8ebc Mon Sep 17 00:00:00 2001 From: Zalathar Date: Thu, 14 Dec 2023 11:55:35 +1100 Subject: [PATCH] coverage: Don't bother storing the source file in `Instrumentor` We can just as easily look it up again from the source map and body span when needed. --- compiler/rustc_mir_transform/src/coverage/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_mir_transform/src/coverage/mod.rs b/compiler/rustc_mir_transform/src/coverage/mod.rs index 75e3f40689c..6c1dc243dea 100644 --- a/compiler/rustc_mir_transform/src/coverage/mod.rs +++ b/compiler/rustc_mir_transform/src/coverage/mod.rs @@ -24,7 +24,7 @@ use rustc_middle::ty::TyCtxt; use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::source_map::SourceMap; -use rustc_span::{ExpnKind, SourceFile, Span, Symbol}; +use rustc_span::{ExpnKind, Span, Symbol}; /// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected /// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen @@ -69,7 +69,6 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, mir_body: &mut mir::Body<'tcx>) { struct Instrumentor<'a, 'tcx> { tcx: TyCtxt<'tcx>, mir_body: &'a mut mir::Body<'tcx>, - source_file: Lrc, fn_sig_span: Span, body_span: Span, function_source_hash: u64, @@ -109,7 +108,6 @@ fn new(tcx: TyCtxt<'tcx>, mir_body: &'a mut mir::Body<'tcx>) -> Self { Self { tcx, mir_body, - source_file, fn_sig_span, body_span, function_source_hash, @@ -160,9 +158,10 @@ fn create_mappings_and_inject_coverage_statements( let source_map = self.tcx.sess.source_map(); let body_span = self.body_span; + let source_file = source_map.lookup_source_file(body_span.lo()); use rustc_session::RemapFileNameExt; let file_name = - Symbol::intern(&self.source_file.name.for_codegen(self.tcx.sess).to_string_lossy()); + Symbol::intern(&source_file.name.for_codegen(self.tcx.sess).to_string_lossy()); let mut mappings = Vec::new();