Skip to content

Commit

Permalink
Rollup merge of rust-lang#54626 - alexcrichton:dwarf-generics, r=mich…
Browse files Browse the repository at this point in the history
…aelwoerister

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
  • Loading branch information
pietroalbini authored Oct 25, 2018
2 parents 8ed2028 + 63c471e commit 5703243
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let source_map = self.tcx.sess.source_map();
let all_source_files = source_map.files();

let (working_dir, working_dir_was_remapped) = self.tcx.sess.working_dir.clone();
let (working_dir, _cwd_remapped) = self.tcx.sess.working_dir.clone();

let adapted = all_source_files.iter()
.filter(|source_file| {
Expand All @@ -349,32 +349,26 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
!source_file.is_imported()
})
.map(|source_file| {
// When exporting SourceFiles, we expand all paths to absolute
// paths because any relative paths are potentially relative to
// a wrong directory.
// However, if a path has been modified via
// `--remap-path-prefix` we assume the user has already set
// things up the way they want and don't touch the path values
// anymore.
match source_file.name {
// This path of this SourceFile has been modified by
// path-remapping, so we use it verbatim (and avoid
// cloning the whole map in the process).
_ if source_file.name_was_remapped => source_file.clone(),

// Otherwise expand all paths to absolute paths because
// any relative paths are potentially relative to a
// wrong directory.
FileName::Real(ref name) => {
if source_file.name_was_remapped ||
(name.is_relative() && working_dir_was_remapped) {
// This path of this SourceFile has been modified by
// path-remapping, so we use it verbatim (and avoid cloning
// the whole map in the process).
source_file.clone()
} else {
let mut adapted = (**source_file).clone();
adapted.name = Path::new(&working_dir).join(name).into();
adapted.name_hash = {
let mut hasher: StableHasher<u128> = StableHasher::new();
adapted.name.hash(&mut hasher);
hasher.finish()
};
Lrc::new(adapted)
}
let mut adapted = (**source_file).clone();
adapted.name = Path::new(&working_dir).join(name).into();
adapted.name_hash = {
let mut hasher: StableHasher<u128> = StableHasher::new();
adapted.name.hash(&mut hasher);
hasher.finish()
};
Lrc::new(adapted)
},

// expanded code, not from a file
_ => source_file.clone(),
}
Expand Down
16 changes: 16 additions & 0 deletions src/test/codegen/remap_path_prefix/auxiliary/xcrate-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-tidy-linelength
// compile-flags: -g --remap-path-prefix={{cwd}}=/the/aux-cwd --remap-path-prefix={{src-base}}/remap_path_prefix/auxiliary=/the/aux-src

#![crate_type = "lib"]

pub fn foo<T>() {}
25 changes: 25 additions & 0 deletions src/test/codegen/remap_path_prefix/xcrate-generic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-windows
// ignore-tidy-linelength
// compile-flags: -g -C metadata=foo -C no-prepopulate-passes
// aux-build:xcrate-generic.rs

#![crate_type = "lib"]

extern crate xcrate_generic;

pub fn foo() {
xcrate_generic::foo::<u32>();
}

// Here we check that local debuginfo is mapped correctly.
// CHECK: !DIFile(filename: "/the/aux-src/xcrate-generic.rs", directory: "")

0 comments on commit 5703243

Please sign in to comment.