@@ -488,66 +488,59 @@ fn load_from_disk_or_invoke_provider_green<'tcx, C: QueryCache>(
488488
489489 debug_assert ! ( dep_graph_data. is_index_green( prev_index) ) ;
490490
491- // First we try to load the result from the on-disk cache.
492- // Some things are never cached on disk.
493- if let Some ( value) = ( query. try_load_from_disk_fn ) ( tcx, key, prev_index, dep_node_index) {
494- if std:: intrinsics:: unlikely ( tcx. sess . opts . unstable_opts . query_dep_graph ) {
495- dep_graph_data. mark_debug_loaded_from_disk ( * dep_node)
491+ // First try to load the result from the on-disk cache. Some things are never cached on disk.
492+ let value;
493+ let verify;
494+ match ( query. try_load_from_disk_fn ) ( tcx, key, prev_index, dep_node_index) {
495+ Some ( loaded_value) => {
496+ if std:: intrinsics:: unlikely ( tcx. sess . opts . unstable_opts . query_dep_graph ) {
497+ dep_graph_data. mark_debug_loaded_from_disk ( * dep_node)
498+ }
499+
500+ value = loaded_value;
501+
502+ let prev_fingerprint = dep_graph_data. prev_value_fingerprint_of ( prev_index) ;
503+ // If `-Zincremental-verify-ich` is specified, re-hash results from
504+ // the cache and make sure that they have the expected fingerprint.
505+ //
506+ // If not, we still seek to verify a subset of fingerprints loaded
507+ // from disk. Re-hashing results is fairly expensive, so we can't
508+ // currently afford to verify every hash. This subset should still
509+ // give us some coverage of potential bugs.
510+ verify = prev_fingerprint. split ( ) . 1 . as_u64 ( ) . is_multiple_of ( 32 )
511+ || tcx. sess . opts . unstable_opts . incremental_verify_ich ;
496512 }
513+ None => {
514+ // We could not load a result from the on-disk cache, so recompute. The dep-graph for
515+ // this computation is already in-place, so we can just call the query provider.
516+ let prof_timer = tcx. prof . query_provider ( ) ;
517+ value = tcx. dep_graph . with_ignore ( || ( query. invoke_provider_fn ) ( tcx, key) ) ;
518+ prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
497519
498- let prev_fingerprint = dep_graph_data. prev_value_fingerprint_of ( prev_index) ;
499- // If `-Zincremental-verify-ich` is specified, re-hash results from
500- // the cache and make sure that they have the expected fingerprint.
501- //
502- // If not, we still seek to verify a subset of fingerprints loaded
503- // from disk. Re-hashing results is fairly expensive, so we can't
504- // currently afford to verify every hash. This subset should still
505- // give us some coverage of potential bugs though.
506- let try_verify = prev_fingerprint. split ( ) . 1 . as_u64 ( ) . is_multiple_of ( 32 ) ;
507- if std:: intrinsics:: unlikely (
508- try_verify || tcx. sess . opts . unstable_opts . incremental_verify_ich ,
509- ) {
510- incremental_verify_ich (
511- tcx,
512- dep_graph_data,
513- & value,
514- prev_index,
515- query. hash_value_fn ,
516- query. format_value ,
517- ) ;
520+ verify = true ;
518521 }
522+ } ;
519523
520- return value;
524+ if verify {
525+ // Verify that re-running the query produced a result with the expected hash.
526+ // This catches bugs in query implementations, turning them into ICEs.
527+ // For example, a query might sort its result by `DefId` - since `DefId`s are
528+ // not stable across compilation sessions, the result could get up getting sorted
529+ // in a different order when the query is re-run, even though all of the inputs
530+ // (e.g. `DefPathHash` values) were green.
531+ //
532+ // See issue #82920 for an example of a miscompilation that would get turned into
533+ // an ICE by this check
534+ incremental_verify_ich (
535+ tcx,
536+ dep_graph_data,
537+ & value,
538+ prev_index,
539+ query. hash_value_fn ,
540+ query. format_value ,
541+ ) ;
521542 }
522543
523- // We could not load a result from the on-disk cache, so
524- // recompute.
525- let prof_timer = tcx. prof . query_provider ( ) ;
526-
527- // The dep-graph for this computation is already in-place.
528- // Call the query provider.
529- let value = tcx. dep_graph . with_ignore ( || ( query. invoke_provider_fn ) ( tcx, key) ) ;
530-
531- prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
532-
533- // Verify that re-running the query produced a result with the expected hash
534- // This catches bugs in query implementations, turning them into ICEs.
535- // For example, a query might sort its result by `DefId` - since `DefId`s are
536- // not stable across compilation sessions, the result could get up getting sorted
537- // in a different order when the query is re-run, even though all of the inputs
538- // (e.g. `DefPathHash` values) were green.
539- //
540- // See issue #82920 for an example of a miscompilation that would get turned into
541- // an ICE by this check
542- incremental_verify_ich (
543- tcx,
544- dep_graph_data,
545- & value,
546- prev_index,
547- query. hash_value_fn ,
548- query. format_value ,
549- ) ;
550-
551544 value
552545}
553546
0 commit comments