Skip to content

Commit 106146f

Browse files
committed
Replace RemapFileNameExt::for_codegen with explicit calls
1 parent 777c6b4 commit 106146f

File tree

9 files changed

+55
-52
lines changed

9 files changed

+55
-52
lines changed

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

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

8585
let mut dwarf = DwarfUnit::new(encoding);
8686

87-
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
87+
use rustc_session::config::RemapPathScopeComponents;
88+
let should_remap_filepaths =
89+
tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO);
8890

8991
let producer = producer(tcx.sess);
9092
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
@@ -173,8 +173,14 @@ impl GlobalFileTable {
173173
// Since rustc generates coverage maps with relative paths, the
174174
// compilation directory can be combined with the relative paths
175175
// to get absolute paths, if needed.
176+
use rustc_session::config::RemapPathScopeComponents;
176177
use rustc_session::RemapFileNameExt;
177-
let working_dir: &str = &tcx.sess.opts.working_dir.for_codegen(tcx.sess).to_string_lossy();
178+
let working_dir: &str = &tcx
179+
.sess
180+
.opts
181+
.working_dir
182+
.for_scope(tcx.sess, RemapPathScopeComponents::MACRO)
183+
.to_string_lossy();
178184

179185
llvm::build_byte_buffer(|buffer| {
180186
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

+5-11
Original file line numberDiff line numberDiff line change
@@ -549,17 +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() {
553-
source_map.path_mapping().to_embeddable_absolute_path(
554-
original_file_name.clone(),
555-
working_directory,
556-
)
557-
} else {
558-
source_map.path_mapping().to_local_embeddable_absolute_path(
559-
original_file_name.clone(),
560-
working_directory,
561-
)
562-
};
552+
// FIXME: This should probably to conditionally remapped under
553+
// a RemapPathScopeComponents but which one?
554+
let adapted_file_name = source_map
555+
.path_mapping()
556+
.to_embeddable_absolute_path(original_file_name.clone(), working_directory);
563557

564558
adapted_source_file.name = FileName::Real(adapted_file_name);
565559
}

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, DUMMY_SP};
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::MACRO)
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

+5-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@ fn create_mappings<'tcx>(
123123
let body_span = hir_info.body_span;
124124

125125
let source_file = source_map.lookup_source_file(body_span.lo());
126-
use rustc_session::RemapFileNameExt;
127-
let file_name = Symbol::intern(&source_file.name.for_codegen(tcx.sess).to_string_lossy());
126+
127+
use rustc_session::{config::RemapPathScopeComponents, RemapFileNameExt};
128+
let file_name = Symbol::intern(
129+
&source_file.name.for_scope(tcx.sess, RemapPathScopeComponents::MACRO).to_string_lossy(),
130+
);
128131

129132
let term_for_bcb = |bcb| {
130133
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

@@ -1439,12 +1440,8 @@ pub trait RemapFileNameExt {
14391440

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

14501447
impl RemapFileNameExt for rustc_span::FileName {
@@ -1461,14 +1458,6 @@ impl RemapFileNameExt for rustc_span::FileName {
14611458
self.prefer_local()
14621459
}
14631460
}
1464-
1465-
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
1466-
if sess.should_prefer_remapped_for_codegen() {
1467-
self.prefer_remapped_unconditionaly()
1468-
} else {
1469-
self.prefer_local()
1470-
}
1471-
}
14721461
}
14731462

14741463
impl RemapFileNameExt for rustc_span::RealFileName {
@@ -1485,12 +1474,4 @@ impl RemapFileNameExt for rustc_span::RealFileName {
14851474
self.local_path_if_available()
14861475
}
14871476
}
1488-
1489-
fn for_codegen(&self, sess: &Session) -> Self::Output<'_> {
1490-
if sess.should_prefer_remapped_for_codegen() {
1491-
self.remapped_path_if_available()
1492-
} else {
1493-
self.local_path_if_available()
1494-
}
1495-
}
14961477
}

tests/run-make/remap-path-prefix/Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ remap-with-scope:
2121
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
2222
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
2323

24-
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
25-
! grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
26-
grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
24+
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=macro $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
25+
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1
26+
! grep "$$PWD/auxiliary" $(TMPDIR)/liblib.rmeta || exit 1
2727

2828
$(RUSTC) --remap-path-prefix $$PWD/auxiliary=/the/aux -Zremap-path-scope=diagnostics,object $(DEBUGINFOOPTS) --crate-type=lib --emit=metadata auxiliary/lib.rs
2929
grep "/the/aux/lib.rs" $(TMPDIR)/liblib.rmeta || exit 1

0 commit comments

Comments
 (0)