@@ -63,9 +63,10 @@ fn hash_body(
63
63
def_path_hash : DefPathHash ,
64
64
item_like : impl for < ' a > HashStable < StableHashingContext < ' a > > ,
65
65
hir_body_nodes : & mut Vec < ( DefPathHash , Fingerprint ) > ,
66
- ) {
66
+ ) -> Fingerprint {
67
67
let hash = hash ( hcx, HirItemLike { item_like : & item_like } ) ;
68
68
hir_body_nodes. push ( ( def_path_hash, hash) ) ;
69
+ hash
69
70
}
70
71
71
72
fn upstream_crates ( cstore : & dyn CrateStore ) -> Vec < ( Symbol , Fingerprint , Svh ) > {
@@ -96,7 +97,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
96
97
97
98
let mut hir_body_nodes = Vec :: new ( ) ;
98
99
99
- {
100
+ let hash = {
100
101
let Crate {
101
102
ref item,
102
103
// These fields are handled separately:
@@ -137,6 +138,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
137
138
collector. insert_entry (
138
139
hir:: CRATE_HIR_ID ,
139
140
Entry { parent : hir:: CRATE_HIR_ID , node : Node :: Crate ( & krate. item ) } ,
141
+ hash,
140
142
) ;
141
143
142
144
collector
@@ -197,27 +199,24 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
197
199
( self . owner_map , self . owner_items_map , svh)
198
200
}
199
201
200
- fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > ) {
202
+ fn insert_entry ( & mut self , id : HirId , entry : Entry < ' hir > , hash : Fingerprint ) {
201
203
let i = id. local_id . as_u32 ( ) as usize ;
202
204
203
205
let owner = HirOwner { parent : entry. parent , node : entry. node } ;
204
206
205
207
let arena = self . arena ;
206
- let krate = self . krate ;
207
208
208
209
let items = self . owner_items_map . entry ( id. owner ) . or_insert_with ( || {
209
210
arena. alloc ( HirOwnerItems {
210
- // Insert a dummy node which will be overwritten
211
- // when we call `insert_entry` on the HIR owner.
212
- owner : Node :: Crate ( & krate. item ) ,
211
+ hash,
213
212
items : IndexVec :: new ( ) ,
214
213
bodies : FxHashMap :: default ( ) ,
215
214
} )
216
215
} ) ;
217
216
218
217
if i == 0 {
219
- // Overwrite the dummy node with the real HIR owner.
220
- items. owner = entry . node ;
218
+ // Overwrite the dummy hash with the real HIR owner hash .
219
+ items. hash = hash ;
221
220
222
221
self . owner_map . insert ( id. owner , self . arena . alloc ( owner) ) ;
223
222
// FIXME: feature(impl_trait_in_bindings) broken and trigger this assert
@@ -234,6 +233,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
234
233
}
235
234
236
235
fn insert ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > ) {
236
+ self . insert_with_hash ( span, hir_id, node, Fingerprint :: ZERO )
237
+ }
238
+
239
+ fn insert_with_hash ( & mut self , span : Span , hir_id : HirId , node : Node < ' hir > , hash : Fingerprint ) {
237
240
let entry = Entry { parent : self . parent_node , node } ;
238
241
239
242
// Make sure that the DepNode of some node coincides with the HirId
@@ -269,7 +272,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
269
272
}
270
273
}
271
274
272
- self . insert_entry ( hir_id, entry) ;
275
+ self . insert_entry ( hir_id, entry, hash ) ;
273
276
}
274
277
275
278
fn with_parent < F : FnOnce ( & mut Self ) > ( & mut self , parent_node_id : HirId , f : F ) {
@@ -281,7 +284,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
281
284
282
285
fn with_dep_node_owner <
283
286
T : for < ' b > HashStable < StableHashingContext < ' b > > ,
284
- F : FnOnce ( & mut Self ) ,
287
+ F : FnOnce ( & mut Self , Fingerprint ) ,
285
288
> (
286
289
& mut self ,
287
290
dep_node_owner : DefIndex ,
@@ -292,10 +295,10 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
292
295
293
296
let def_path_hash = self . definitions . def_path_hash ( dep_node_owner) ;
294
297
295
- hash_body ( & mut self . hcx , def_path_hash, item_like, & mut self . hir_body_nodes ) ;
298
+ let hash = hash_body ( & mut self . hcx , def_path_hash, item_like, & mut self . hir_body_nodes ) ;
296
299
297
300
self . current_dep_node_owner = dep_node_owner;
298
- f ( self ) ;
301
+ f ( self , hash ) ;
299
302
self . current_dep_node_owner = prev_owner;
300
303
}
301
304
}
@@ -342,8 +345,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
342
345
i. hir_id. owner,
343
346
self . definitions. opt_def_index( self . hir_to_node_id[ & i. hir_id] ) . unwrap( )
344
347
) ;
345
- self . with_dep_node_owner ( i. hir_id . owner , i, |this| {
346
- this. insert ( i. span , i. hir_id , Node :: Item ( i) ) ;
348
+ self . with_dep_node_owner ( i. hir_id . owner , i, |this, hash | {
349
+ this. insert_with_hash ( i. span , i. hir_id , Node :: Item ( i) , hash ) ;
347
350
this. with_parent ( i. hir_id , |this| {
348
351
if let ItemKind :: Struct ( ref struct_def, _) = i. kind {
349
352
// If this is a tuple or unit-like struct, register the constructor.
@@ -374,8 +377,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
374
377
ti. hir_id. owner,
375
378
self . definitions. opt_def_index( self . hir_to_node_id[ & ti. hir_id] ) . unwrap( )
376
379
) ;
377
- self . with_dep_node_owner ( ti. hir_id . owner , ti, |this| {
378
- this. insert ( ti. span , ti. hir_id , Node :: TraitItem ( ti) ) ;
380
+ self . with_dep_node_owner ( ti. hir_id . owner , ti, |this, hash | {
381
+ this. insert_with_hash ( ti. span , ti. hir_id , Node :: TraitItem ( ti) , hash ) ;
379
382
380
383
this. with_parent ( ti. hir_id , |this| {
381
384
intravisit:: walk_trait_item ( this, ti) ;
@@ -388,8 +391,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
388
391
ii. hir_id. owner,
389
392
self . definitions. opt_def_index( self . hir_to_node_id[ & ii. hir_id] ) . unwrap( )
390
393
) ;
391
- self . with_dep_node_owner ( ii. hir_id . owner , ii, |this| {
392
- this. insert ( ii. span , ii. hir_id , Node :: ImplItem ( ii) ) ;
394
+ self . with_dep_node_owner ( ii. hir_id . owner , ii, |this, hash | {
395
+ this. insert_with_hash ( ii. span , ii. hir_id , Node :: ImplItem ( ii) , hash ) ;
393
396
394
397
this. with_parent ( ii. hir_id , |this| {
395
398
intravisit:: walk_impl_item ( this, ii) ;
@@ -508,8 +511,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
508
511
let node_id = self . hir_to_node_id [ & macro_def. hir_id ] ;
509
512
let def_index = self . definitions . opt_def_index ( node_id) . unwrap ( ) ;
510
513
511
- self . with_dep_node_owner ( def_index, macro_def, |this| {
512
- this. insert ( macro_def. span , macro_def. hir_id , Node :: MacroDef ( macro_def) ) ;
514
+ self . with_dep_node_owner ( def_index, macro_def, |this, hash| {
515
+ this. insert_with_hash (
516
+ macro_def. span ,
517
+ macro_def. hir_id ,
518
+ Node :: MacroDef ( macro_def) ,
519
+ hash,
520
+ ) ;
513
521
} ) ;
514
522
}
515
523
0 commit comments