@@ -400,7 +400,7 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
400400 assert ! ( query. query_state( qcx) . all_inactive( ) ) ;
401401 let cache = query. query_cache ( qcx) ;
402402 cache. iter ( & mut |key, value, dep_node| {
403- if query. cache_on_disk ( qcx. tcx , key) {
403+ if query. will_cache_on_disk_for_key ( qcx. tcx , key) {
404404 let dep_node = SerializedDepNodeIndex :: new ( dep_node. index ( ) ) ;
405405
406406 // Record position of the cache entry.
@@ -449,7 +449,7 @@ where
449449 let key = Q :: Key :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
450450 panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
451451 } ) ;
452- if query. cache_on_disk ( tcx, & key) {
452+ if query. will_cache_on_disk_for_key ( tcx, & key) {
453453 let _ = query. execute_query ( tcx, key) ;
454454 }
455455}
@@ -651,7 +651,11 @@ macro_rules! define_queries {
651651 cycle_error_handling: cycle_error_handling!( [ $( $modifiers) * ] ) ,
652652 query_state: std:: mem:: offset_of!( QueryStates <' tcx>, $name) ,
653653 query_cache: std:: mem:: offset_of!( QueryCaches <' tcx>, $name) ,
654- cache_on_disk: |tcx, key| :: rustc_middle:: query:: cached:: $name( tcx, key) ,
654+ will_cache_on_disk_for_key_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
655+ Some ( :: rustc_middle:: query:: cached:: $name)
656+ } {
657+ None
658+ } ) ,
655659 execute_query: |tcx, key| erase( tcx. $name( key) ) ,
656660 compute: |tcx, key| {
657661 #[ cfg( debug_assertions) ]
@@ -669,37 +673,34 @@ macro_rules! define_queries {
669673 )
670674 )
671675 } ,
672- can_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] true false ) ,
673- try_load_from_disk: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
674- |tcx, key, prev_index, index| {
675- if :: rustc_middle:: query:: cached:: $name( tcx, key) {
676- let value = $crate:: plumbing:: try_load_from_disk:: <
677- queries:: $name:: ProvidedValue <' tcx>
678- >(
679- tcx,
680- prev_index,
681- index,
682- ) ;
683- value. map( |value| queries:: $name:: provided_to_erased( tcx, value) )
684- } else {
685- None
676+ try_load_from_disk_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
677+ Some ( |tcx, key, prev_index, index| {
678+ // Check the `cache_on_disk_if` condition for this key.
679+ if !:: rustc_middle:: query:: cached:: $name( tcx, key) {
680+ return None ;
686681 }
687- }
682+
683+ let value: queries:: $name:: ProvidedValue <' tcx> =
684+ $crate:: plumbing:: try_load_from_disk( tcx, prev_index, index) ?;
685+
686+ // Arena-alloc the value if appropriate, and erase it.
687+ Some ( queries:: $name:: provided_to_erased( tcx, value) )
688+ } )
688689 } {
689- |_tcx, _key, _prev_index, _index| None
690+ None
691+ } ) ,
692+ is_loadable_from_disk_fn: should_ever_cache_on_disk!( [ $( $modifiers) * ] {
693+ Some ( |tcx, key, index| -> bool {
694+ :: rustc_middle:: query:: cached:: $name( tcx, key) &&
695+ $crate:: plumbing:: loadable_from_disk( tcx, index)
696+ } )
697+ } {
698+ None
690699 } ) ,
691700 value_from_cycle_error: |tcx, cycle, guar| {
692701 let result: queries:: $name:: Value <' tcx> = Value :: from_cycle_error( tcx, cycle, guar) ;
693702 erase( result)
694703 } ,
695- loadable_from_disk: |_tcx, _key, _index| {
696- should_ever_cache_on_disk!( [ $( $modifiers) * ] {
697- :: rustc_middle:: query:: cached:: $name( _tcx, _key) &&
698- $crate:: plumbing:: loadable_from_disk( _tcx, _index)
699- } {
700- false
701- } )
702- } ,
703704 hash_result: hash_result!( [ $( $modifiers) * ] [ queries:: $name:: Value <' tcx>] ) ,
704705 format_value: |value| format!( "{:?}" , restore:: <queries:: $name:: Value <' tcx>>( * value) ) ,
705706 }
0 commit comments