From 5de668acb07218424cbfe79f32f4961ca773570d Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 19 Mar 2024 13:51:22 +0100 Subject: [PATCH 1/4] Replace `RemapFileNameExt::for_codegen` with explicit calls --- src/debuginfo/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 1bb0e59051372..c9f59ae9f29aa 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -84,7 +84,9 @@ impl DebugContext { let mut dwarf = DwarfUnit::new(encoding); - let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen(); + use rustc_session::config::RemapPathScopeComponents; + let should_remap_filepaths = + tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO); let producer = producer(tcx.sess); let comp_dir = tcx From d6a817a7d9b8950cf73914d17cfc1c8e35dc2c7f Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 19 Mar 2024 13:51:22 +0100 Subject: [PATCH 2/4] Make local_crate_source_file return a RealFileName so it can be remapped (or not) by callers --- src/debuginfo/mod.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index c9f59ae9f29aa..222dc56a2b1bc 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -99,9 +99,16 @@ impl DebugContext { FileNameDisplayPreference::Local }) .into_owned(); + let (name, file_info) = match tcx.sess.local_crate_source_file() { Some(path) => { - let name = path.to_string_lossy().into_owned(); + let name = path + .to_string_lossy(if should_remap_filepaths { + FileNameDisplayPreference::Remapped + } else { + FileNameDisplayPreference::Local + }) + .into_owned(); (name, None) } None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), From 6a2b2b43bd65ee7e3def7e10289bb98ca415dc03 Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 21 Mar 2024 21:13:06 +0100 Subject: [PATCH 3/4] Introduce `FileNameMapping::to_real_filename` and use it everywhere --- src/debuginfo/mod.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 222dc56a2b1bc..b661fa185b859 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -85,6 +85,8 @@ impl DebugContext { let mut dwarf = DwarfUnit::new(encoding); use rustc_session::config::RemapPathScopeComponents; + use rustc_session::RemapFileNameExt; + let should_remap_filepaths = tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO); @@ -93,22 +95,16 @@ impl DebugContext { .sess .opts .working_dir - .to_string_lossy(if should_remap_filepaths { - FileNameDisplayPreference::Remapped - } else { - FileNameDisplayPreference::Local - }) - .into_owned(); + .for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO) + .to_string_lossy() + .to_string(); let (name, file_info) = match tcx.sess.local_crate_source_file() { Some(path) => { let name = path - .to_string_lossy(if should_remap_filepaths { - FileNameDisplayPreference::Remapped - } else { - FileNameDisplayPreference::Local - }) - .into_owned(); + .for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO) + .to_string_lossy() + .to_string(); (name, None) } None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), From 4d7ded634aab19de52b382794010563574f1507d Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 22 Mar 2024 15:27:17 +0100 Subject: [PATCH 4/4] Replace Session should_remap_filepaths with filename_display_preference --- src/debuginfo/line_info.rs | 15 ++------------- src/debuginfo/mod.rs | 23 +++++++---------------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index 380eba437c270..32b9c824ded2f 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -89,11 +89,7 @@ impl DebugContext { match &source_file.name { FileName::Real(path) => { let (dir_path, file_name) = - split_path_dir_and_file(if self.should_remap_filepaths { - path.remapped_path_if_available() - } else { - path.local_path_if_available() - }); + split_path_dir_and_file(path.to_path(self.filename_display_preference)); let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str()); let file_name = osstr_as_utf8_bytes(file_name); @@ -115,14 +111,7 @@ impl DebugContext { filename => { let dir_id = line_program.default_directory(); let dummy_file_name = LineString::new( - filename - .display(if self.should_remap_filepaths { - FileNameDisplayPreference::Remapped - } else { - FileNameDisplayPreference::Local - }) - .to_string() - .into_bytes(), + filename.display(self.filename_display_preference).to_string().into_bytes(), line_program.encoding(), line_strings, ); diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index b661fa185b859..5d943b5d99657 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -42,7 +42,7 @@ pub(crate) struct DebugContext { namespace_map: DefIdMap, array_size_type: UnitEntryId, - should_remap_filepaths: bool, + filename_display_preference: FileNameDisplayPreference, } pub(crate) struct FunctionDebugContext { @@ -85,26 +85,17 @@ impl DebugContext { let mut dwarf = DwarfUnit::new(encoding); use rustc_session::config::RemapPathScopeComponents; - use rustc_session::RemapFileNameExt; - let should_remap_filepaths = - tcx.sess.should_prefer_remapped(RemapPathScopeComponents::DEBUGINFO); + let filename_display_preference = + tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO); let producer = producer(tcx.sess); - let comp_dir = tcx - .sess - .opts - .working_dir - .for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO) - .to_string_lossy() - .to_string(); + let comp_dir = + tcx.sess.opts.working_dir.to_string_lossy(filename_display_preference).to_string(); let (name, file_info) = match tcx.sess.local_crate_source_file() { Some(path) => { - let name = path - .for_scope(tcx.sess, RemapPathScopeComponents::DEBUGINFO) - .to_string_lossy() - .to_string(); + let name = path.to_string_lossy(filename_display_preference).to_string(); (name, None) } None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), @@ -161,7 +152,7 @@ impl DebugContext { stack_pointer_register, namespace_map: DefIdMap::default(), array_size_type, - should_remap_filepaths, + filename_display_preference, } }