1- use crate :: dep_graph:: { DepNodeIndex , SerializedDepNodeIndex } ;
1+ use crate :: dep_graph:: { DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
22use crate :: mir:: interpret:: { AllocDecodingSession , AllocDecodingState } ;
33use crate :: mir:: { self , interpret} ;
44use crate :: ty:: codec:: { OpaqueEncoder , RefDecodable , TyDecoder , TyEncoder } ;
@@ -264,6 +264,13 @@ impl<'sess> OnDiskCache<'sess> {
264264 ( file_to_file_index, file_index_to_stable_id)
265265 } ;
266266
267+ // Register any dep nodes that we reused from the previous session,
268+ // but didn't `DepNode::construct` in this session. This ensures
269+ // that their `DefPathHash` to `RawDefId` mappings are registered
270+ // in 'latest_foreign_def_path_hashes' if necessary, since that
271+ // normally happens in `DepNode::construct`.
272+ tcx. dep_graph . register_reused_dep_nodes ( tcx) ;
273+
267274 // Load everything into memory so we can write it out to the on-disk
268275 // cache. The vast majority of cacheable query results should already
269276 // be in memory, so this should be a cheap operation.
@@ -467,7 +474,7 @@ impl<'sess> OnDiskCache<'sess> {
467474 . insert ( hash, RawDefId { krate : def_id. krate . as_u32 ( ) , index : def_id. index . as_u32 ( ) } ) ;
468475 }
469476
470- /// If the given `hash` still exists in the current compilation,
477+ /// If the given `dep_node`'s hash still exists in the current compilation,
471478 /// calls `store_foreign_def_id` with its current `DefId`.
472479 ///
473480 /// Normally, `store_foreign_def_id_hash` can be called directly by
@@ -476,13 +483,22 @@ impl<'sess> OnDiskCache<'sess> {
476483 /// session, we only have the `DefPathHash` available. This method is used
477484 /// to that any `DepNode` that we re-use has a `DefPathHash` -> `RawId` written
478485 /// 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) ;
486+ pub fn register_reused_dep_node ( & self , tcx : TyCtxt < ' tcx > , dep_node : & DepNode ) {
487+ // For reused dep nodes, we only need to store the mapping if the node
488+ // is one whose query key we can reconstruct from the hash. We use the
489+ // mapping to aid that reconstruction in the next session. While we also
490+ // use it to decode `DefId`s we encoded in the cache as `DefPathHashes`,
491+ // they're already registered during `DefId` encoding.
492+ if dep_node. kind . can_reconstruct_query_key ( ) {
493+ let hash = DefPathHash ( dep_node. hash . into ( ) ) ;
494+
495+ // We can't simply copy the `RawDefId` from `foreign_def_path_hashes` to
496+ // `latest_foreign_def_path_hashes`, since the `RawDefId` might have
497+ // changed in the current compilation session (e.g. we've added/removed crates,
498+ // or added/removed definitions before/after the target definition).
499+ if let Some ( def_id) = self . def_path_hash_to_def_id ( tcx, hash) {
500+ self . store_foreign_def_id_hash ( def_id, hash) ;
501+ }
486502 }
487503 }
488504
0 commit comments