Skip to content

Commit

Permalink
Use the virtual name for libstd files in StableSourceFileId and also …
Browse files Browse the repository at this point in the history
…in the

encoded build artifacts.

Fix #70924.
  • Loading branch information
pnkfelix committed May 30, 2020
1 parent da09fd3 commit 5e5a3d5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl<'tcx> EncodeContext<'tcx> {
// any relative paths are potentially relative to a
// wrong directory.
FileName::Real(ref name) => {
let name = name.local_path();
let name = name.stable_name();
let mut adapted = (**source_file).clone();
adapted.name = Path::new(&working_dir).join(name).into();
adapted.name_hash = {
Expand Down
13 changes: 13 additions & 0 deletions src/librustc_span/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub enum RealFileName {

impl RealFileName {
/// Returns the path suitable for reading from the file system on the local host.
/// Avoid embedding this in build artifacts; see `stable_name` for that.
pub fn local_path(&self) -> &Path {
match self {
RealFileName::Named(p)
Expand All @@ -107,12 +108,24 @@ impl RealFileName {
}

/// Returns the path suitable for reading from the file system on the local host.
/// Avoid embedding this in build artifacts; see `stable_name` for that.
pub fn into_local_path(self) -> PathBuf {
match self {
RealFileName::Named(p)
| RealFileName::Devirtualized { local_path: p, virtual_name: _ } => p,
}
}

/// Returns the path suitable for embedding into build artifacts. Note that
/// a virtualized path will not correspond to a valid file system path; see
/// `local_path` for something that is more likely to return paths into the
/// local host file system.
pub fn stable_name(&self) -> &Path {
match self {
RealFileName::Named(p)
| RealFileName::Devirtualized { local_path: _, virtual_name: p } => &p,
}
}
}

/// Differentiates between real files and common virtual files.
Expand Down
11 changes: 10 additions & 1 deletion src/librustc_span/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ impl FileLoader for RealFileLoader {
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
pub struct StableSourceFileId(u128);

// FIXME: we need a more globally consistent approach to the problem solved by
// StableSourceFileId, perhaps built atop source_file.name_hash.
impl StableSourceFileId {
pub fn new(source_file: &SourceFile) -> StableSourceFileId {
StableSourceFileId::new_from_pieces(
Expand All @@ -102,7 +104,14 @@ impl StableSourceFileId {
) -> StableSourceFileId {
let mut hasher = StableHasher::new();

name.hash(&mut hasher);
if let FileName::Real(real_name) = name {
// rust-lang/rust#70924: Use the stable (virtualized) name when
// available. (We do not want artifacts from transient file system
// paths for libstd to leak into our build artifacts.)
real_name.stable_name().hash(&mut hasher)
} else {
name.hash(&mut hasher);
}
name_was_remapped.hash(&mut hasher);
unmapped_path.hash(&mut hasher);

Expand Down

0 comments on commit 5e5a3d5

Please sign in to comment.