@@ -62,7 +62,7 @@ use crate::ty::TyCtxt;
62
62
use rustc_data_structures:: fingerprint:: Fingerprint ;
63
63
use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId } ;
64
64
use rustc_hir:: definitions:: DefPathHash ;
65
- use rustc_hir:: HirId ;
65
+ use rustc_hir:: { HirId , ItemLocalId } ;
66
66
use rustc_query_system:: dep_graph:: FingerprintStyle ;
67
67
use rustc_span:: symbol:: Symbol ;
68
68
use std:: hash:: Hash ;
@@ -289,7 +289,7 @@ impl DepNodeExt for DepNode {
289
289
let kind = dep_kind_from_label_string ( label) ?;
290
290
291
291
match kind. fingerprint_style ( tcx) {
292
- FingerprintStyle :: Opaque => Err ( ( ) ) ,
292
+ FingerprintStyle :: Opaque | FingerprintStyle :: HirId => Err ( ( ) ) ,
293
293
FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
294
294
FingerprintStyle :: DefPathHash => {
295
295
Ok ( DepNode :: from_def_path_hash ( tcx, def_path_hash, kind) )
@@ -417,7 +417,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
417
417
impl < ' tcx > DepNodeParams < TyCtxt < ' tcx > > for HirId {
418
418
#[ inline( always) ]
419
419
fn fingerprint_style ( ) -> FingerprintStyle {
420
- FingerprintStyle :: Opaque
420
+ FingerprintStyle :: HirId
421
421
}
422
422
423
423
// We actually would not need to specialize the implementation of this
@@ -426,10 +426,36 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
426
426
#[ inline( always) ]
427
427
fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint {
428
428
let HirId { owner, local_id } = * self ;
429
-
430
429
let def_path_hash = tcx. def_path_hash ( owner. to_def_id ( ) ) ;
431
- let local_id = Fingerprint :: from_smaller_hash ( local_id. as_u32 ( ) . into ( ) ) ;
430
+ Fingerprint :: new (
431
+ // `owner` is local, so is completely defined by the local hash
432
+ def_path_hash. local_hash ( ) ,
433
+ local_id. as_u32 ( ) . into ( ) ,
434
+ )
435
+ }
432
436
433
- def_path_hash. 0 . combine ( local_id)
437
+ #[ inline( always) ]
438
+ fn to_debug_str ( & self , tcx : TyCtxt < ' tcx > ) -> String {
439
+ let HirId { owner, local_id } = * self ;
440
+ format ! ( "{}.{}" , tcx. def_path_str( owner. to_def_id( ) ) , local_id. as_u32( ) )
441
+ }
442
+
443
+ #[ inline( always) ]
444
+ fn recover ( tcx : TyCtxt < ' tcx > , dep_node : & DepNode ) -> Option < Self > {
445
+ if dep_node. kind . fingerprint_style ( tcx) == FingerprintStyle :: HirId {
446
+ let ( local_hash, local_id) = Fingerprint :: from ( dep_node. hash ) . as_value ( ) ;
447
+ let def_path_hash = DefPathHash :: new ( tcx. sess . local_stable_crate_id ( ) , local_hash) ;
448
+ let owner = tcx
449
+ . def_path_hash_to_def_id ( def_path_hash, & mut || {
450
+ panic ! ( "Failed to extract HirId: {:?} {}" , dep_node. kind, dep_node. hash)
451
+ } )
452
+ . expect_local ( ) ;
453
+ let local_id = local_id
454
+ . try_into ( )
455
+ . unwrap_or_else ( |_| panic ! ( "local id should be u32, found {:?}" , local_id) ) ;
456
+ Some ( HirId { owner, local_id : ItemLocalId :: from_u32 ( local_id) } )
457
+ } else {
458
+ None
459
+ }
434
460
}
435
461
}
0 commit comments