Skip to content

Commit 09c34cb

Browse files
committed
Auto merge of #149709 - Urgau:overhaul-filenames, r=davidtwco
Overhaul filename handling for cross-compiler consistency This PR overhauls the way we handle filenames in the compiler and `rmeta` in order to achieve achieve cross-compiler consistency (ie. having the same path no matter if the filename was created in the current compiler session or is coming from `rmeta`). This is required as some parts of the compiler rely on consistent paths for the soundness of generated code (see rust-lang/rust#148328). In order to achieved consistency multiple steps are being taken by this PR: - by making `RealFileName` immutable - by only having `SourceMap::to_real_filename` create `RealFileName` - currently `RealFileName` can be created from any `Path` and are remapped afterwards, which creates consistency issue - by also making `RealFileName` holds it's working directory, embeddable name and the remapped scopes - this removes the need for a `Session`, to know the current(!) scopes and cwd, which is invalid as they may not be equal to the scopes used when creating the filename In order for `SourceMap::to_real_filename` to know which scopes to apply `FilePathMapping` now takes the current remapping scopes to apply, which makes `FileNameDisplayPreference` and company useless and are removed. This PR is split-up in multiple commits (unfortunately not atomic), but should help review the changes. Unblocks rust-lang/rust#147611 Fixes rust-lang/rust#148328
2 parents 2afb92f + a95aaca commit 09c34cb

File tree

1 file changed

+5
-23
lines changed

1 file changed

+5
-23
lines changed

src/debuginfo.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,29 +297,11 @@ impl<'gcc, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
297297
let pos = span.lo();
298298
let DebugLoc { file, line, col } = self.lookup_debug_loc(pos);
299299
match file.name {
300-
rustc_span::FileName::Real(ref name) => match *name {
301-
rustc_span::RealFileName::LocalPath(ref name) => {
302-
if let Some(name) = name.to_str() {
303-
self.context.new_location(name, line as i32, col as i32)
304-
} else {
305-
Location::null()
306-
}
307-
}
308-
rustc_span::RealFileName::Remapped {
309-
ref local_path,
310-
virtual_name: ref _unused,
311-
} => {
312-
if let Some(name) = local_path.as_ref() {
313-
if let Some(name) = name.to_str() {
314-
self.context.new_location(name, line as i32, col as i32)
315-
} else {
316-
Location::null()
317-
}
318-
} else {
319-
Location::null()
320-
}
321-
}
322-
},
300+
rustc_span::FileName::Real(ref name) => self.context.new_location(
301+
name.path(rustc_span::RemapPathScopeComponents::DEBUGINFO).to_string_lossy(),
302+
line as i32,
303+
col as i32,
304+
),
323305
_ => Location::null(),
324306
}
325307
}

0 commit comments

Comments
 (0)