@@ -35,11 +35,12 @@ use rustc::hir;
3535use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , DefId } ;
3636use rustc:: hir:: intravisit as visit;
3737use rustc:: ty:: TyCtxt ;
38- use rustc:: util:: nodemap:: DefIdMap ;
3938use rustc_data_structures:: fnv:: FnvHashMap ;
4039
40+ use self :: def_path_hash:: DefPathHashes ;
4141use self :: svh_visitor:: StrictVersionHashVisitor ;
4242
43+ mod def_path_hash;
4344mod svh_visitor;
4445
4546pub type IncrementalHashesMap = FnvHashMap < DepNode < DefId > , u64 > ;
@@ -50,7 +51,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
5051 let krate = tcx. map . krate ( ) ;
5152 let mut visitor = HashItemsVisitor { tcx : tcx,
5253 hashes : FnvHashMap ( ) ,
53- def_path_hashes : DefIdMap ( ) } ;
54+ def_path_hashes : DefPathHashes :: new ( tcx ) } ;
5455 visitor. calculate_def_id ( DefId :: local ( CRATE_DEF_INDEX ) , |v| visit:: walk_crate ( v, krate) ) ;
5556 krate. visit_all_items ( & mut visitor) ;
5657 visitor. compute_crate_hash ( ) ;
@@ -59,20 +60,20 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
5960
6061struct HashItemsVisitor < ' a , ' tcx : ' a > {
6162 tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
62- def_path_hashes : DefIdMap < u64 > ,
63+ def_path_hashes : DefPathHashes < ' a , ' tcx > ,
6364 hashes : IncrementalHashesMap ,
6465}
6566
6667impl < ' a , ' tcx > HashItemsVisitor < ' a , ' tcx > {
6768 fn calculate_node_id < W > ( & mut self , id : ast:: NodeId , walk_op : W )
68- where W : for < ' v > FnMut ( & mut StrictVersionHashVisitor < ' v , ' tcx > )
69+ where W : for < ' v > FnMut ( & mut StrictVersionHashVisitor < ' v , ' a , ' tcx > )
6970 {
7071 let def_id = self . tcx . map . local_def_id ( id) ;
7172 self . calculate_def_id ( def_id, walk_op)
7273 }
7374
7475 fn calculate_def_id < W > ( & mut self , def_id : DefId , mut walk_op : W )
75- where W : for < ' v > FnMut ( & mut StrictVersionHashVisitor < ' v , ' tcx > )
76+ where W : for < ' v > FnMut ( & mut StrictVersionHashVisitor < ' v , ' a , ' tcx > )
7677 {
7778 assert ! ( def_id. is_local( ) ) ;
7879 debug ! ( "HashItemsVisitor::calculate(def_id={:?})" , def_id) ;
@@ -99,15 +100,22 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
99100
100101 // add each item (in some deterministic order) to the overall
101102 // crate hash.
102- //
103- // FIXME -- it'd be better to sort by the hash of the def-path,
104- // so that reordering items would not affect the crate hash.
105103 {
106- let mut keys: Vec < _ > = self . hashes . keys ( ) . collect ( ) ;
107- keys. sort ( ) ;
108- for key in keys {
109- self . hashes [ key] . hash ( & mut crate_state) ;
110- }
104+ let def_path_hashes = & mut self . def_path_hashes ;
105+ let mut item_hashes: Vec < _ > =
106+ self . hashes . iter ( )
107+ . map ( |( item_dep_node, & item_hash) | {
108+ // convert from a DepNode<DefId> tp a
109+ // DepNode<u64> where the u64 is the
110+ // hash of the def-id's def-path:
111+ let item_dep_node =
112+ item_dep_node. map_def ( |& did| Some ( def_path_hashes. hash ( did) ) )
113+ . unwrap ( ) ;
114+ ( item_dep_node, item_hash)
115+ } )
116+ . collect ( ) ;
117+ item_hashes. sort ( ) ; // avoid artificial dependencies on item ordering
118+ item_hashes. hash ( & mut crate_state) ;
111119 }
112120
113121 for attr in & krate. attrs {
0 commit comments