Skip to content

Commit dd50173

Browse files
incr.comp.: Initialize the CachingCodemapView in StableHashingContext lazily.
1 parent 67c84e0 commit dd50173

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/librustc/ich/caching_codemap_view.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::rc::Rc;
1212
use syntax::codemap::CodeMap;
1313
use syntax_pos::{BytePos, FileMap};
14-
use ty::TyCtxt;
1514

1615
#[derive(Clone)]
1716
struct CacheEntry {
@@ -23,15 +22,14 @@ struct CacheEntry {
2322
file_index: usize,
2423
}
2524

26-
pub struct CachingCodemapView<'tcx> {
27-
codemap: &'tcx CodeMap,
25+
pub struct CachingCodemapView<'cm> {
26+
codemap: &'cm CodeMap,
2827
line_cache: [CacheEntry; 3],
2928
time_stamp: usize,
3029
}
3130

32-
impl<'gcx> CachingCodemapView<'gcx> {
33-
pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CachingCodemapView<'gcx> {
34-
let codemap = tcx.sess.codemap();
31+
impl<'cm> CachingCodemapView<'cm> {
32+
pub fn new(codemap: &'cm CodeMap) -> CachingCodemapView<'cm> {
3533
let files = codemap.files();
3634
let first_file = files[0].clone();
3735
let entry = CacheEntry {

src/librustc/ich/hcx.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use std::collections::HashMap;
2121

2222
use syntax::ast;
2323
use syntax::attr;
24+
use syntax::codemap::CodeMap;
2425
use syntax::ext::hygiene::SyntaxContext;
2526
use syntax::symbol::Symbol;
2627
use syntax_pos::Span;
@@ -36,13 +37,17 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
3637
/// things (e.g. each DefId/DefPath is only hashed once).
3738
pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
3839
tcx: TyCtxt<'a, 'gcx, 'tcx>,
39-
codemap: CachingCodemapView<'gcx>,
4040
hash_spans: bool,
4141
hash_bodies: bool,
4242
overflow_checks_enabled: bool,
4343
node_id_hashing_mode: NodeIdHashingMode,
4444
// A sorted array of symbol keys for fast lookup.
4545
ignored_attr_names: Vec<Symbol>,
46+
47+
// Very often, we are hashing something that does not need the
48+
// CachingCodemapView, so we initialize it lazily.
49+
raw_codemap: &'gcx CodeMap,
50+
caching_codemap: Option<CachingCodemapView<'gcx>>,
4651
}
4752

4853
#[derive(PartialEq, Eq, Clone, Copy)]
@@ -66,7 +71,8 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
6671

6772
StableHashingContext {
6873
tcx,
69-
codemap: CachingCodemapView::new(tcx),
74+
caching_codemap: None,
75+
raw_codemap: tcx.sess.codemap(),
7076
hash_spans: hash_spans_initial,
7177
hash_bodies: true,
7278
overflow_checks_enabled: check_overflow_initial,
@@ -132,7 +138,15 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
132138

133139
#[inline]
134140
pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
135-
&mut self.codemap
141+
match self.caching_codemap {
142+
Some(ref mut cm) => {
143+
cm
144+
}
145+
ref mut none => {
146+
*none = Some(CachingCodemapView::new(self.raw_codemap));
147+
none.as_mut().unwrap()
148+
}
149+
}
136150
}
137151

138152
#[inline]

0 commit comments

Comments
 (0)