Skip to content

Commit 84e54cd

Browse files
committed
Replace RemapFileNameExt::for_codegen with explicit calls
1 parent ce62d57 commit 84e54cd

File tree

8 files changed

+56
-40
lines changed

8 files changed

+56
-40
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ impl DebugContext {
6262

6363
let mut dwarf = DwarfUnit::new(encoding);
6464

65-
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
65+
use rustc_session::config::RemapPathScopeComponents;
66+
let should_remap_filepaths =
67+
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
6668

6769
let producer = producer(tcx.sess);
6870
let comp_dir = tcx

compiler/rustc_codegen_llvm/src/back/write.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ use rustc_data_structures::small_c_str::SmallCStr;
2929
use rustc_errors::{DiagCtxt, FatalError, Level};
3030
use rustc_fs_util::{link_or_copy, path_to_c_string};
3131
use rustc_middle::ty::TyCtxt;
32-
use rustc_session::config::{self, Lto, OutputType, Passes, SplitDwarfKind, SwitchWithOptPath};
32+
use rustc_session::config::{self, Lto, OutputType, Passes};
33+
use rustc_session::config::{RemapPathScopeComponents, SplitDwarfKind, SwitchWithOptPath};
3334
use rustc_session::Session;
3435
use rustc_span::symbol::sym;
3536
use rustc_span::InnerSpan;
@@ -257,7 +258,8 @@ pub fn target_machine_factory(
257258
};
258259
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);
259260

260-
let should_prefer_remapped_paths = sess.should_prefer_remapped_for_codegen();
261+
let should_prefer_remapped_paths =
262+
sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
261263

262264
Arc::new(move |config: TargetMachineFactoryConfig| {
263265
let path_to_cstring_helper = |path: Option<PathBuf>| -> CString {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,14 @@ impl GlobalFileTable {
174174
// Since rustc generates coverage maps with relative paths, the
175175
// compilation directory can be combined with the relative paths
176176
// to get absolute paths, if needed.
177+
use rustc_session::config::RemapPathScopeComponents;
177178
use rustc_session::RemapFileNameExt;
178-
let working_dir: &str = &tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
179+
let working_dir: &str = &tcx
180+
.sess
181+
.opts
182+
.working_dir
183+
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
184+
.to_string_lossy();
179185

180186
llvm::build_byte_buffer(|buffer| {
181187
coverageinfo::write_filenames_section_to_buffer(

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,13 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
554554
) -> &'ll DIFile {
555555
debug!(?source_file.name);
556556

557-
use rustc_session::RemapFileNameExt;
557+
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
558558
let (directory, file_name) = match &source_file.name {
559559
FileName::Real(filename) => {
560560
let working_directory = &cx.sess().opts.working_dir;
561561
debug!(?working_directory);
562562

563-
if cx.sess().should_prefer_remapped_for_codegen() {
563+
if cx.sess().should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
564564
let filename = cx
565565
.sess()
566566
.source_map()
@@ -623,7 +623,13 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
623623
}
624624
other => {
625625
debug!(?other);
626-
("".into(), other.for_codegen(cx.sess()).to_string_lossy().into_owned())
626+
(
627+
"".into(),
628+
other
629+
.for_scope(cx.sess(), RemapPathScopeComponents::DEBUGINFO)
630+
.to_string_lossy()
631+
.into_owned(),
632+
)
627633
}
628634
};
629635

@@ -862,9 +868,14 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
862868
// FIXME(#41252) Remove "clang LLVM" if we can get GDB and LLVM to play nice.
863869
let producer = format!("clang LLVM ({rustc_producer})");
864870

865-
use rustc_session::RemapFileNameExt;
871+
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
866872
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
867-
let work_dir = tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
873+
let work_dir = tcx
874+
.sess
875+
.opts
876+
.working_dir
877+
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
878+
.to_string_lossy();
868879
let output_filenames = tcx.output_filenames(());
869880
let split_name = if tcx.sess.target_can_use_split_dwarf() {
870881
output_filenames
@@ -875,7 +886,7 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
875886
)
876887
// We get a path relative to the working directory from split_dwarf_path
877888
.map(|f| {
878-
if tcx.sess.should_prefer_remapped_for_codegen() {
889+
if tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
879890
tcx.sess.source_map().path_mapping().map_prefix(f).0
880891
} else {
881892
f.into()

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_middle::ty::fast_reject::{self, TreatParams};
2121
use rustc_middle::ty::{AssocItemContainer, SymbolName};
2222
use rustc_middle::util::common::to_readable_str;
2323
use rustc_serialize::{opaque, Decodable, Decoder, Encodable, Encoder};
24-
use rustc_session::config::{CrateType, OptLevel};
24+
use rustc_session::config::{CrateType, OptLevel, RemapPathScopeComponents};
2525
use rustc_span::hygiene::HygieneEncodeContext;
2626
use rustc_span::symbol::sym;
2727
use rustc_span::{
@@ -549,7 +549,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
549549

550550
match source_file.name {
551551
FileName::Real(ref original_file_name) => {
552-
let adapted_file_name = if self.tcx.sess.should_prefer_remapped_for_codegen() {
552+
let adapted_file_name = if self
553+
.tcx
554+
.sess
555+
.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO)
556+
{
553557
source_map.path_mapping().to_embeddable_absolute_path(
554558
original_file_name.clone(),
555559
working_directory,

compiler/rustc_middle/src/mir/consts.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{self, Debug, Display, Formatter};
22

33
use rustc_hir::def_id::DefId;
4-
use rustc_session::RemapFileNameExt;
4+
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
55
use rustc_span::Span;
66
use rustc_target::abi::{HasDataLayout, Size};
77

@@ -516,7 +516,11 @@ impl<'tcx> TyCtxt<'tcx> {
516516
let caller = self.sess.source_map().lookup_char_pos(topmost.lo());
517517
self.const_caller_location(
518518
rustc_span::symbol::Symbol::intern(
519-
&caller.file.name.for_codegen(self.sess).to_string_lossy(),
519+
&caller
520+
.file
521+
.name
522+
.for_scope(self.sess, RemapPathScopeComponents::DEBUGINFO)
523+
.to_string_lossy(),
520524
),
521525
caller.line as u32,
522526
caller.col_display as u32 + 1,

compiler/rustc_mir_transform/src/coverage/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ fn create_mappings<'tcx>(
125125
let body_span = hir_info.body_span;
126126

127127
let source_file = source_map.lookup_source_file(body_span.lo());
128-
use rustc_session::RemapFileNameExt;
129-
let file_name = Symbol::intern(&source_file.name.for_codegen(tcx.sess).to_string_lossy());
128+
129+
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
130+
let file_name = Symbol::intern(
131+
&source_file
132+
.name
133+
.for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO)
134+
.to_string_lossy(),
135+
);
130136

131137
let term_for_bcb = |bcb| {
132138
coverage_counters

compiler/rustc_session/src/session.rs

+5-24
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ impl Session {
252252

253253
pub fn local_crate_source_file(&self) -> Option<PathBuf> {
254254
let path = self.io.input.opt_path()?;
255-
if self.should_prefer_remapped_for_codegen() {
255+
// FIXME: The remap path scope should probably not be hardcoded.
256+
if self.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO) {
256257
Some(self.opts.file_path_mapping().map_prefix(path).0.into_owned())
257258
} else {
258259
Some(path.to_path_buf())
@@ -886,8 +887,8 @@ impl Session {
886887
self.opts.cg.link_dead_code.unwrap_or(false)
887888
}
888889

889-
pub fn should_prefer_remapped_for_codegen(&self) -> bool {
890-
self.opts.unstable_opts.remap_path_scope.contains(RemapPathScopeComponents::DEBUGINFO)
890+
pub fn should_prefer_remapped(&self, scope: RemapPathScopeComponents) -> bool {
891+
self.opts.unstable_opts.remap_path_scope.contains(scope)
891892
}
892893
}
893894

@@ -1440,12 +1441,8 @@ pub trait RemapFileNameExt {
14401441

14411442
/// Returns a possibly remapped filename based on the passed scope and remap cli options.
14421443
///
1443-
/// One and only one scope should be passed to this method. For anything related to
1444-
/// "codegen" see the [`RemapFileNameExt::for_codegen`] method.
1444+
/// One and only one scope should be passed to this method, it will panic otherwise.
14451445
fn for_scope(&self, sess: &Session, scope: RemapPathScopeComponents) -> Self::Output<'_>;
1446-
1447-
/// Return a possibly remapped filename, to be used in "codegen" related parts.
1448-
fn for_codegen(&self, sess: &Session) -> Self::Output<'_>;
14491446
}
14501447

14511448
impl RemapFileNameExt for rustc_span::FileName {
@@ -1462,14 +1459,6 @@ impl RemapFileNameExt for rustc_span::FileName {
14621459
self.prefer_local()
14631460
}
14641461
}
1465-
1466-
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
1467-
if sess.should_prefer_remapped_for_codegen() {
1468-
self.prefer_remapped_unconditionaly()
1469-
} else {
1470-
self.prefer_local()
1471-
}
1472-
}
14731462
}
14741463

14751464
impl RemapFileNameExt for rustc_span::RealFileName {
@@ -1486,12 +1475,4 @@ impl RemapFileNameExt for rustc_span::RealFileName {
14861475
self.local_path_if_available()
14871476
}
14881477
}
1489-
1490-
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
1491-
if sess.should_prefer_remapped_for_codegen() {
1492-
self.remapped_path_if_available()
1493-
} else {
1494-
self.local_path_if_available()
1495-
}
1496-
}
14971478
}

0 commit comments

Comments
 (0)