Skip to content

Commit 39cb4c6

Browse files
committed
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
2 parents abab763 + c7e5b70 commit 39cb4c6

File tree

6 files changed

+24
-43
lines changed

6 files changed

+24
-43
lines changed

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
341341
std_hash::Hash::hash(&TAG_VALID_SPAN, hasher);
342342
// We truncate the stable_id hash and line and col numbers. The chances
343343
// of causing a collision this way should be minimal.
344-
std_hash::Hash::hash(&(file_lo.stable_id.0 as u64), hasher);
344+
std_hash::Hash::hash(&file_lo.name, hasher);
345345

346346
let col = (col_lo.0 as u64) & 0xFF;
347347
let line = ((line_lo as u64) & 0xFF_FF_FF) << 8;

src/librustc/ich/impls_syntax.rs

-2
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,6 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for FileMap {
394394
// Do not hash the source as it is not encoded
395395
src: _,
396396
src_hash,
397-
// The stable id is just a hash of other fields
398-
stable_id: _,
399397
external_src: _,
400398
start_pos,
401399
end_pos: _,

src/librustc/ty/maps/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl<'sess> OnDiskCache<'sess> {
176176
let index = FileMapIndex(index as u32);
177177
let file_ptr: *const FileMap = &**file as *const _;
178178
file_to_file_index.insert(file_ptr, index);
179-
file_index_to_stable_id.insert(index, file.stable_id);
179+
file_index_to_stable_id.insert(index, StableFilemapId::new(&file));
180180
}
181181

182182
(file_to_file_index, file_index_to_stable_id)

src/librustc_metadata/decoder.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,6 @@ impl<'a, 'tcx> CrateMetadata {
11241124
let syntax_pos::FileMap { name,
11251125
name_was_remapped,
11261126
src_hash,
1127-
stable_id,
11281127
start_pos,
11291128
end_pos,
11301129
lines,
@@ -1156,7 +1155,6 @@ impl<'a, 'tcx> CrateMetadata {
11561155
name_was_remapped,
11571156
self.cnum.as_u32(),
11581157
src_hash,
1159-
stable_id,
11601158
source_length,
11611159
lines,
11621160
multibyte_chars,

src/libsyntax/codemap.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
2323
pub use self::ExpnFormat::*;
2424

2525
use rustc_data_structures::fx::FxHashMap;
26+
use rustc_data_structures::stable_hasher::StableHasher;
2627
use std::cell::{RefCell, Ref};
28+
use std::hash::Hash;
2729
use std::path::{Path, PathBuf};
2830
use std::rc::Rc;
2931

@@ -100,6 +102,24 @@ impl FileLoader for RealFileLoader {
100102
}
101103
}
102104

105+
// This is a FileMap identifier that is used to correlate FileMaps between
106+
// subsequent compilation sessions (which is something we need to do during
107+
// incremental compilation).
108+
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
109+
pub struct StableFilemapId(u128);
110+
111+
impl StableFilemapId {
112+
pub fn new(filemap: &FileMap) -> StableFilemapId {
113+
let mut hasher = StableHasher::new();
114+
115+
filemap.name.hash(&mut hasher);
116+
filemap.name_was_remapped.hash(&mut hasher);
117+
filemap.unmapped_path.hash(&mut hasher);
118+
119+
StableFilemapId(hasher.finish())
120+
}
121+
}
122+
103123
// _____________________________________________________________________________
104124
// CodeMap
105125
//
@@ -197,7 +217,7 @@ impl CodeMap {
197217

198218
self.stable_id_to_filemap
199219
.borrow_mut()
200-
.insert(filemap.stable_id, filemap.clone());
220+
.insert(StableFilemapId::new(&filemap), filemap.clone());
201221

202222
filemap
203223
}
@@ -226,7 +246,6 @@ impl CodeMap {
226246
name_was_remapped: bool,
227247
crate_of_origin: u32,
228248
src_hash: u128,
229-
stable_id: StableFilemapId,
230249
source_len: usize,
231250
mut file_local_lines: Vec<BytePos>,
232251
mut file_local_multibyte_chars: Vec<MultiByteChar>,
@@ -257,7 +276,6 @@ impl CodeMap {
257276
crate_of_origin,
258277
src: None,
259278
src_hash,
260-
stable_id,
261279
external_src: RefCell::new(ExternalSource::AbsentOk),
262280
start_pos,
263281
end_pos,
@@ -270,7 +288,7 @@ impl CodeMap {
270288

271289
self.stable_id_to_filemap
272290
.borrow_mut()
273-
.insert(stable_id, filemap.clone());
291+
.insert(StableFilemapId::new(&filemap), filemap.clone());
274292

275293
filemap
276294
}

src/libsyntax_pos/lib.rs

-33
Original file line numberDiff line numberDiff line change
@@ -678,8 +678,6 @@ pub struct FileMap {
678678
pub src: Option<Rc<String>>,
679679
/// The source code's hash
680680
pub src_hash: u128,
681-
/// The stable id used during incr. comp.
682-
pub stable_id: StableFilemapId,
683681
/// The external source code (used for external crates, which will have a `None`
684682
/// value as `self.src`.
685683
pub external_src: RefCell<ExternalSource>,
@@ -695,34 +693,12 @@ pub struct FileMap {
695693
pub non_narrow_chars: RefCell<Vec<NonNarrowChar>>,
696694
}
697695

698-
// This is a FileMap identifier that is used to correlate FileMaps between
699-
// subsequent compilation sessions (which is something we need to do during
700-
// incremental compilation).
701-
#[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Debug)]
702-
pub struct StableFilemapId(pub u128);
703-
704-
impl StableFilemapId {
705-
pub fn new(name: &FileName,
706-
name_was_remapped: bool,
707-
unmapped_path: &FileName)
708-
-> StableFilemapId {
709-
use std::hash::Hash;
710-
711-
let mut hasher = StableHasher::new();
712-
name.hash(&mut hasher);
713-
name_was_remapped.hash(&mut hasher);
714-
unmapped_path.hash(&mut hasher);
715-
StableFilemapId(hasher.finish())
716-
}
717-
}
718-
719696
impl Encodable for FileMap {
720697
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
721698
s.emit_struct("FileMap", 8, |s| {
722699
s.emit_struct_field("name", 0, |s| self.name.encode(s))?;
723700
s.emit_struct_field("name_was_remapped", 1, |s| self.name_was_remapped.encode(s))?;
724701
s.emit_struct_field("src_hash", 2, |s| self.src_hash.encode(s))?;
725-
s.emit_struct_field("stable_id", 3, |s| self.stable_id.encode(s))?;
726702
s.emit_struct_field("start_pos", 4, |s| self.start_pos.encode(s))?;
727703
s.emit_struct_field("end_pos", 5, |s| self.end_pos.encode(s))?;
728704
s.emit_struct_field("lines", 6, |s| {
@@ -790,8 +766,6 @@ impl Decodable for FileMap {
790766
d.read_struct_field("name_was_remapped", 1, |d| Decodable::decode(d))?;
791767
let src_hash: u128 =
792768
d.read_struct_field("src_hash", 2, |d| Decodable::decode(d))?;
793-
let stable_id: StableFilemapId =
794-
d.read_struct_field("stable_id", 3, |d| Decodable::decode(d))?;
795769
let start_pos: BytePos =
796770
d.read_struct_field("start_pos", 4, |d| Decodable::decode(d))?;
797771
let end_pos: BytePos = d.read_struct_field("end_pos", 5, |d| Decodable::decode(d))?;
@@ -839,7 +813,6 @@ impl Decodable for FileMap {
839813
end_pos,
840814
src: None,
841815
src_hash,
842-
stable_id,
843816
external_src: RefCell::new(ExternalSource::AbsentOk),
844817
lines: RefCell::new(lines),
845818
multibyte_chars: RefCell::new(multibyte_chars),
@@ -866,11 +839,6 @@ impl FileMap {
866839
let mut hasher: StableHasher<u128> = StableHasher::new();
867840
hasher.write(src.as_bytes());
868841
let src_hash = hasher.finish();
869-
870-
let stable_id = StableFilemapId::new(&name,
871-
name_was_remapped,
872-
&unmapped_path);
873-
874842
let end_pos = start_pos.to_usize() + src.len();
875843

876844
FileMap {
@@ -880,7 +848,6 @@ impl FileMap {
880848
crate_of_origin: 0,
881849
src: Some(Rc::new(src)),
882850
src_hash,
883-
stable_id,
884851
external_src: RefCell::new(ExternalSource::Unneeded),
885852
start_pos,
886853
end_pos: Pos::from_usize(end_pos),

0 commit comments

Comments
 (0)