Skip to content

Do not intern filemap to entry w/ mismatched length. #37449

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

Merged
merged 2 commits into from
Oct 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,14 @@ impl<'a, 'tcx> CrateMetadata {

match reusable_filemap {
Some(fm) => {

debug!("CrateMetaData::imported_filemaps reuse \
filemap {:?} original (start_pos {:?} end_pos {:?}) \
translated (start_pos {:?} end_pos {:?})",
filemap_to_import.name,
filemap_to_import.start_pos, filemap_to_import.end_pos,
fm.start_pos, fm.end_pos);

cstore::ImportedFileMap {
original_start_pos: filemap_to_import.start_pos,
original_end_pos: filemap_to_import.end_pos,
Expand Down Expand Up @@ -1176,6 +1184,12 @@ impl<'a, 'tcx> CrateMetadata {
source_length,
lines,
multibyte_chars);
debug!("CrateMetaData::imported_filemaps alloc \
filemap {:?} original (start_pos {:?} end_pos {:?}) \
translated (start_pos {:?} end_pos {:?})",
local_version.name, start_pos, end_pos,
local_version.start_pos, local_version.end_pos);

cstore::ImportedFileMap {
original_start_pos: start_pos,
original_end_pos: end_pos,
Expand All @@ -1193,6 +1207,10 @@ impl<'a, 'tcx> CrateMetadata {
}

fn are_equal_modulo_startpos(fm1: &syntax_pos::FileMap, fm2: &syntax_pos::FileMap) -> bool {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(maybe we should move this to a method on FileMap, the idea being that future modifications to FileMap, such as adding new fields, would know to update the method accordingly. But that can wait for a future PR; I prefer to keep this one minimal.)

if fm1.byte_length() != fm2.byte_length() {
return false;
}

if fm1.name != fm2.name {
return false;
}
Expand Down
3 changes: 3 additions & 0 deletions src/libsyntax_pos/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ impl FileMap {
self.src.is_none()
}

pub fn byte_length(&self) -> u32 {
self.end_pos.0 - self.start_pos.0
}
pub fn count_lines(&self) -> usize {
self.lines.borrow().len()
}
Expand Down