22//! generate the actual methods on tcx which find and execute the provider,
33//! manage the caches, and so forth.
44
5- use crate :: dep_graph:: HasDepContext ;
5+ use crate :: dep_graph:: { HasDepContext , SerializedDepNodeIndex } ;
66use crate :: dep_graph:: { DepContext , DepKind , DepNode , DepNodeIndex , DepNodeParams } ;
77use crate :: ich:: StableHashingContext ;
88use crate :: query:: caches:: QueryCache ;
@@ -492,6 +492,62 @@ where
492492 ( result, dep_node_index)
493493}
494494
495+ #[ inline( always) ]
496+ fn load_from_disk_and_cache_in_memory < V , Qcx > (
497+ qcx : Qcx ,
498+ dep_node : & DepNode < Qcx :: DepKind > ,
499+ prev_dep_node_index : SerializedDepNodeIndex ,
500+ dep_node_index : DepNodeIndex ,
501+ try_load_from_disk : fn ( Qcx , SerializedDepNodeIndex ) -> Option < V > ,
502+ hash_result : Option < fn ( & mut StableHashingContext < ' _ > , & V ) -> Fingerprint > ,
503+ ) -> Option < ( V , DepNodeIndex ) >
504+ where
505+ V : Debug ,
506+ Qcx : QueryContext ,
507+ {
508+ let dep_graph = qcx. dep_context ( ) . dep_graph ( ) ;
509+ let prof_timer = qcx. dep_context ( ) . profiler ( ) . incr_cache_loading ( ) ;
510+
511+ // The call to `with_query_deserialization` enforces that no new `DepNodes`
512+ // are created during deserialization. See the docs of that method for more
513+ // details.
514+ let result =
515+ dep_graph. with_query_deserialization ( || try_load_from_disk ( qcx, prev_dep_node_index) ) ;
516+
517+ prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
518+
519+ if let Some ( result) = result {
520+ if std:: intrinsics:: unlikely (
521+ qcx. dep_context ( ) . sess ( ) . opts . unstable_opts . query_dep_graph ,
522+ ) {
523+ dep_graph. mark_debug_loaded_from_disk ( * dep_node)
524+ }
525+
526+ let prev_fingerprint = qcx
527+ . dep_context ( )
528+ . dep_graph ( )
529+ . prev_fingerprint_of ( dep_node)
530+ . unwrap_or ( Fingerprint :: ZERO ) ;
531+ // If `-Zincremental-verify-ich` is specified, re-hash results from
532+ // the cache and make sure that they have the expected fingerprint.
533+ //
534+ // If not, we still seek to verify a subset of fingerprints loaded
535+ // from disk. Re-hashing results is fairly expensive, so we can't
536+ // currently afford to verify every hash. This subset should still
537+ // give us some coverage of potential bugs though.
538+ let try_verify = prev_fingerprint. as_value ( ) . 1 % 32 == 0 ;
539+ if std:: intrinsics:: unlikely (
540+ try_verify || qcx. dep_context ( ) . sess ( ) . opts . unstable_opts . incremental_verify_ich ,
541+ ) {
542+ incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, hash_result) ;
543+ }
544+
545+ Some ( ( result, dep_node_index) )
546+ } else {
547+ None
548+ }
549+ }
550+
495551#[ inline( always) ]
496552fn try_load_from_disk_and_cache_in_memory < Q , Qcx > (
497553 query : Q ,
@@ -514,51 +570,16 @@ where
514570 // First we try to load the result from the on-disk cache.
515571 // Some things are never cached on disk.
516572 if let Some ( try_load_from_disk) = query. try_load_from_disk ( qcx, & key) {
517- let prof_timer = qcx. dep_context ( ) . profiler ( ) . incr_cache_loading ( ) ;
518-
519- // The call to `with_query_deserialization` enforces that no new `DepNodes`
520- // are created during deserialization. See the docs of that method for more
521- // details.
522- let result =
523- dep_graph. with_query_deserialization ( || try_load_from_disk ( qcx, prev_dep_node_index) ) ;
524-
525- prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
526-
527- if let Some ( result) = result {
528- if std:: intrinsics:: unlikely (
529- qcx. dep_context ( ) . sess ( ) . opts . unstable_opts . query_dep_graph ,
530- ) {
531- dep_graph. mark_debug_loaded_from_disk ( * dep_node)
532- }
533-
534- let prev_fingerprint = qcx
535- . dep_context ( )
536- . dep_graph ( )
537- . prev_fingerprint_of ( dep_node)
538- . unwrap_or ( Fingerprint :: ZERO ) ;
539- // If `-Zincremental-verify-ich` is specified, re-hash results from
540- // the cache and make sure that they have the expected fingerprint.
541- //
542- // If not, we still seek to verify a subset of fingerprints loaded
543- // from disk. Re-hashing results is fairly expensive, so we can't
544- // currently afford to verify every hash. This subset should still
545- // give us some coverage of potential bugs though.
546- let try_verify = prev_fingerprint. as_value ( ) . 1 % 32 == 0 ;
547- if std:: intrinsics:: unlikely (
548- try_verify || qcx. dep_context ( ) . sess ( ) . opts . unstable_opts . incremental_verify_ich ,
549- ) {
550- incremental_verify_ich ( * qcx. dep_context ( ) , & result, dep_node, query. hash_result ( ) ) ;
551- }
552-
553- return Some ( ( result, dep_node_index) ) ;
573+ if let Some ( value) = load_from_disk_and_cache_in_memory :: < Q :: Value , Qcx > (
574+ qcx,
575+ dep_node,
576+ prev_dep_node_index,
577+ dep_node_index,
578+ try_load_from_disk,
579+ query. hash_result ( ) ,
580+ ) {
581+ return Some ( value) ;
554582 }
555-
556- // We always expect to find a cached result for things that
557- // can be forced from `DepNode`.
558- debug_assert ! (
559- !qcx. dep_context( ) . fingerprint_style( dep_node. kind) . reconstructible( ) ,
560- "missing on-disk cache entry for {dep_node:?}"
561- ) ;
562583 }
563584
564585 // We could not load a result from the on-disk cache, so
0 commit comments