@@ -13,9 +13,10 @@ use hir::def_id::DefId;
13
13
use hir:: map:: DefPathHash ;
14
14
use ich:: { self , CachingCodemapView } ;
15
15
use session:: config:: DebugInfoLevel :: NoDebugInfo ;
16
- use ty:: TyCtxt ;
17
- use util:: nodemap:: { NodeMap , ItemLocalMap } ;
16
+ use ty:: { self , TyCtxt , fast_reject } ;
17
+ use util:: nodemap:: { NodeMap , NodeSet , ItemLocalMap } ;
18
18
19
+ use std:: cmp:: Ord ;
19
20
use std:: hash as std_hash;
20
21
use std:: collections:: { HashMap , HashSet , BTreeMap } ;
21
22
@@ -47,6 +48,7 @@ pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
47
48
#[ derive( PartialEq , Eq , Clone , Copy ) ]
48
49
pub enum NodeIdHashingMode {
49
50
Ignore ,
51
+ CheckedIgnore ,
50
52
HashDefPath ,
51
53
HashTraitsInScope ,
52
54
}
@@ -148,7 +150,7 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
148
150
self . overflow_checks_enabled = true ;
149
151
}
150
152
let prev_hash_node_ids = self . node_id_hashing_mode ;
151
- self . node_id_hashing_mode = NodeIdHashingMode :: Ignore ;
153
+ self . node_id_hashing_mode = NodeIdHashingMode :: CheckedIgnore ;
152
154
153
155
f ( self ) ;
154
156
@@ -202,6 +204,9 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N
202
204
let hir_id = hcx. tcx . hir . node_to_hir_id ( * self ) ;
203
205
match hcx. node_id_hashing_mode {
204
206
NodeIdHashingMode :: Ignore => {
207
+ // Don't do anything.
208
+ }
209
+ NodeIdHashingMode :: CheckedIgnore => {
205
210
// Most NodeIds in the HIR can be ignored, but if there is a
206
211
// corresponding entry in the `trait_map` we need to hash that.
207
212
// Make sure we don't ignore too much by checking that there is
@@ -321,7 +326,7 @@ pub fn hash_stable_hashmap<'a, 'gcx, 'tcx, K, V, R, SK, F, W>(
321
326
let mut keys: Vec < _ > = map. keys ( )
322
327
. map ( |k| ( extract_stable_key ( hcx, k) , k) )
323
328
. collect ( ) ;
324
- keys. sort_unstable_by_key ( |& ( ref stable_key , _) | stable_key . clone ( ) ) ;
329
+ keys. sort_unstable_by ( |& ( ref sk1 , _) , & ( ref sk2 , _ ) | sk1 . cmp ( sk2 ) ) ;
325
330
keys. len ( ) . hash_stable ( hcx, hasher) ;
326
331
for ( stable_key, key) in keys {
327
332
stable_key. hash_stable ( hcx, hasher) ;
@@ -354,8 +359,25 @@ pub fn hash_stable_nodemap<'a, 'tcx, 'gcx, V, W>(
354
359
where V : HashStable < StableHashingContext < ' a , ' gcx , ' tcx > > ,
355
360
W : StableHasherResult ,
356
361
{
357
- hash_stable_hashmap ( hcx, hasher, map, |hcx, node_id| {
358
- hcx. tcx . hir . definitions ( ) . node_to_hir_id ( * node_id) . local_id
362
+ let definitions = hcx. tcx . hir . definitions ( ) ;
363
+ hash_stable_hashmap ( hcx, hasher, map, |_, node_id| {
364
+ let hir_id = definitions. node_to_hir_id ( * node_id) ;
365
+ let owner_def_path_hash = definitions. def_path_hash ( hir_id. owner ) ;
366
+ ( owner_def_path_hash, hir_id. local_id )
367
+ } ) ;
368
+ }
369
+
370
+ pub fn hash_stable_nodeset < ' a , ' tcx , ' gcx , W > (
371
+ hcx : & mut StableHashingContext < ' a , ' gcx , ' tcx > ,
372
+ hasher : & mut StableHasher < W > ,
373
+ map : & NodeSet )
374
+ where W : StableHasherResult ,
375
+ {
376
+ let definitions = hcx. tcx . hir . definitions ( ) ;
377
+ hash_stable_hashset ( hcx, hasher, map, |_, node_id| {
378
+ let hir_id = definitions. node_to_hir_id ( * node_id) ;
379
+ let owner_def_path_hash = definitions. def_path_hash ( hir_id. owner ) ;
380
+ ( owner_def_path_hash, hir_id. local_id )
359
381
} ) ;
360
382
}
361
383
@@ -386,10 +408,56 @@ pub fn hash_stable_btreemap<'a, 'tcx, 'gcx, K, V, SK, F, W>(
386
408
let mut keys: Vec < _ > = map. keys ( )
387
409
. map ( |k| ( extract_stable_key ( hcx, k) , k) )
388
410
. collect ( ) ;
389
- keys. sort_unstable_by_key ( |& ( ref stable_key , _) | stable_key . clone ( ) ) ;
411
+ keys. sort_unstable_by ( |& ( ref sk1 , _) , & ( ref sk2 , _ ) | sk1 . cmp ( sk2 ) ) ;
390
412
keys. len ( ) . hash_stable ( hcx, hasher) ;
391
413
for ( stable_key, key) in keys {
392
414
stable_key. hash_stable ( hcx, hasher) ;
393
415
map[ key] . hash_stable ( hcx, hasher) ;
394
416
}
395
417
}
418
+
419
+ pub fn hash_stable_trait_impls < ' a , ' tcx , ' gcx , W , R > (
420
+ hcx : & mut StableHashingContext < ' a , ' gcx , ' tcx > ,
421
+ hasher : & mut StableHasher < W > ,
422
+ blanket_impls : & Vec < DefId > ,
423
+ non_blanket_impls : & HashMap < fast_reject:: SimplifiedType , Vec < DefId > , R > )
424
+ where W : StableHasherResult ,
425
+ R : std_hash:: BuildHasher ,
426
+ {
427
+ {
428
+ let mut blanket_impls: AccumulateVec < [ _ ; 8 ] > = blanket_impls
429
+ . iter ( )
430
+ . map ( |& def_id| hcx. def_path_hash ( def_id) )
431
+ . collect ( ) ;
432
+
433
+ if blanket_impls. len ( ) > 1 {
434
+ blanket_impls. sort_unstable ( ) ;
435
+ }
436
+
437
+ blanket_impls. hash_stable ( hcx, hasher) ;
438
+ }
439
+
440
+ {
441
+ let tcx = hcx. tcx ( ) ;
442
+ let mut keys: AccumulateVec < [ _ ; 8 ] > =
443
+ non_blanket_impls. keys ( )
444
+ . map ( |k| ( k, k. map_def ( |d| tcx. def_path_hash ( d) ) ) )
445
+ . collect ( ) ;
446
+ keys. sort_unstable_by ( |& ( _, ref k1) , & ( _, ref k2) | k1. cmp ( k2) ) ;
447
+ keys. len ( ) . hash_stable ( hcx, hasher) ;
448
+ for ( key, ref stable_key) in keys {
449
+ stable_key. hash_stable ( hcx, hasher) ;
450
+ let mut impls : AccumulateVec < [ _ ; 8 ] > = non_blanket_impls[ key]
451
+ . iter ( )
452
+ . map ( |& impl_id| hcx. def_path_hash ( impl_id) )
453
+ . collect ( ) ;
454
+
455
+ if impls. len ( ) > 1 {
456
+ impls. sort_unstable ( ) ;
457
+ }
458
+
459
+ impls. hash_stable ( hcx, hasher) ;
460
+ }
461
+ }
462
+ }
463
+
0 commit comments