Skip to content

Commit 63c471e

Browse files
committed
rustc: Tweak filenames encoded into metadata
This commit is a fix for rust-lang#54408 where on nightly right now whenever generics are inlined the path name listed for the inlined function's debuginfo is a relative path to the cwd, which surely doesn't exist! Previously on beta/stable the debuginfo mentioned an absolute path which still didn't exist, but more predictably didn't exist. The change between stable/nightly is that nightly is now compiled with `--remap-path-prefix` to give a deterministic prefix to all rustc-generated paths in debuginfo. By using `--remap-path-prefix` the previous logic would recognize that the cwd was remapped, causing the original relative path name of the standard library to get emitted. If `--remap-path-prefix` *wasn't* passed in then the logic would create an absolute path name and then create a new source file entry. The fix in this commit is to apply the "recreate the source file entry with an absolute path" logic a bit more aggresively. If the source file's name was remapped then we don't touch it, but otherwise we always take the working dir (which may have been remapped) and then join it to the file to ensure that we process all relative file names as well. The end result is that the standard library should have an absolute path for all file names in debuginfo (using our `--remap-path-prefix` argument) as it does on stable after this patch. Closes rust-lang#54408
1 parent 8876906 commit 63c471e

File tree

3 files changed

+59
-24
lines changed

3 files changed

+59
-24
lines changed

src/librustc_metadata/encoder.rs

+18-24
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
340340
let source_map = self.tcx.sess.source_map();
341341
let all_source_files = source_map.files();
342342

343-
let (working_dir, working_dir_was_remapped) = self.tcx.sess.working_dir.clone();
343+
let (working_dir, _cwd_remapped) = self.tcx.sess.working_dir.clone();
344344

345345
let adapted = all_source_files.iter()
346346
.filter(|source_file| {
@@ -349,32 +349,26 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
349349
!source_file.is_imported()
350350
})
351351
.map(|source_file| {
352-
// When exporting SourceFiles, we expand all paths to absolute
353-
// paths because any relative paths are potentially relative to
354-
// a wrong directory.
355-
// However, if a path has been modified via
356-
// `--remap-path-prefix` we assume the user has already set
357-
// things up the way they want and don't touch the path values
358-
// anymore.
359352
match source_file.name {
353+
// This path of this SourceFile has been modified by
354+
// path-remapping, so we use it verbatim (and avoid
355+
// cloning the whole map in the process).
356+
_ if source_file.name_was_remapped => source_file.clone(),
357+
358+
// Otherwise expand all paths to absolute paths because
359+
// any relative paths are potentially relative to a
360+
// wrong directory.
360361
FileName::Real(ref name) => {
361-
if source_file.name_was_remapped ||
362-
(name.is_relative() && working_dir_was_remapped) {
363-
// This path of this SourceFile has been modified by
364-
// path-remapping, so we use it verbatim (and avoid cloning
365-
// the whole map in the process).
366-
source_file.clone()
367-
} else {
368-
let mut adapted = (**source_file).clone();
369-
adapted.name = Path::new(&working_dir).join(name).into();
370-
adapted.name_hash = {
371-
let mut hasher: StableHasher<u128> = StableHasher::new();
372-
adapted.name.hash(&mut hasher);
373-
hasher.finish()
374-
};
375-
Lrc::new(adapted)
376-
}
362+
let mut adapted = (**source_file).clone();
363+
adapted.name = Path::new(&working_dir).join(name).into();
364+
adapted.name_hash = {
365+
let mut hasher: StableHasher<u128> = StableHasher::new();
366+
adapted.name.hash(&mut hasher);
367+
hasher.finish()
368+
};
369+
Lrc::new(adapted)
377370
},
371+
378372
// expanded code, not from a file
379373
_ => source_file.clone(),
380374
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-tidy-linelength
12+
// compile-flags: -g --remap-path-prefix={{cwd}}=/the/aux-cwd --remap-path-prefix={{src-base}}/remap_path_prefix/auxiliary=/the/aux-src
13+
14+
#![crate_type = "lib"]
15+
16+
pub fn foo<T>() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-windows
12+
// ignore-tidy-linelength
13+
// compile-flags: -g -C metadata=foo -C no-prepopulate-passes
14+
// aux-build:xcrate-generic.rs
15+
16+
#![crate_type = "lib"]
17+
18+
extern crate xcrate_generic;
19+
20+
pub fn foo() {
21+
xcrate_generic::foo::<u32>();
22+
}
23+
24+
// Here we check that local debuginfo is mapped correctly.
25+
// CHECK: !DIFile(filename: "/the/aux-src/xcrate-generic.rs", directory: "")

0 commit comments

Comments
 (0)