@@ -7,14 +7,16 @@ 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 , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
10
+ use rustc_middle:: dep_graph:: {
11
+ self , DepKind , DepKindStruct , DepNode , DepNodeIndex , SerializedDepNodeIndex ,
12
+ } ;
11
13
use rustc_middle:: ty:: tls:: { self , ImplicitCtxt } ;
12
14
use rustc_middle:: ty:: { self , TyCtxt } ;
13
15
use rustc_query_system:: dep_graph:: { DepNodeParams , HasDepContext } ;
14
16
use rustc_query_system:: ich:: StableHashingContext ;
15
17
use rustc_query_system:: query:: {
16
- force_query, QueryContext , QueryDescription , QueryJobId , QueryMap , QuerySideEffects ,
17
- QueryStackFrame ,
18
+ force_query, QueryConfig , QueryContext , QueryDescription , QueryJobId , QueryMap ,
19
+ QuerySideEffects , QueryStackFrame ,
18
20
} ;
19
21
use std:: any:: Any ;
20
22
use std:: num:: NonZeroU64 ;
@@ -303,19 +305,19 @@ pub(crate) fn try_load_from_on_disk_cache<'tcx, K: DepNodeParams<TyCtxt<'tcx>>,
303
305
tcx : TyCtxt < ' tcx > ,
304
306
dep_node : DepNode ,
305
307
cache_on_disk : fn ( TyCtxt < ' tcx > , & K ) -> bool ,
306
- do_query : fn ( TyCtxt < ' tcx > , K ) -> V ,
308
+ cache_query_deps : fn ( TyCtxt < ' tcx > , K ) -> V ,
307
309
) {
308
310
debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
309
311
310
312
let key = K :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
311
313
panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
312
314
} ) ;
313
315
if cache_on_disk ( tcx, & key) {
314
- let _ = do_query ( tcx, key) ;
316
+ let _ = cache_query_deps ( tcx, key) ;
315
317
}
316
318
}
317
319
318
- fn force_from_dep_node < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
320
+ pub ( crate ) fn force_from_dep_node < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
319
321
where
320
322
Q : QueryDescription < QueryCtxt < ' tcx > > ,
321
323
Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
@@ -331,6 +333,39 @@ where
331
333
}
332
334
}
333
335
336
+ pub ( crate ) fn query_callback < ' tcx , Q : QueryConfig > (
337
+ // NOTE: we can't remove these function pointers, because `recover` is invariant -> `try_load_from_on_disk_cache` takes a concrete lifetime, not a universal lifetime.
338
+ // Instead, we infer the correct lifetime at the callsite, so we can pass in a HRTB function pointer to the DepKindStruct.
339
+ try_load_from_on_disk_cache : fn ( TyCtxt < ' _ > , DepNode ) ,
340
+ force_from_dep_node : fn ( TyCtxt < ' _ > , DepNode ) -> bool ,
341
+ is_anon : bool ,
342
+ is_eval_always : bool ,
343
+ ) -> DepKindStruct
344
+ where
345
+ Q : QueryDescription < QueryCtxt < ' tcx > > ,
346
+ Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
347
+ {
348
+ let fingerprint_style = Q :: Key :: fingerprint_style ( ) ;
349
+
350
+ if is_anon || !fingerprint_style. reconstructible ( ) {
351
+ return DepKindStruct {
352
+ is_anon,
353
+ is_eval_always,
354
+ fingerprint_style,
355
+ force_from_dep_node : None ,
356
+ try_load_from_on_disk_cache : None ,
357
+ } ;
358
+ }
359
+
360
+ DepKindStruct {
361
+ is_anon,
362
+ is_eval_always,
363
+ fingerprint_style,
364
+ force_from_dep_node : Some ( force_from_dep_node) ,
365
+ try_load_from_on_disk_cache : Some ( try_load_from_on_disk_cache) ,
366
+ }
367
+ }
368
+
334
369
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
335
370
// invoked by `rustc_query_append`.
336
371
macro_rules! define_queries {
@@ -399,7 +434,6 @@ macro_rules! define_queries {
399
434
#[ allow( nonstandard_style) ]
400
435
mod query_callbacks {
401
436
use super :: * ;
402
- use rustc_query_system:: dep_graph:: DepNodeParams ;
403
437
use rustc_query_system:: query:: QueryDescription ;
404
438
use rustc_query_system:: dep_graph:: FingerprintStyle ;
405
439
@@ -458,29 +492,14 @@ macro_rules! define_queries {
458
492
$( pub ( crate ) fn $name( ) -> DepKindStruct {
459
493
let is_anon = is_anon!( [ $( $modifiers) * ] ) ;
460
494
let is_eval_always = is_eval_always!( [ $( $modifiers) * ] ) ;
495
+ type Q <' tcx> = queries:: $name<' tcx>;
461
496
462
- let fingerprint_style =
463
- <<queries:: $name<' _> as QueryConfig >:: Key as DepNodeParams <TyCtxt <' _>>>:: fingerprint_style( ) ;
464
-
465
- if is_anon || !fingerprint_style. reconstructible( ) {
466
- return DepKindStruct {
467
- is_anon,
468
- is_eval_always,
469
- fingerprint_style,
470
- force_from_dep_node: None ,
471
- try_load_from_on_disk_cache: None ,
472
- }
473
- }
474
-
475
- DepKindStruct {
497
+ $crate:: plumbing:: query_callback:: <Q <' _>>(
498
+ |tcx, key| $crate:: plumbing:: try_load_from_on_disk_cache:: <<Q <' _> as QueryConfig >:: Key , _>( tcx, key, <Q <' _>>:: cache_on_disk, TyCtxt :: $name) ,
499
+ |tcx, key| $crate:: plumbing:: force_from_dep_node:: <Q <' _>>( tcx, key) ,
476
500
is_anon,
477
- is_eval_always,
478
- fingerprint_style,
479
- force_from_dep_node: Some ( |tcx, dep_node| $crate:: plumbing:: force_from_dep_node:: <queries:: $name<' _>>( tcx, dep_node) ) ,
480
- try_load_from_on_disk_cache: Some ( |tcx, key| $crate:: plumbing:: try_load_from_on_disk_cache:: <
481
- <queries:: $name<' _> as QueryConfig >:: Key , _
482
- >( tcx, key, queries:: $name:: cache_on_disk, TyCtxt :: $name) ) ,
483
- }
501
+ is_eval_always
502
+ )
484
503
} ) *
485
504
}
486
505
0 commit comments