@@ -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 , OwnerId } ;
65+ use rustc_hir:: { HirId , ItemLocalId , OwnerId } ;
6666use rustc_query_system:: dep_graph:: FingerprintStyle ;
6767use rustc_span:: symbol:: Symbol ;
6868use std:: hash:: Hash ;
@@ -194,7 +194,7 @@ impl DepNodeExt for DepNode {
194194 let kind = dep_kind_from_label_string ( label) ?;
195195
196196 match tcx. fingerprint_style ( kind) {
197- FingerprintStyle :: Opaque => Err ( ( ) ) ,
197+ FingerprintStyle :: Opaque | FingerprintStyle :: HirId => Err ( ( ) ) ,
198198 FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
199199 FingerprintStyle :: DefPathHash => {
200200 Ok ( DepNode :: from_def_path_hash ( tcx, def_path_hash, kind) )
@@ -344,7 +344,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
344344impl < ' tcx > DepNodeParams < TyCtxt < ' tcx > > for HirId {
345345 #[ inline( always) ]
346346 fn fingerprint_style ( ) -> FingerprintStyle {
347- FingerprintStyle :: Opaque
347+ FingerprintStyle :: HirId
348348 }
349349
350350 // We actually would not need to specialize the implementation of this
@@ -353,10 +353,36 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
353353 #[ inline( always) ]
354354 fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint {
355355 let HirId { owner, local_id } = * self ;
356-
357356 let def_path_hash = tcx. def_path_hash ( owner. to_def_id ( ) ) ;
358- let local_id = Fingerprint :: from_smaller_hash ( local_id. as_u32 ( ) . into ( ) ) ;
357+ Fingerprint :: new (
358+ // `owner` is local, so is completely defined by the local hash
359+ def_path_hash. local_hash ( ) ,
360+ local_id. as_u32 ( ) . into ( ) ,
361+ )
362+ }
359363
360- def_path_hash. 0 . combine ( local_id)
364+ #[ inline( always) ]
365+ fn to_debug_str ( & self , tcx : TyCtxt < ' tcx > ) -> String {
366+ let HirId { owner, local_id } = * self ;
367+ format ! ( "{}.{}" , tcx. def_path_str( owner. to_def_id( ) ) , local_id. as_u32( ) )
368+ }
369+
370+ #[ inline( always) ]
371+ fn recover ( tcx : TyCtxt < ' tcx > , dep_node : & DepNode ) -> Option < Self > {
372+ if tcx. fingerprint_style ( dep_node. kind ) == FingerprintStyle :: HirId {
373+ let ( local_hash, local_id) = Fingerprint :: from ( dep_node. hash ) . as_value ( ) ;
374+ let def_path_hash = DefPathHash :: new ( tcx. sess . local_stable_crate_id ( ) , local_hash) ;
375+ let def_id = tcx
376+ . def_path_hash_to_def_id ( def_path_hash, & mut || {
377+ panic ! ( "Failed to extract HirId: {:?} {}" , dep_node. kind, dep_node. hash)
378+ } )
379+ . expect_local ( ) ;
380+ let local_id = local_id
381+ . try_into ( )
382+ . unwrap_or_else ( |_| panic ! ( "local id should be u32, found {:?}" , local_id) ) ;
383+ Some ( HirId { owner : OwnerId { def_id } , local_id : ItemLocalId :: from_u32 ( local_id) } )
384+ } else {
385+ None
386+ }
361387 }
362388}
0 commit comments