@@ -396,7 +396,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
396396 assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
397397 let cache = query. query_cache ( qcx) ;
398398 cache. iter ( & mut |key, value, dep_node| {
399- if query. cache_on_disk ( qcx. tcx , key) {
399+ if query. will_cache_on_disk_for_key ( qcx. tcx , key) {
400400 let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
401401
402402 // Record position of the cache entry.
@@ -445,7 +445,7 @@ where
445445 let key = Q :: Key :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
446446 panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
447447 } ) ;
448- if query. cache_on_disk ( tcx, & key) {
448+ if query. will_cache_on_disk_for_key ( tcx, & key) {
449449 let _ = query. execute_query ( tcx, key) ;
450450 }
451451}
@@ -648,7 +648,11 @@ macro_rules! define_queries {
648648 cycle_error_handling: cycle_error_handling!( [ $( $modifiers) * ] ) ,
649649 query_state: std:: mem:: offset_of!( QueryStates <' tcx>, $name) ,
650650 query_cache: std:: mem:: offset_of!( QueryCaches <' tcx>, $name) ,
651- cache_on_disk: |tcx, key| :: rustc_middle:: query:: cached:: $name( tcx, key) ,
651+ will_cache_on_disk_for_key_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
652+ Some ( :: rustc_middle:: query:: cached:: $name)
653+ } {
654+ None
655+ } ) ,
652656 execute_query: |tcx, key| erase:: erase_val( tcx. $name( key) ) ,
653657 compute: |tcx, key| {
654658 #[ cfg( debug_assertions) ]
@@ -666,37 +670,34 @@ macro_rules! define_queries {
666670 )
667671 )
668672 } ,
669- can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
670- try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
671- |tcx, key, prev_index, index| {
672- if :: rustc_middle:: query:: cached:: $name( tcx, key) {
673- let value = $crate:: plumbing:: try_load_from_disk:: <
674- queries:: $name:: ProvidedValue <' tcx>
675- >(
676- tcx,
677- prev_index,
678- index,
679- ) ;
680- value. map( |value| queries:: $name:: provided_to_erased( tcx, value) )
681- } else {
682- None
673+ try_load_from_disk_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
674+ Some ( |tcx, key, prev_index, index| {
675+ // Check the `cache_on_disk_if` condition for this key.
676+ if !:: rustc_middle:: query:: cached:: $name( tcx, key) {
677+ return None ;
683678 }
684- }
679+
680+ let value: queries:: $name:: ProvidedValue <' tcx> =
681+ $crate:: plumbing:: try_load_from_disk( tcx, prev_index, index) ?;
682+
683+ // Arena-alloc the value if appropriate, and erase it.
684+ Some ( queries:: $name:: provided_to_erased( tcx, value) )
685+ } )
685686 } {
686- |_tcx, _key, _prev_index, _index| None
687+ None
688+ } ) ,
689+ is_loadable_from_disk_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
690+ Some ( |tcx, key, index| -> bool {
691+ :: rustc_middle:: query:: cached:: $name( tcx, key) &&
692+ $crate:: plumbing:: loadable_from_disk( tcx, index)
693+ } )
694+ } {
695+ None
687696 } ) ,
688697 value_from_cycle_error: |tcx, cycle, guar| {
689698 let result: queries:: $name:: Value <' tcx> = Value :: from_cycle_error( tcx, cycle, guar) ;
690699 erase:: erase_val( result)
691700 } ,
692- loadable_from_disk: |_tcx, _key, _index| {
693- should_ever_cache_on_disk!( [ $( $modifiers) * ] {
694- :: rustc_middle:: query:: cached:: $name( _tcx, _key) &&
695- $crate:: plumbing:: loadable_from_disk( _tcx, _index)
696- } {
697- false
698- } )
699- } ,
700701 hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
701702 format_value: |value| format!( "{:?}" , erase:: restore_val:: <queries:: $name:: Value <' tcx>>( * value) ) ,
702703 }
0 commit comments