-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Track devirtualized filenames #72767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
905d738
da09fd3
5e5a3d5
a8e4236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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( | ||
|
@@ -95,14 +97,21 @@ impl StableSourceFileId { | |
) | ||
} | ||
|
||
pub fn new_from_pieces( | ||
fn new_from_pieces( | ||
name: &FileName, | ||
name_was_remapped: bool, | ||
unmapped_path: Option<&FileName>, | ||
) -> 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); | ||
} | ||
Comment on lines
+107
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just noticed a problem with this (although it's unlikely to cause issues in practice): the hashed data could overlap. If we had an |
||
name_was_remapped.hash(&mut hasher); | ||
unmapped_path.hash(&mut hasher); | ||
|
||
|
@@ -235,7 +244,7 @@ impl SourceMap { | |
|
||
fn try_new_source_file( | ||
&self, | ||
filename: FileName, | ||
mut filename: FileName, | ||
src: String, | ||
) -> Result<Lrc<SourceFile>, OffsetOverflowError> { | ||
// The path is used to determine the directory for loading submodules and | ||
|
@@ -245,13 +254,22 @@ impl SourceMap { | |
// be empty, so the working directory will be used. | ||
let unmapped_path = filename.clone(); | ||
|
||
let (filename, was_remapped) = match filename { | ||
FileName::Real(filename) => { | ||
let (filename, was_remapped) = self.path_mapping.map_prefix(filename); | ||
(FileName::Real(filename), was_remapped) | ||
let was_remapped; | ||
if let FileName::Real(real_filename) = &mut filename { | ||
match real_filename { | ||
RealFileName::Named(path_to_be_remapped) | ||
| RealFileName::Devirtualized { | ||
local_path: path_to_be_remapped, | ||
virtual_name: _, | ||
} => { | ||
let mapped = self.path_mapping.map_prefix(path_to_be_remapped.clone()); | ||
was_remapped = mapped.1; | ||
*path_to_be_remapped = mapped.0; | ||
} | ||
} | ||
other => (other, false), | ||
}; | ||
} else { | ||
was_remapped = false; | ||
} | ||
|
||
let file_id = | ||
StableSourceFileId::new_from_pieces(&filename, was_remapped, Some(&unmapped_path)); | ||
|
@@ -998,7 +1016,7 @@ impl SourceMap { | |
} | ||
pub fn ensure_source_file_source_present(&self, source_file: Lrc<SourceFile>) -> bool { | ||
source_file.add_external_src(|| match source_file.name { | ||
FileName::Real(ref name) => self.file_loader.read_file(name).ok(), | ||
FileName::Real(ref name) => self.file_loader.read_file(name.local_path()).ok(), | ||
_ => None, | ||
}) | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.