@@ -62,7 +62,7 @@ use crate::ty::TyCtxt;
6262use rustc_data_structures:: fingerprint:: Fingerprint ;
6363use rustc_hir:: def_id:: { CrateNum , DefId , LocalDefId } ;
6464use rustc_hir:: definitions:: DefPathHash ;
65- use rustc_hir:: HirId ;
65+ use rustc_hir:: { HirId , ItemLocalId } ;
6666use rustc_query_system:: dep_graph:: FingerprintStyle ;
6767use rustc_span:: symbol:: Symbol ;
6868use std:: hash:: Hash ;
@@ -289,7 +289,7 @@ impl DepNodeExt for DepNode {
289289 let kind = dep_kind_from_label_string ( label) ?;
290290
291291 match kind. fingerprint_style ( tcx) {
292- FingerprintStyle :: Opaque => Err ( ( ) ) ,
292+ FingerprintStyle :: Opaque | FingerprintStyle :: HirId => Err ( ( ) ) ,
293293 FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
294294 FingerprintStyle :: DefPathHash => {
295295 Ok ( DepNode :: from_def_path_hash ( tcx, def_path_hash, kind) )
@@ -417,7 +417,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
417417impl < ' tcx > DepNodeParams < TyCtxt < ' tcx > > for HirId {
418418 #[ inline( always) ]
419419 fn fingerprint_style ( ) -> FingerprintStyle {
420- FingerprintStyle :: Opaque
420+ FingerprintStyle :: HirId
421421 }
422422
423423 // We actually would not need to specialize the implementation of this
@@ -426,10 +426,36 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
426426 #[ inline( always) ]
427427 fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint {
428428 let HirId { owner, local_id } = * self ;
429-
430429 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+ }
432436
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+ }
434460 }
435461}
0 commit comments