@@ -7,7 +7,7 @@ use crate::{on_disk_cache, Queries};
77use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
88use rustc_data_structures:: sync:: Lock ;
99use rustc_errors:: { Diagnostic , Handler } ;
10- use rustc_middle:: dep_graph:: { self , DepKind , DepNodeIndex , SerializedDepNodeIndex } ;
10+ use rustc_middle:: dep_graph:: { self , DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
1111use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
1212use rustc_middle:: ty:: { self , TyCtxt } ;
1313use rustc_query_system:: dep_graph:: HasDepContext ;
@@ -298,6 +298,23 @@ pub(crate) fn create_query_frame<
298298 QueryStackFrame :: new ( name, description, span, def_kind, hash)
299299}
300300
301+ pub ( crate ) fn try_load_from_on_disk_cache < ' tcx , K , V > (
302+ tcx : TyCtxt < ' tcx > ,
303+ dep_node : DepNode ,
304+ recover : fn ( TyCtxt < ' tcx > , DepNode ) -> Option < K > ,
305+ cache_on_disk : fn ( TyCtxt < ' tcx > , & K ) -> bool ,
306+ do_query : fn ( TyCtxt < ' tcx > , K ) -> V ,
307+ ) {
308+ debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
309+
310+ let key = recover ( tcx, dep_node) . unwrap_or_else ( || {
311+ panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
312+ } ) ;
313+ if cache_on_disk ( tcx, & key) {
314+ let _ = do_query ( tcx, key) ;
315+ }
316+ }
317+
301318// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
302319// invoked by `rustc_query_append`.
303320macro_rules! define_queries {
@@ -457,21 +474,12 @@ macro_rules! define_queries {
457474 }
458475 }
459476
460- fn try_load_from_on_disk_cache( tcx: TyCtxt <' _>, dep_node: DepNode ) {
461- debug_assert!( tcx. dep_graph. is_green( & dep_node) ) ;
462-
463- let key = recover( tcx, dep_node) . unwrap_or_else( || panic!( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash) ) ;
464- if queries:: $name:: cache_on_disk( tcx, & key) {
465- let _ = tcx. $name( key) ;
466- }
467- }
468-
469477 DepKindStruct {
470478 is_anon,
471479 is_eval_always,
472480 fingerprint_style,
473481 force_from_dep_node: Some ( force_from_dep_node) ,
474- try_load_from_on_disk_cache: Some ( try_load_from_on_disk_cache) ,
482+ try_load_from_on_disk_cache: Some ( |tcx , key| $crate :: plumbing :: try_load_from_on_disk_cache( tcx , key , recover , queries :: $name :: cache_on_disk , TyCtxt :: $name ) ) ,
475483 }
476484 } ) *
477485 }
0 commit comments