about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-12-14 18:22:55 +0000
committerbors <bors@rust-lang.org>2017-12-14 18:22:55 +0000
commit3fc7f8522bbe59189b6423295a65f337b9735a88 (patch)
tree4f45444154f0da16d64b4c7bb711ac58216ed6ee /src/libsyntax
parent2974104276265858d74733d7ebcca1d3347fd34e (diff)
parent0b4c2cccac30ebcd436e0cfd77b34019c40d4ce3 (diff)
downloadrust-3fc7f8522bbe59189b6423295a65f337b9735a88.tar.gz
rust-3fc7f8522bbe59189b6423295a65f337b9735a88.zip
Auto merge of #46562 - michaelwoerister:faster-span-hashing, r=eddyb
incr.comp.: Speed up span hashing by caching expansion context hashes.

This PR fixes the performance regressions from https://github.com/rust-lang/rust/pull/46338.

r? @nikomatsakis
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/codemap.rs26
1 files changed, 4 insertions, 22 deletions
diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs
index 2c91d60ce9d..07bba29ca4b 100644
--- a/src/libsyntax/codemap.rs
+++ b/src/libsyntax/codemap.rs
@@ -23,9 +23,7 @@ pub use syntax_pos::hygiene::{ExpnFormat, ExpnInfo, NameAndSpan};
 pub use self::ExpnFormat::*;
 
 use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::stable_hasher::StableHasher;
 use std::cell::{RefCell, Ref};
-use std::hash::Hash;
 use std::path::{Path, PathBuf};
 use std::rc::Rc;
 
@@ -102,24 +100,6 @@ 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
 //
@@ -217,7 +197,7 @@ impl CodeMap {
 
         self.stable_id_to_filemap
             .borrow_mut()
-            .insert(StableFilemapId::new(&filemap), filemap.clone());
+            .insert(filemap.stable_id, filemap.clone());
 
         filemap
     }
@@ -246,6 +226,7 @@ impl CodeMap {
                                 name_was_remapped: bool,
                                 crate_of_origin: u32,
                                 src_hash: u128,
+                                stable_id: StableFilemapId,
                                 source_len: usize,
                                 mut file_local_lines: Vec<BytePos>,
                                 mut file_local_multibyte_chars: Vec<MultiByteChar>,
@@ -276,6 +257,7 @@ impl CodeMap {
             crate_of_origin,
             src: None,
             src_hash,
+            stable_id,
             external_src: RefCell::new(ExternalSource::AbsentOk),
             start_pos,
             end_pos,
@@ -288,7 +270,7 @@ impl CodeMap {
 
         self.stable_id_to_filemap
             .borrow_mut()
-            .insert(StableFilemapId::new(&filemap), filemap.clone());
+            .insert(stable_id, filemap.clone());
 
         filemap
     }