@@ -454,6 +454,7 @@ impl<'sess> OnDiskCache<'sess> {
454
454
fn try_remap_cnum ( & self , tcx : TyCtxt < ' _ > , cnum : u32 ) -> Option < CrateNum > {
455
455
let cnum_map =
456
456
self . cnum_map . get_or_init ( || Self :: compute_cnum_map ( tcx, & self . prev_cnums [ ..] ) ) ;
457
+ debug ! ( "try_remap_cnum({}): cnum_map={:?}" , cnum, cnum_map) ;
457
458
458
459
cnum_map[ CrateNum :: from_u32 ( cnum) ]
459
460
}
@@ -466,9 +467,22 @@ impl<'sess> OnDiskCache<'sess> {
466
467
. insert ( hash, RawDefId { krate : def_id. krate . as_u32 ( ) , index : def_id. index . as_u32 ( ) } ) ;
467
468
}
468
469
469
- pub fn register_reused_dep_path_hash ( & self , hash : DefPathHash ) {
470
- if let Some ( old_id) = self . foreign_def_path_hashes . get ( & hash) {
471
- self . latest_foreign_def_path_hashes . lock ( ) . insert ( hash, * old_id) ;
470
+ /// If the given `hash` still exists in the current compilation,
471
+ /// calls `store_foreign_def_id` with its current `DefId`.
472
+ ///
473
+ /// Normally, `store_foreign_def_id_hash` can be called directly by
474
+ /// the dependency graph when we construct a `DepNode`. However,
475
+ /// when we re-use a deserialized `DepNode` from the previous compilation
476
+ /// session, we only have the `DefPathHash` available. This method is used
477
+ /// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
478
+ /// out for usage in the next compilation session.
479
+ pub fn register_reused_dep_path_hash ( & self , tcx : TyCtxt < ' tcx > , hash : DefPathHash ) {
480
+ // We can't simply copy the `RawDefId` from `foreign_def_path_hashes` to
481
+ // `latest_foreign_def_path_hashes`, since the `RawDefId` might have
482
+ // changed in the current compilation session (e.g. we've added/removed crates,
483
+ // or added/removed definitions before/after the target definition).
484
+ if let Some ( def_id) = self . def_path_hash_to_def_id ( tcx, hash) {
485
+ self . store_foreign_def_id_hash ( def_id, hash) ;
472
486
}
473
487
}
474
488
@@ -592,6 +606,7 @@ impl<'sess> OnDiskCache<'sess> {
592
606
match cache. entry ( hash) {
593
607
Entry :: Occupied ( e) => * e. get ( ) ,
594
608
Entry :: Vacant ( e) => {
609
+ debug ! ( "def_path_hash_to_def_id({:?})" , hash) ;
595
610
// Check if the `DefPathHash` corresponds to a definition in the current
596
611
// crate
597
612
if let Some ( def_id) = self . local_def_path_hash_to_def_id . get ( & hash) . cloned ( ) {
@@ -605,9 +620,11 @@ impl<'sess> OnDiskCache<'sess> {
605
620
// current compilation session, the crate is guaranteed to be the same
606
621
// (otherwise, we would compute a different `DefPathHash`).
607
622
let raw_def_id = self . get_raw_def_id ( & hash) ?;
623
+ debug ! ( "def_path_hash_to_def_id({:?}): raw_def_id = {:?}" , hash, raw_def_id) ;
608
624
// If the owning crate no longer exists, the corresponding definition definitely
609
625
// no longer exists.
610
626
let krate = self . try_remap_cnum ( tcx, raw_def_id. krate ) ?;
627
+ debug ! ( "def_path_hash_to_def_id({:?}): krate = {:?}" , hash, krate) ;
611
628
// If our `DefPathHash` corresponded to a definition in the local crate,
612
629
// we should have either found it in `local_def_path_hash_to_def_id`, or
613
630
// never attempted to load it in the first place. Any query result or `DepNode`
@@ -621,6 +638,7 @@ impl<'sess> OnDiskCache<'sess> {
621
638
// Try to find a definition in the current session, using the previous `DefIndex`
622
639
// as an initial guess.
623
640
let opt_def_id = tcx. cstore . def_path_hash_to_def_id ( krate, raw_def_id. index , hash) ;
641
+ debug ! ( "def_path_to_def_id({:?}): opt_def_id = {:?}" , hash, opt_def_id) ;
624
642
e. insert ( opt_def_id) ;
625
643
opt_def_id
626
644
}
0 commit comments