@@ -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 , OwnerId } ;
65
+ use rustc_hir:: { HirId , ItemLocalId , OwnerId } ;
66
66
use rustc_query_system:: dep_graph:: FingerprintStyle ;
67
67
use rustc_span:: symbol:: Symbol ;
68
68
use std:: hash:: Hash ;
@@ -194,7 +194,7 @@ impl DepNodeExt for DepNode {
194
194
let kind = dep_kind_from_label_string ( label) ?;
195
195
196
196
match tcx. fingerprint_style ( kind) {
197
- FingerprintStyle :: Opaque => Err ( ( ) ) ,
197
+ FingerprintStyle :: Opaque | FingerprintStyle :: HirId => Err ( ( ) ) ,
198
198
FingerprintStyle :: Unit => Ok ( DepNode :: new_no_params ( tcx, kind) ) ,
199
199
FingerprintStyle :: DefPathHash => {
200
200
Ok ( DepNode :: from_def_path_hash ( tcx, def_path_hash, kind) )
@@ -344,7 +344,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
344
344
impl < ' tcx > DepNodeParams < TyCtxt < ' tcx > > for HirId {
345
345
#[ inline( always) ]
346
346
fn fingerprint_style ( ) -> FingerprintStyle {
347
- FingerprintStyle :: Opaque
347
+ FingerprintStyle :: HirId
348
348
}
349
349
350
350
// We actually would not need to specialize the implementation of this
@@ -353,10 +353,36 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
353
353
#[ inline( always) ]
354
354
fn to_fingerprint ( & self , tcx : TyCtxt < ' tcx > ) -> Fingerprint {
355
355
let HirId { owner, local_id } = * self ;
356
-
357
356
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
+ }
359
363
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
+ }
361
387
}
362
388
}
0 commit comments