@@ -454,6 +454,7 @@ impl<'sess> OnDiskCache<'sess> {
454454 fn try_remap_cnum ( & self , tcx : TyCtxt < ' _ > , cnum : u32 ) -> Option < CrateNum > {
455455 let cnum_map =
456456 self . cnum_map . get_or_init ( || Self :: compute_cnum_map ( tcx, & self . prev_cnums [ ..] ) ) ;
457+ debug ! ( "try_remap_cnum({}): cnum_map={:?}" , cnum, cnum_map) ;
457458
458459 cnum_map[ CrateNum :: from_u32 ( cnum) ]
459460 }
@@ -466,9 +467,22 @@ impl<'sess> OnDiskCache<'sess> {
466467 . insert ( hash, RawDefId { krate : def_id. krate . as_u32 ( ) , index : def_id. index . as_u32 ( ) } ) ;
467468 }
468469
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) ;
472486 }
473487 }
474488
@@ -592,6 +606,7 @@ impl<'sess> OnDiskCache<'sess> {
592606 match cache. entry ( hash) {
593607 Entry :: Occupied ( e) => * e. get ( ) ,
594608 Entry :: Vacant ( e) => {
609+ debug ! ( "def_path_hash_to_def_id({:?})" , hash) ;
595610 // Check if the `DefPathHash` corresponds to a definition in the current
596611 // crate
597612 if let Some ( def_id) = self . local_def_path_hash_to_def_id . get ( & hash) . cloned ( ) {
@@ -605,9 +620,11 @@ impl<'sess> OnDiskCache<'sess> {
605620 // current compilation session, the crate is guaranteed to be the same
606621 // (otherwise, we would compute a different `DefPathHash`).
607622 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) ;
608624 // If the owning crate no longer exists, the corresponding definition definitely
609625 // no longer exists.
610626 let krate = self . try_remap_cnum ( tcx, raw_def_id. krate ) ?;
627+ debug ! ( "def_path_hash_to_def_id({:?}): krate = {:?}" , hash, krate) ;
611628 // If our `DefPathHash` corresponded to a definition in the local crate,
612629 // we should have either found it in `local_def_path_hash_to_def_id`, or
613630 // never attempted to load it in the first place. Any query result or `DepNode`
@@ -621,6 +638,7 @@ impl<'sess> OnDiskCache<'sess> {
621638 // Try to find a definition in the current session, using the previous `DefIndex`
622639 // as an initial guess.
623640 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) ;
624642 e. insert ( opt_def_id) ;
625643 opt_def_id
626644 }
0 commit comments