Skip to content

Commit 2f461b7

Browse files
committed
[RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes
1 parent 8c3eda3 commit 2f461b7

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

Diff for: src/common.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -414,11 +414,12 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
414414
// Note: must be kept in sync with get_caller_location from cg_ssa
415415
pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> {
416416
let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| {
417+
use rustc_session::RemapFileNameExt;
417418
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
418419
let caller = fx.tcx.sess.source_map().lookup_char_pos(topmost.lo());
419420
let const_loc = fx.tcx.const_caller_location((
420421
rustc_span::symbol::Symbol::intern(
421-
&caller.file.name.prefer_remapped().to_string_lossy(),
422+
&caller.file.name.for_codegen(&fx.tcx.sess).to_string_lossy(),
422423
),
423424
caller.line as u32,
424425
caller.col_display as u32 + 1,

Diff for: src/debuginfo/line_info.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ impl DebugContext {
9595
match &source_file.name {
9696
FileName::Real(path) => {
9797
let (dir_path, file_name) =
98-
split_path_dir_and_file(path.remapped_path_if_available());
98+
split_path_dir_and_file(if self.should_remap_filepaths {
99+
path.remapped_path_if_available()
100+
} else {
101+
path.local_path_if_available()
102+
});
99103
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
100104
let file_name = osstr_as_utf8_bytes(file_name);
101105

@@ -116,7 +120,14 @@ impl DebugContext {
116120
filename => {
117121
let dir_id = line_program.default_directory();
118122
let dummy_file_name = LineString::new(
119-
filename.prefer_remapped().to_string().into_bytes(),
123+
filename
124+
.display(if self.should_remap_filepaths {
125+
FileNameDisplayPreference::Remapped
126+
} else {
127+
FileNameDisplayPreference::Local
128+
})
129+
.to_string()
130+
.into_bytes(),
120131
line_program.encoding(),
121132
line_strings,
122133
);

Diff for: src/debuginfo/mod.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub(crate) struct DebugContext {
3131

3232
dwarf: DwarfUnit,
3333
unit_range_list: RangeList,
34+
35+
should_remap_filepaths: bool,
3436
}
3537

3638
pub(crate) struct FunctionDebugContext {
@@ -63,12 +65,18 @@ impl DebugContext {
6365

6466
let mut dwarf = DwarfUnit::new(encoding);
6567

68+
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen();
69+
6670
let producer = producer();
6771
let comp_dir = tcx
6872
.sess
6973
.opts
7074
.working_dir
71-
.to_string_lossy(FileNameDisplayPreference::Remapped)
75+
.to_string_lossy(if should_remap_filepaths {
76+
FileNameDisplayPreference::Remapped
77+
} else {
78+
FileNameDisplayPreference::Local
79+
})
7280
.into_owned();
7381
let (name, file_info) = match tcx.sess.local_crate_source_file() {
7482
Some(path) => {
@@ -102,7 +110,12 @@ impl DebugContext {
102110
root.set(gimli::DW_AT_low_pc, AttributeValue::Address(Address::Constant(0)));
103111
}
104112

105-
DebugContext { endian, dwarf, unit_range_list: RangeList(Vec::new()) }
113+
DebugContext {
114+
endian,
115+
dwarf,
116+
unit_range_list: RangeList(Vec::new()),
117+
should_remap_filepaths,
118+
}
106119
}
107120

108121
pub(crate) fn define_function(

0 commit comments

Comments
 (0)