about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2017-09-14 12:08:03 +0200
committerMichael Woerister <michaelwoerister@posteo>2017-09-18 11:27:41 +0200
commitdd501735ac8eb38756f8a4f4da91b0b7a4fbca1b (patch)
tree651f1d95fa272ddf43371d2125e4b14db7aec13a /src
parent67c84e05e72931587e5f81a297dee95bc149bcd8 (diff)
downloadrust-dd501735ac8eb38756f8a4f4da91b0b7a4fbca1b.tar.gz
rust-dd501735ac8eb38756f8a4f4da91b0b7a4fbca1b.zip
incr.comp.: Initialize the CachingCodemapView in StableHashingContext lazily.
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ich/caching_codemap_view.rs10
-rw-r--r--src/librustc/ich/hcx.rs20
2 files changed, 21 insertions, 9 deletions
diff --git a/src/librustc/ich/caching_codemap_view.rs b/src/librustc/ich/caching_codemap_view.rs
index 49e18f100cf..71e442b3bb2 100644
--- a/src/librustc/ich/caching_codemap_view.rs
+++ b/src/librustc/ich/caching_codemap_view.rs
@@ -11,7 +11,6 @@
 use std::rc::Rc;
 use syntax::codemap::CodeMap;
 use syntax_pos::{BytePos, FileMap};
-use ty::TyCtxt;
 
 #[derive(Clone)]
 struct CacheEntry {
@@ -23,15 +22,14 @@ struct CacheEntry {
     file_index: usize,
 }
 
-pub struct CachingCodemapView<'tcx> {
-    codemap: &'tcx CodeMap,
+pub struct CachingCodemapView<'cm> {
+    codemap: &'cm CodeMap,
     line_cache: [CacheEntry; 3],
     time_stamp: usize,
 }
 
-impl<'gcx> CachingCodemapView<'gcx> {
-    pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CachingCodemapView<'gcx> {
-        let codemap = tcx.sess.codemap();
+impl<'cm> CachingCodemapView<'cm> {
+    pub fn new(codemap: &'cm CodeMap) -> CachingCodemapView<'cm> {
         let files = codemap.files();
         let first_file = files[0].clone();
         let entry = CacheEntry {
diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs
index 0932c5ce8fb..3f9590a45c6 100644
--- a/src/librustc/ich/hcx.rs
+++ b/src/librustc/ich/hcx.rs
@@ -21,6 +21,7 @@ use std::collections::HashMap;
 
 use syntax::ast;
 use syntax::attr;
+use syntax::codemap::CodeMap;
 use syntax::ext::hygiene::SyntaxContext;
 use syntax::symbol::Symbol;
 use syntax_pos::Span;
@@ -36,13 +37,17 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
 /// things (e.g. each DefId/DefPath is only hashed once).
 pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'gcx, 'tcx>,
-    codemap: CachingCodemapView<'gcx>,
     hash_spans: bool,
     hash_bodies: bool,
     overflow_checks_enabled: bool,
     node_id_hashing_mode: NodeIdHashingMode,
     // A sorted array of symbol keys for fast lookup.
     ignored_attr_names: Vec<Symbol>,
+
+    // Very often, we are hashing something that does not need the
+    // CachingCodemapView, so we initialize it lazily.
+    raw_codemap: &'gcx CodeMap,
+    caching_codemap: Option<CachingCodemapView<'gcx>>,
 }
 
 #[derive(PartialEq, Eq, Clone, Copy)]
@@ -66,7 +71,8 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
 
         StableHashingContext {
             tcx,
-            codemap: CachingCodemapView::new(tcx),
+            caching_codemap: None,
+            raw_codemap: tcx.sess.codemap(),
             hash_spans: hash_spans_initial,
             hash_bodies: true,
             overflow_checks_enabled: check_overflow_initial,
@@ -132,7 +138,15 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
 
     #[inline]
     pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
-        &mut self.codemap
+        match self.caching_codemap {
+            Some(ref mut cm) => {
+                cm
+            }
+            ref mut none => {
+                *none = Some(CachingCodemapView::new(self.raw_codemap));
+                none.as_mut().unwrap()
+            }
+        }
     }
 
     #[inline]