Auto merge of #122450 - Urgau:simplify-trim-paths-feature, r=michaelwoerister

Simplify trim-paths feature by merging all debuginfo options together

This PR simplifies the trim-paths feature by merging all debuginfo options together, as described in https://github.com/rust-lang/rust/issues/111540#issuecomment-1994010274.

And also do some correctness fixes found during the review.

cc `@weihanglo`
r? `@michaelwoerister`
This commit is contained in:
bors 2024-03-29 14:00:21 +00:00
commit b2f6349b49
2 changed files with 12 additions and 27 deletions

View File

@ -89,11 +89,7 @@ pub(crate) fn add_source_file(&mut self, source_file: &SourceFile) -> FileId {
match &source_file.name { match &source_file.name {
FileName::Real(path) => { FileName::Real(path) => {
let (dir_path, file_name) = let (dir_path, file_name) =
split_path_dir_and_file(if self.should_remap_filepaths { split_path_dir_and_file(path.to_path(self.filename_display_preference));
path.remapped_path_if_available()
} else {
path.local_path_if_available()
});
let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str()); let dir_name = osstr_as_utf8_bytes(dir_path.as_os_str());
let file_name = osstr_as_utf8_bytes(file_name); let file_name = osstr_as_utf8_bytes(file_name);
@ -115,14 +111,7 @@ pub(crate) fn add_source_file(&mut self, source_file: &SourceFile) -> FileId {
filename => { filename => {
let dir_id = line_program.default_directory(); let dir_id = line_program.default_directory();
let dummy_file_name = LineString::new( let dummy_file_name = LineString::new(
filename filename.display(self.filename_display_preference).to_string().into_bytes(),
.display(if self.should_remap_filepaths {
FileNameDisplayPreference::Remapped
} else {
FileNameDisplayPreference::Local
})
.to_string()
.into_bytes(),
line_program.encoding(), line_program.encoding(),
line_strings, line_strings,
); );

View File

@ -42,7 +42,7 @@ pub(crate) struct DebugContext {
namespace_map: DefIdMap<UnitEntryId>, namespace_map: DefIdMap<UnitEntryId>,
array_size_type: UnitEntryId, array_size_type: UnitEntryId,
should_remap_filepaths: bool, filename_display_preference: FileNameDisplayPreference,
} }
pub(crate) struct FunctionDebugContext { pub(crate) struct FunctionDebugContext {
@ -84,22 +84,18 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, cgu_name: &str) -> Self
let mut dwarf = DwarfUnit::new(encoding); let mut dwarf = DwarfUnit::new(encoding);
let should_remap_filepaths = tcx.sess.should_prefer_remapped_for_codegen(); use rustc_session::config::RemapPathScopeComponents;
let filename_display_preference =
tcx.sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
let producer = producer(tcx.sess); let producer = producer(tcx.sess);
let comp_dir = tcx let comp_dir =
.sess tcx.sess.opts.working_dir.to_string_lossy(filename_display_preference).to_string();
.opts
.working_dir
.to_string_lossy(if should_remap_filepaths {
FileNameDisplayPreference::Remapped
} else {
FileNameDisplayPreference::Local
})
.into_owned();
let (name, file_info) = match tcx.sess.local_crate_source_file() { let (name, file_info) = match tcx.sess.local_crate_source_file() {
Some(path) => { Some(path) => {
let name = path.to_string_lossy().into_owned(); let name = path.to_string_lossy(filename_display_preference).to_string();
(name, None) (name, None)
} }
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),
@ -156,7 +152,7 @@ pub(crate) fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, cgu_name: &str) -> Self
stack_pointer_register, stack_pointer_register,
namespace_map: DefIdMap::default(), namespace_map: DefIdMap::default(),
array_size_type, array_size_type,
should_remap_filepaths, filename_display_preference,
} }
} }