@@ -11,10 +11,132 @@ use smallvec::SmallVec;
11
11
use std:: mem;
12
12
use syntax:: attr;
13
13
14
- impl < ' a > HashStable < StableHashingContext < ' a > > for DefId {
14
+ impl < ' ctx > rustc_hir :: HashStableContext for StableHashingContext < ' ctx > {
15
15
#[ inline]
16
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
17
- hcx. def_path_hash ( * self ) . hash_stable ( hcx, hasher) ;
16
+ fn hash_def_id ( & mut self , def_id : DefId , hasher : & mut StableHasher ) {
17
+ let hcx = self ;
18
+ hcx. def_path_hash ( def_id) . hash_stable ( hcx, hasher) ;
19
+ }
20
+
21
+ #[ inline]
22
+ fn hash_hir_id ( & mut self , hir_id : hir:: HirId , hasher : & mut StableHasher ) {
23
+ let hcx = self ;
24
+ match hcx. node_id_hashing_mode {
25
+ NodeIdHashingMode :: Ignore => {
26
+ // Don't do anything.
27
+ }
28
+ NodeIdHashingMode :: HashDefPath => {
29
+ let hir:: HirId { owner, local_id } = hir_id;
30
+
31
+ hcx. local_def_path_hash ( owner) . hash_stable ( hcx, hasher) ;
32
+ local_id. hash_stable ( hcx, hasher) ;
33
+ }
34
+ }
35
+ }
36
+
37
+ fn hash_body_id ( & mut self , id : hir:: BodyId , hasher : & mut StableHasher ) {
38
+ let hcx = self ;
39
+ if hcx. hash_bodies ( ) {
40
+ hcx. body_resolver . body ( id) . hash_stable ( hcx, hasher) ;
41
+ }
42
+ }
43
+
44
+ // The following implementations of HashStable for `ItemId`, `TraitItemId`, and
45
+ // `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
46
+ // the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
47
+ // are used when another item in the HIR is *referenced* and we certainly
48
+ // want to pick up on a reference changing its target, so we hash the NodeIds
49
+ // in "DefPath Mode".
50
+
51
+ fn hash_item_id ( & mut self , id : hir:: ItemId , hasher : & mut StableHasher ) {
52
+ let hcx = self ;
53
+ let hir:: ItemId { id } = id;
54
+
55
+ hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
56
+ id. hash_stable ( hcx, hasher) ;
57
+ } )
58
+ }
59
+
60
+ fn hash_impl_item_id ( & mut self , id : hir:: ImplItemId , hasher : & mut StableHasher ) {
61
+ let hcx = self ;
62
+ let hir:: ImplItemId { hir_id } = id;
63
+
64
+ hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
65
+ hir_id. hash_stable ( hcx, hasher) ;
66
+ } )
67
+ }
68
+
69
+ fn hash_trait_item_id ( & mut self , id : hir:: TraitItemId , hasher : & mut StableHasher ) {
70
+ let hcx = self ;
71
+ let hir:: TraitItemId { hir_id } = id;
72
+
73
+ hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
74
+ hir_id. hash_stable ( hcx, hasher) ;
75
+ } )
76
+ }
77
+
78
+ fn hash_hir_mod ( & mut self , module : & hir:: Mod < ' _ > , hasher : & mut StableHasher ) {
79
+ let hcx = self ;
80
+ let hir:: Mod { inner : ref inner_span, ref item_ids } = * module;
81
+
82
+ inner_span. hash_stable ( hcx, hasher) ;
83
+
84
+ // Combining the `DefPathHash`s directly is faster than feeding them
85
+ // into the hasher. Because we use a commutative combine, we also don't
86
+ // have to sort the array.
87
+ let item_ids_hash = item_ids
88
+ . iter ( )
89
+ . map ( |id| {
90
+ let ( def_path_hash, local_id) = id. id . to_stable_hash_key ( hcx) ;
91
+ debug_assert_eq ! ( local_id, hir:: ItemLocalId :: from_u32( 0 ) ) ;
92
+ def_path_hash. 0
93
+ } )
94
+ . fold ( Fingerprint :: ZERO , |a, b| a. combine_commutative ( b) ) ;
95
+
96
+ item_ids. len ( ) . hash_stable ( hcx, hasher) ;
97
+ item_ids_hash. hash_stable ( hcx, hasher) ;
98
+ }
99
+
100
+ fn hash_hir_expr ( & mut self , expr : & hir:: Expr < ' _ > , hasher : & mut StableHasher ) {
101
+ self . while_hashing_hir_bodies ( true , |hcx| {
102
+ let hir:: Expr { hir_id : _, ref span, ref kind, ref attrs } = * expr;
103
+
104
+ span. hash_stable ( hcx, hasher) ;
105
+ kind. hash_stable ( hcx, hasher) ;
106
+ attrs. hash_stable ( hcx, hasher) ;
107
+ } )
108
+ }
109
+
110
+ fn hash_hir_ty ( & mut self , ty : & hir:: Ty < ' _ > , hasher : & mut StableHasher ) {
111
+ self . while_hashing_hir_bodies ( true , |hcx| {
112
+ let hir:: Ty { hir_id : _, ref kind, ref span } = * ty;
113
+
114
+ kind. hash_stable ( hcx, hasher) ;
115
+ span. hash_stable ( hcx, hasher) ;
116
+ } )
117
+ }
118
+
119
+ fn hash_hir_visibility_kind (
120
+ & mut self ,
121
+ vis : & hir:: VisibilityKind < ' _ > ,
122
+ hasher : & mut StableHasher ,
123
+ ) {
124
+ let hcx = self ;
125
+ mem:: discriminant ( vis) . hash_stable ( hcx, hasher) ;
126
+ match * vis {
127
+ hir:: VisibilityKind :: Public | hir:: VisibilityKind :: Inherited => {
128
+ // No fields to hash.
129
+ }
130
+ hir:: VisibilityKind :: Crate ( sugar) => {
131
+ sugar. hash_stable ( hcx, hasher) ;
132
+ }
133
+ hir:: VisibilityKind :: Restricted { ref path, hir_id } => {
134
+ hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
135
+ hir_id. hash_stable ( hcx, hasher) ;
136
+ } ) ;
137
+ path. hash_stable ( hcx, hasher) ;
138
+ }
139
+ }
18
140
}
19
141
}
20
142
@@ -69,66 +191,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::ItemLocalId {
69
191
}
70
192
}
71
193
72
- // The following implementations of HashStable for `ItemId`, `TraitItemId`, and
73
- // `ImplItemId` deserve special attention. Normally we do not hash `NodeId`s within
74
- // the HIR, since they just signify a HIR nodes own path. But `ItemId` et al
75
- // are used when another item in the HIR is *referenced* and we certainly
76
- // want to pick up on a reference changing its target, so we hash the NodeIds
77
- // in "DefPath Mode".
78
-
79
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: ItemId {
80
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
81
- let hir:: ItemId { id } = * self ;
82
-
83
- hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
84
- id. hash_stable ( hcx, hasher) ;
85
- } )
86
- }
87
- }
88
-
89
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: TraitItemId {
90
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
91
- let hir:: TraitItemId { hir_id } = * self ;
92
-
93
- hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
94
- hir_id. hash_stable ( hcx, hasher) ;
95
- } )
96
- }
97
- }
98
-
99
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: ImplItemId {
100
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
101
- let hir:: ImplItemId { hir_id } = * self ;
102
-
103
- hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
104
- hir_id. hash_stable ( hcx, hasher) ;
105
- } )
106
- }
107
- }
108
-
109
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: Ty < ' _ > {
110
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
111
- hcx. while_hashing_hir_bodies ( true , |hcx| {
112
- let hir:: Ty { hir_id : _, ref kind, ref span } = * self ;
113
-
114
- kind. hash_stable ( hcx, hasher) ;
115
- span. hash_stable ( hcx, hasher) ;
116
- } )
117
- }
118
- }
119
-
120
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: Expr < ' _ > {
121
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
122
- hcx. while_hashing_hir_bodies ( true , |hcx| {
123
- let hir:: Expr { hir_id : _, ref span, ref kind, ref attrs } = * self ;
124
-
125
- span. hash_stable ( hcx, hasher) ;
126
- kind. hash_stable ( hcx, hasher) ;
127
- attrs. hash_stable ( hcx, hasher) ;
128
- } )
129
- }
130
- }
131
-
132
194
impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: TraitItem < ' _ > {
133
195
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
134
196
let hir:: TraitItem { hir_id : _, ident, ref attrs, ref generics, ref kind, span } = * self ;
@@ -168,49 +230,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem<'_> {
168
230
}
169
231
}
170
232
171
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: VisibilityKind < ' _ > {
172
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
173
- mem:: discriminant ( self ) . hash_stable ( hcx, hasher) ;
174
- match * self {
175
- hir:: VisibilityKind :: Public | hir:: VisibilityKind :: Inherited => {
176
- // No fields to hash.
177
- }
178
- hir:: VisibilityKind :: Crate ( sugar) => {
179
- sugar. hash_stable ( hcx, hasher) ;
180
- }
181
- hir:: VisibilityKind :: Restricted { ref path, hir_id } => {
182
- hcx. with_node_id_hashing_mode ( NodeIdHashingMode :: HashDefPath , |hcx| {
183
- hir_id. hash_stable ( hcx, hasher) ;
184
- } ) ;
185
- path. hash_stable ( hcx, hasher) ;
186
- }
187
- }
188
- }
189
- }
190
-
191
- impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: Mod < ' _ > {
192
- fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
193
- let hir:: Mod { inner : ref inner_span, ref item_ids } = * self ;
194
-
195
- inner_span. hash_stable ( hcx, hasher) ;
196
-
197
- // Combining the `DefPathHash`s directly is faster than feeding them
198
- // into the hasher. Because we use a commutative combine, we also don't
199
- // have to sort the array.
200
- let item_ids_hash = item_ids
201
- . iter ( )
202
- . map ( |id| {
203
- let ( def_path_hash, local_id) = id. id . to_stable_hash_key ( hcx) ;
204
- debug_assert_eq ! ( local_id, hir:: ItemLocalId :: from_u32( 0 ) ) ;
205
- def_path_hash. 0
206
- } )
207
- . fold ( Fingerprint :: ZERO , |a, b| a. combine_commutative ( b) ) ;
208
-
209
- item_ids. len ( ) . hash_stable ( hcx, hasher) ;
210
- item_ids_hash. hash_stable ( hcx, hasher) ;
211
- }
212
- }
213
-
214
233
impl < ' a > HashStable < StableHashingContext < ' a > > for hir:: Item < ' _ > {
215
234
fn hash_stable ( & self , hcx : & mut StableHashingContext < ' a > , hasher : & mut StableHasher ) {
216
235
let hir:: Item { ident, ref attrs, hir_id : _, ref kind, ref vis, span } = * self ;
0 commit comments