@@ -7,7 +7,7 @@ use crate::{on_disk_cache, Queries};
7
7
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
8
8
use rustc_data_structures:: sync:: Lock ;
9
9
use 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 } ;
11
11
use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
12
12
use rustc_middle:: ty:: { self , TyCtxt } ;
13
13
use rustc_query_system:: dep_graph:: HasDepContext ;
@@ -298,6 +298,23 @@ pub(crate) fn create_query_frame<
298
298
QueryStackFrame :: new ( name, description, span, def_kind, hash)
299
299
}
300
300
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
+
301
318
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
302
319
// invoked by `rustc_query_append`.
303
320
macro_rules! define_queries {
@@ -457,21 +474,12 @@ macro_rules! define_queries {
457
474
}
458
475
}
459
476
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
-
469
477
DepKindStruct {
470
478
is_anon,
471
479
is_eval_always,
472
480
fingerprint_style,
473
481
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 ) ) ,
475
483
}
476
484
} ) *
477
485
}
0 commit comments