3030use syntax:: ast;
3131use std:: cell:: RefCell ;
3232use std:: hash:: { Hash , Hasher } ;
33- use std:: collections:: hash_map:: DefaultHasher ;
3433use rustc:: dep_graph:: DepNode ;
3534use rustc:: hir;
3635use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , DefId } ;
@@ -43,10 +42,12 @@ use rustc::session::config::DebugInfoLevel::NoDebugInfo;
4342use self :: def_path_hash:: DefPathHashes ;
4443use self :: svh_visitor:: StrictVersionHashVisitor ;
4544use self :: caching_codemap_view:: CachingCodemapView ;
45+ use self :: hasher:: IchHasher ;
4646
4747mod def_path_hash;
4848mod svh_visitor;
4949mod caching_codemap_view;
50+ mod hasher;
5051
5152pub struct IncrementalHashesMap {
5253 hashes : FnvHashMap < DepNode < DefId > , u64 > ,
@@ -74,6 +75,10 @@ impl IncrementalHashesMap {
7475 pub fn iter < ' a > ( & ' a self ) -> :: std:: collections:: hash_map:: Iter < ' a , DepNode < DefId > , u64 > {
7576 self . hashes . iter ( )
7677 }
78+
79+ pub fn len ( & self ) -> usize {
80+ self . hashes . len ( )
81+ }
7782}
7883
7984impl < ' a > :: std:: ops:: Index < & ' a DepNode < DefId > > for IncrementalHashesMap {
@@ -102,6 +107,9 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
102107 |v| visit:: walk_crate ( v, krate) ) ;
103108 krate. visit_all_items ( & mut visitor) ;
104109 } ) ;
110+
111+ tcx. sess . perf_stats . incr_comp_hashes_count . set ( visitor. hashes . len ( ) as u64 ) ;
112+
105113 record_time ( & tcx. sess . perf_stats . svh_time , || visitor. compute_crate_hash ( ) ) ;
106114 visitor. hashes
107115}
@@ -127,9 +135,7 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
127135 {
128136 assert ! ( def_id. is_local( ) ) ;
129137 debug ! ( "HashItemsVisitor::calculate(def_id={:?})" , def_id) ;
130- // FIXME: this should use SHA1, not DefaultHasher. DefaultHasher is not
131- // built to avoid collisions.
132- let mut state = DefaultHasher :: new ( ) ;
138+ let mut state = IchHasher :: new ( ) ;
133139 walk_op ( & mut StrictVersionHashVisitor :: new ( & mut state,
134140 self . tcx ,
135141 & mut self . def_path_hashes ,
@@ -138,12 +144,16 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
138144 let item_hash = state. finish ( ) ;
139145 self . hashes . insert ( DepNode :: Hir ( def_id) , item_hash) ;
140146 debug ! ( "calculate_item_hash: def_id={:?} hash={:?}" , def_id, item_hash) ;
147+
148+ let bytes_hashed = self . tcx . sess . perf_stats . incr_comp_bytes_hashed . get ( ) +
149+ state. bytes_hashed ( ) ;
150+ self . tcx . sess . perf_stats . incr_comp_bytes_hashed . set ( bytes_hashed) ;
141151 }
142152
143153 fn compute_crate_hash ( & mut self ) {
144154 let krate = self . tcx . map . krate ( ) ;
145155
146- let mut crate_state = DefaultHasher :: new ( ) ;
156+ let mut crate_state = IchHasher :: new ( ) ;
147157
148158 let crate_disambiguator = self . tcx . sess . local_crate_disambiguator ( ) ;
149159 "crate_disambiguator" . hash ( & mut crate_state) ;
0 commit comments