Auto merge of #46757 - michaelwoerister:revert-46562, r=eddyb
incr.comp.: Revert hashing optimization that caused regression. This PR reverts part of #46562 which caused [a regression in the crossbeam rust-icci](https://travis-ci.org/rust-icci/crossbeam/builds/316574774) test. I don't know what the problem is exactly yet. Fortunately, the problematic part is also the less important one, so reverting should not have much impact on performance. r? @eddyb
This commit is contained in:
commit
39cb4c6057
|
@ -341,7 +341,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
|
||||||
std_hash::Hash::hash(&TAG_VALID_SPAN, hasher);
|
std_hash::Hash::hash(&TAG_VALID_SPAN, hasher);
|
||||||
// We truncate the stable_id hash and line and col numbers. The chances
|
// We truncate the stable_id hash and line and col numbers. The chances
|
||||||
// of causing a collision this way should be minimal.
|
// of causing a collision this way should be minimal.
|
||||||
std_hash::Hash::hash(&(file_lo.stable_id.0 as u64), hasher);
|
std_hash::Hash::hash(&file_lo.name, hasher);
|
||||||
|
|
||||||
let col = (col_lo.0 as u64) & 0xFF;
|
let col = (col_lo.0 as u64) & 0xFF;
|
||||||
let line = ((line_lo as u64) & 0xFF_FF_FF) << 8;
|
let line = ((line_lo as u64) & 0xFF_FF_FF) << 8;
|
||||||
|
|
|
@ -394,8 +394,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for FileMap {
|
||||||
// Do not hash the source as it is not encoded
|
// Do not hash the source as it is not encoded
|
||||||
src: _,
|
src: _,
|
||||||
src_hash,
|
src_hash,
|
||||||
// The stable id is just a hash of other fields
|
|
||||||
stable_id: _,
|
|
||||||
external_src: _,
|
external_src: _,
|
||||||
start_pos,
|
start_pos,
|
||||||
end_pos: _,
|
end_pos: _,
|
||||||
|
|
|
@ -176,7 +176,7 @@ impl<'sess> OnDiskCache<'sess> {
|
||||||
let index = FileMapIndex(index as u32);
|
let index = FileMapIndex(index as u32);
|
||||||
let file_ptr: *const FileMap = &**file as *const _;
|
let file_ptr: *const FileMap = &**file as *const _;
|
||||||
file_to_file_index.insert(file_ptr, index);
|
file_to_file_index.insert(file_ptr, index);
|
||||||
file_index_to_stable_id.insert(index, file.stable_id);
|
file_index_to_stable_id.insert(index, StableFilemapId::new(&file));
|
||||||
}
|
}
|
||||||
|
|
||||||
(file_to_file_index, file_index_to_stable_id)
|
(file_to_file_index, file_index_to_stable_id)
|
||||||
|
|
|
@ -1124,7 +1124,6 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
let syntax_pos::FileMap { name,
|
let syntax_pos::FileMap { name,
|
||||||
name_was_remapped,
|
name_was_remapped,
|
||||||
src_hash,
|
src_hash,
|
||||||
stable_id,
|
|
||||||
start_pos,
|
start_pos,
|
||||||
end_pos,
|
end_pos,
|
||||||
lines,
|
lines,
|
||||||
|
@ -1156,7 +1155,6 @@ impl<'a, 'tcx> CrateMetadata {
|
||||||
name_was_remapped,
|
name_was_remapped,
|
||||||
self.cnum.as_u32(),
|
self.cnum.as_u32(),
|
||||||
src_hash,
|
src_hash,
|
||||||
stable_id,
|
|
||||||
source_length,
|
source_length,
|
||||||
lines,
|
lines,
|
||||||
multibyte_chars,
|
multibyte_chars,
|
||||||
|
|
|
@ -23,7 +23,9 @@ pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
|
||||||
pub use self::ExpnFormat::*;
|
pub use self::ExpnFormat::*;
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
|
use rustc_data_structures::stable_hasher::StableHasher;
|
||||||
use std::cell::{RefCell, Ref};
|
use std::cell::{RefCell, Ref};
|
||||||
|
use std::hash::Hash;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -100,6 +102,24 @@ impl FileLoader for RealFileLoader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a FileMap identifier that is used to correlate FileMaps between
|
||||||
|
// subsequent compilation sessions (which is something we need to do during
|
||||||
|
// incremental compilation).
|
||||||
|
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
|
||||||
|
pub struct StableFilemapId(u128);
|
||||||
|
|
||||||
|
impl StableFilemapId {
|
||||||
|
pub fn new(filemap: &FileMap) -> StableFilemapId {
|
||||||
|
let mut hasher = StableHasher::new();
|
||||||
|
|
||||||
|
filemap.name.hash(&mut hasher);
|
||||||
|
filemap.name_was_remapped.hash(&mut hasher);
|
||||||
|
filemap.unmapped_path.hash(&mut hasher);
|
||||||
|
|
||||||
|
StableFilemapId(hasher.finish())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// _____________________________________________________________________________
|
// _____________________________________________________________________________
|
||||||
// CodeMap
|
// CodeMap
|
||||||
//
|
//
|
||||||
|
@ -197,7 +217,7 @@ impl CodeMap {
|
||||||
|
|
||||||
self.stable_id_to_filemap
|
self.stable_id_to_filemap
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(filemap.stable_id, filemap.clone());
|
.insert(StableFilemapId::new(&filemap), filemap.clone());
|
||||||
|
|
||||||
filemap
|
filemap
|
||||||
}
|
}
|
||||||
|
@ -226,7 +246,6 @@ impl CodeMap {
|
||||||
name_was_remapped: bool,
|
name_was_remapped: bool,
|
||||||
crate_of_origin: u32,
|
crate_of_origin: u32,
|
||||||
src_hash: u128,
|
src_hash: u128,
|
||||||
stable_id: StableFilemapId,
|
|
||||||
source_len: usize,
|
source_len: usize,
|
||||||
mut file_local_lines: Vec<BytePos>,
|
mut file_local_lines: Vec<BytePos>,
|
||||||
mut file_local_multibyte_chars: Vec<MultiByteChar>,
|
mut file_local_multibyte_chars: Vec<MultiByteChar>,
|
||||||
|
@ -257,7 +276,6 @@ impl CodeMap {
|
||||||
crate_of_origin,
|
crate_of_origin,
|
||||||
src: None,
|
src: None,
|
||||||
src_hash,
|
src_hash,
|
||||||
stable_id,
|
|
||||||
external_src: RefCell::new(ExternalSource::AbsentOk),
|
external_src: RefCell::new(ExternalSource::AbsentOk),
|
||||||
start_pos,
|
start_pos,
|
||||||
end_pos,
|
end_pos,
|
||||||
|
@ -270,7 +288,7 @@ impl CodeMap {
|
||||||
|
|
||||||
self.stable_id_to_filemap
|
self.stable_id_to_filemap
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.insert(stable_id, filemap.clone());
|
.insert(StableFilemapId::new(&filemap), filemap.clone());
|
||||||
|
|
||||||
filemap
|
filemap
|
||||||
}
|
}
|
||||||
|
|
|
@ -678,8 +678,6 @@ pub struct FileMap {
|
||||||
pub src: Option<Rc<String>>,
|
pub src: Option<Rc<String>>,
|
||||||
/// The source code's hash
|
/// The source code's hash
|
||||||
pub src_hash: u128,
|
pub src_hash: u128,
|
||||||
/// The stable id used during incr. comp.
|
|
||||||
pub stable_id: StableFilemapId,
|
|
||||||
/// The external source code (used for external crates, which will have a `None`
|
/// The external source code (used for external crates, which will have a `None`
|
||||||
/// value as `self.src`.
|
/// value as `self.src`.
|
||||||
pub external_src: RefCell<ExternalSource>,
|
pub external_src: RefCell<ExternalSource>,
|
||||||
|
@ -695,34 +693,12 @@ pub struct FileMap {
|
||||||
pub non_narrow_chars: RefCell<Vec<NonNarrowChar>>,
|
pub non_narrow_chars: RefCell<Vec<NonNarrowChar>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a FileMap identifier that is used to correlate FileMaps between
|
|
||||||
// subsequent compilation sessions (which is something we need to do during
|
|
||||||
// incremental compilation).
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
|
|
||||||
pub struct StableFilemapId(pub u128);
|
|
||||||
|
|
||||||
impl StableFilemapId {
|
|
||||||
pub fn new(name: &FileName,
|
|
||||||
name_was_remapped: bool,
|
|
||||||
unmapped_path: &FileName)
|
|
||||||
-> StableFilemapId {
|
|
||||||
use std::hash::Hash;
|
|
||||||
|
|
||||||
let mut hasher = StableHasher::new();
|
|
||||||
name.hash(&mut hasher);
|
|
||||||
name_was_remapped.hash(&mut hasher);
|
|
||||||
unmapped_path.hash(&mut hasher);
|
|
||||||
StableFilemapId(hasher.finish())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Encodable for FileMap {
|
impl Encodable for FileMap {
|
||||||
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||||
s.emit_struct("FileMap", 8, |s| {
|
s.emit_struct("FileMap", 8, |s| {
|
||||||
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
|
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
|
||||||
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
|
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
|
||||||
s.emit_struct_field("src_hash", 2, |s| self.src_hash.encode(s))?;
|
s.emit_struct_field("src_hash", 2, |s| self.src_hash.encode(s))?;
|
||||||
s.emit_struct_field("stable_id", 3, |s| self.stable_id.encode(s))?;
|
|
||||||
s.emit_struct_field("start_pos", 4, |s| self.start_pos.encode(s))?;
|
s.emit_struct_field("start_pos", 4, |s| self.start_pos.encode(s))?;
|
||||||
s.emit_struct_field("end_pos", 5, |s| self.end_pos.encode(s))?;
|
s.emit_struct_field("end_pos", 5, |s| self.end_pos.encode(s))?;
|
||||||
s.emit_struct_field("lines", 6, |s| {
|
s.emit_struct_field("lines", 6, |s| {
|
||||||
|
@ -790,8 +766,6 @@ impl Decodable for FileMap {
|
||||||
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
|
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
|
||||||
let src_hash: u128 =
|
let src_hash: u128 =
|
||||||
d.read_struct_field("src_hash", 2, |d| Decodable::decode(d))?;
|
d.read_struct_field("src_hash", 2, |d| Decodable::decode(d))?;
|
||||||
let stable_id: StableFilemapId =
|
|
||||||
d.read_struct_field("stable_id", 3, |d| Decodable::decode(d))?;
|
|
||||||
let start_pos: BytePos =
|
let start_pos: BytePos =
|
||||||
d.read_struct_field("start_pos", 4, |d| Decodable::decode(d))?;
|
d.read_struct_field("start_pos", 4, |d| Decodable::decode(d))?;
|
||||||
let end_pos: BytePos = d.read_struct_field("end_pos", 5, |d| Decodable::decode(d))?;
|
let end_pos: BytePos = d.read_struct_field("end_pos", 5, |d| Decodable::decode(d))?;
|
||||||
|
@ -839,7 +813,6 @@ impl Decodable for FileMap {
|
||||||
end_pos,
|
end_pos,
|
||||||
src: None,
|
src: None,
|
||||||
src_hash,
|
src_hash,
|
||||||
stable_id,
|
|
||||||
external_src: RefCell::new(ExternalSource::AbsentOk),
|
external_src: RefCell::new(ExternalSource::AbsentOk),
|
||||||
lines: RefCell::new(lines),
|
lines: RefCell::new(lines),
|
||||||
multibyte_chars: RefCell::new(multibyte_chars),
|
multibyte_chars: RefCell::new(multibyte_chars),
|
||||||
|
@ -866,11 +839,6 @@ impl FileMap {
|
||||||
let mut hasher: StableHasher<u128> = StableHasher::new();
|
let mut hasher: StableHasher<u128> = StableHasher::new();
|
||||||
hasher.write(src.as_bytes());
|
hasher.write(src.as_bytes());
|
||||||
let src_hash = hasher.finish();
|
let src_hash = hasher.finish();
|
||||||
|
|
||||||
let stable_id = StableFilemapId::new(&name,
|
|
||||||
name_was_remapped,
|
|
||||||
&unmapped_path);
|
|
||||||
|
|
||||||
let end_pos = start_pos.to_usize() + src.len();
|
let end_pos = start_pos.to_usize() + src.len();
|
||||||
|
|
||||||
FileMap {
|
FileMap {
|
||||||
|
@ -880,7 +848,6 @@ impl FileMap {
|
||||||
crate_of_origin: 0,
|
crate_of_origin: 0,
|
||||||
src: Some(Rc::new(src)),
|
src: Some(Rc::new(src)),
|
||||||
src_hash,
|
src_hash,
|
||||||
stable_id,
|
|
||||||
external_src: RefCell::new(ExternalSource::Unneeded),
|
external_src: RefCell::new(ExternalSource::Unneeded),
|
||||||
start_pos,
|
start_pos,
|
||||||
end_pos: Pos::from_usize(end_pos),
|
end_pos: Pos::from_usize(end_pos),
|
||||||
|
|
Loading…
Reference in New Issue