@@ -35,11 +35,12 @@ use rustc::hir;
35
35
use rustc:: hir:: def_id:: { CRATE_DEF_INDEX , DefId } ;
36
36
use rustc:: hir:: intravisit as visit;
37
37
use rustc:: ty:: TyCtxt ;
38
- use rustc:: util:: nodemap:: DefIdMap ;
39
38
use rustc_data_structures:: fnv:: FnvHashMap ;
40
39
40
+ use self :: def_path_hash:: DefPathHashes ;
41
41
use self :: svh_visitor:: StrictVersionHashVisitor ;
42
42
43
+ mod def_path_hash;
43
44
mod svh_visitor;
44
45
45
46
pub type IncrementalHashesMap = FnvHashMap < DepNode < DefId > , u64 > ;
@@ -50,7 +51,7 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
50
51
let krate = tcx. map . krate ( ) ;
51
52
let mut visitor = HashItemsVisitor { tcx : tcx,
52
53
hashes : FnvHashMap ( ) ,
53
- def_path_hashes : DefIdMap ( ) } ;
54
+ def_path_hashes : DefPathHashes :: new ( tcx ) } ;
54
55
visitor. calculate_def_id ( DefId :: local ( CRATE_DEF_INDEX ) , |v| visit:: walk_crate ( v, krate) ) ;
55
56
krate. visit_all_items ( & mut visitor) ;
56
57
visitor. compute_crate_hash ( ) ;
@@ -59,20 +60,20 @@ pub fn compute_incremental_hashes_map<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
59
60
60
61
struct HashItemsVisitor < ' a , ' tcx : ' a > {
61
62
tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
62
- def_path_hashes : DefIdMap < u64 > ,
63
+ def_path_hashes : DefPathHashes < ' a , ' tcx > ,
63
64
hashes : IncrementalHashesMap ,
64
65
}
65
66
66
67
impl < ' a , ' tcx > HashItemsVisitor < ' a , ' tcx > {
67
68
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 > )
69
70
{
70
71
let def_id = self . tcx . map . local_def_id ( id) ;
71
72
self . calculate_def_id ( def_id, walk_op)
72
73
}
73
74
74
75
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 > )
76
77
{
77
78
assert ! ( def_id. is_local( ) ) ;
78
79
debug ! ( "HashItemsVisitor::calculate(def_id={:?})" , def_id) ;
@@ -99,15 +100,22 @@ impl<'a, 'tcx> HashItemsVisitor<'a, 'tcx> {
99
100
100
101
// add each item (in some deterministic order) to the overall
101
102
// 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.
105
103
{
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) ;
111
119
}
112
120
113
121
for attr in & krate. attrs {
0 commit comments