Skip to content

Commit f923083

Browse files
committed
cache def-path hashes across all items
This seems like approx a 2x win on syntex_syntax.
1 parent 484da37 commit f923083

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/librustc_incremental/calculate_svh/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ use rustc::hir;
3535
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
3636
use rustc::hir::intravisit as visit;
3737
use rustc::ty::TyCtxt;
38+
use rustc::util::nodemap::DefIdMap;
3839
use rustc_data_structures::fnv::FnvHashMap;
3940

4041
use self::svh_visitor::StrictVersionHashVisitor;
@@ -47,7 +48,9 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
4748
-> IncrementalHashesMap {
4849
let _ignore = tcx.dep_graph.in_ignore();
4950
let krate = tcx.map.krate();
50-
let mut visitor = HashItemsVisitor { tcx: tcx, hashes: FnvHashMap() };
51+
let mut visitor = HashItemsVisitor { tcx: tcx,
52+
hashes: FnvHashMap(),
53+
def_path_hashes: DefIdMap() };
5154
visitor.calculate_def_id(DefId::local(CRATE_DEF_INDEX), |v| visit::walk_crate(v, krate));
5255
krate.visit_all_items(&mut visitor);
5356
visitor.compute_crate_hash();
@@ -56,6 +59,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
5659

5760
struct HashItemsVisitor<'a, 'tcx: 'a> {
5861
tcx: TyCtxt<'a, 'tcx, 'tcx>,
62+
def_path_hashes: DefIdMap<u64>,
5963
hashes: IncrementalHashesMap,
6064
}
6165

@@ -75,7 +79,9 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
7579
// FIXME: this should use SHA1, not SipHash. SipHash is not
7680
// built to avoid collisions.
7781
let mut state = SipHasher::new();
78-
walk_op(&mut StrictVersionHashVisitor::new(&mut state, self.tcx));
82+
walk_op(&mut StrictVersionHashVisitor::new(&mut state,
83+
self.tcx,
84+
&mut self.def_path_hashes));
7985
let item_hash = state.finish();
8086
self.hashes.insert(DepNode::Hir(def_id), item_hash);
8187
debug!("calculate_item_hash: def_id={:?} hash={:?}", def_id, item_hash);

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,24 @@ pub struct StrictVersionHashVisitor<'a, 'tcx: 'a> {
3535
pub st: &'a mut SipHasher,
3636

3737
// collect a deterministic hash of def-ids that we have seen
38-
def_id_hashes: DefIdMap<u64>,
38+
def_path_hashes: &'a mut DefIdMap<u64>,
3939
}
4040

4141
impl<'a, 'tcx> StrictVersionHashVisitor<'a, 'tcx> {
4242
pub fn new(st: &'a mut SipHasher,
43-
tcx: TyCtxt<'a, 'tcx, 'tcx>)
43+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
44+
def_path_hashes: &'a mut DefIdMap<u64>)
4445
-> Self {
45-
StrictVersionHashVisitor { st: st, tcx: tcx, def_id_hashes: DefIdMap() }
46+
StrictVersionHashVisitor { st: st, tcx: tcx, def_path_hashes: def_path_hashes }
4647
}
4748

4849
fn compute_def_id_hash(&mut self, def_id: DefId) -> u64 {
4950
let tcx = self.tcx;
50-
*self.def_id_hashes.entry(def_id)
51-
.or_insert_with(|| {
52-
let def_path = tcx.def_path(def_id);
53-
def_path.deterministic_hash(tcx)
54-
})
51+
*self.def_path_hashes.entry(def_id)
52+
.or_insert_with(|| {
53+
let def_path = tcx.def_path(def_id);
54+
def_path.deterministic_hash(tcx)
55+
})
5556
}
5657
}
5758

0 commit comments

Comments
 (0)