@@ -7,13 +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 , 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
- use rustc_query_system:: dep_graph:: HasDepContext ;
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
- QueryContext , QueryJobId , QueryMap , QuerySideEffects , QueryStackFrame ,
18
+ force_query, QueryConfig , QueryContext , QueryDescription , QueryJobId , QueryMap ,
19
+ QuerySideEffects , QueryStackFrame ,
17
20
} ;
18
21
use std:: any:: Any ;
19
22
use std:: num:: NonZeroU64 ;
@@ -298,6 +301,66 @@ pub(crate) fn create_query_frame<
298
301
QueryStackFrame :: new ( name, description, span, def_kind, hash)
299
302
}
300
303
304
+ fn try_load_from_on_disk_cache < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode )
305
+ where
306
+ Q : QueryDescription < QueryCtxt < ' tcx > > ,
307
+ Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
308
+ {
309
+ debug_assert ! ( tcx. dep_graph. is_green( & dep_node) ) ;
310
+
311
+ let key = Q :: Key :: recover ( tcx, & dep_node) . unwrap_or_else ( || {
312
+ panic ! ( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash)
313
+ } ) ;
314
+ if Q :: cache_on_disk ( tcx, & key) {
315
+ let _ = Q :: execute_query ( tcx, key) ;
316
+ }
317
+ }
318
+
319
+ fn force_from_dep_node < ' tcx , Q > ( tcx : TyCtxt < ' tcx > , dep_node : DepNode ) -> bool
320
+ where
321
+ Q : QueryDescription < QueryCtxt < ' tcx > > ,
322
+ Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
323
+ {
324
+ if let Some ( key) = Q :: Key :: recover ( tcx, & dep_node) {
325
+ #[ cfg( debug_assertions) ]
326
+ let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered ( ) ;
327
+ let tcx = QueryCtxt :: from_tcx ( tcx) ;
328
+ force_query :: < Q , _ > ( tcx, key, dep_node) ;
329
+ true
330
+ } else {
331
+ false
332
+ }
333
+ }
334
+
335
+ pub ( crate ) fn query_callback < ' tcx , Q : QueryConfig > (
336
+ is_anon : bool ,
337
+ is_eval_always : bool ,
338
+ ) -> DepKindStruct < ' tcx >
339
+ where
340
+ Q : QueryDescription < QueryCtxt < ' tcx > > ,
341
+ Q :: Key : DepNodeParams < TyCtxt < ' tcx > > ,
342
+ {
343
+ let fingerprint_style = Q :: Key :: fingerprint_style ( ) ;
344
+
345
+ if is_anon || !fingerprint_style. reconstructible ( ) {
346
+ return DepKindStruct {
347
+ is_anon,
348
+ is_eval_always,
349
+ fingerprint_style,
350
+ force_from_dep_node : None ,
351
+ try_load_from_on_disk_cache : None ,
352
+ } ;
353
+ }
354
+
355
+ DepKindStruct {
356
+ is_anon,
357
+ is_eval_always,
358
+ fingerprint_style,
359
+ force_from_dep_node : Some ( force_from_dep_node :: < Q > ) ,
360
+ try_load_from_on_disk_cache : Some ( try_load_from_on_disk_cache :: < Q > ) ,
361
+ }
362
+ }
363
+
301
364
// NOTE: `$V` isn't used here, but we still need to match on it so it can be passed to other macros
302
365
// invoked by `rustc_query_append`.
303
366
macro_rules! define_queries {
@@ -308,18 +371,6 @@ macro_rules! define_queries {
308
371
input: ( $( ( [ $( $modifiers) * ] [ $( $attr) * ] [ $name] ) ) * )
309
372
}
310
373
311
- mod make_query {
312
- use super :: * ;
313
-
314
- // Create an eponymous constructor for each query.
315
- $( #[ allow( nonstandard_style) ] $( #[ $attr] ) *
316
- pub fn $name<' tcx>( tcx: QueryCtxt <' tcx>, key: <queries:: $name<' tcx> as QueryConfig >:: Key ) -> QueryStackFrame {
317
- let kind = dep_graph:: DepKind :: $name;
318
- let name = stringify!( $name) ;
319
- $crate:: plumbing:: create_query_frame( tcx, queries:: $name:: describe, key, kind, name)
320
- } ) *
321
- }
322
-
323
374
#[ allow( nonstandard_style) ]
324
375
mod queries {
325
376
use std:: marker:: PhantomData ;
@@ -373,18 +424,19 @@ macro_rules! define_queries {
373
424
try_load_from_disk: Self :: TRY_LOAD_FROM_DISK ,
374
425
}
375
426
}
427
+
428
+ fn execute_query( tcx: TyCtxt <' tcx>, k: Self :: Key ) -> Self :: Stored {
429
+ tcx. $name( k)
430
+ }
376
431
} ) *
377
432
378
433
#[ allow( nonstandard_style) ]
379
434
mod query_callbacks {
380
435
use super :: * ;
381
- use rustc_middle:: dep_graph:: DepNode ;
382
- use rustc_query_system:: dep_graph:: DepNodeParams ;
383
- use rustc_query_system:: query:: { force_query, QueryDescription } ;
384
436
use rustc_query_system:: dep_graph:: FingerprintStyle ;
385
437
386
438
// We use this for most things when incr. comp. is turned off.
387
- pub fn Null ( ) -> DepKindStruct {
439
+ pub fn Null < ' tcx> ( ) -> DepKindStruct < ' tcx> {
388
440
DepKindStruct {
389
441
is_anon: false ,
390
442
is_eval_always: false ,
@@ -395,7 +447,7 @@ macro_rules! define_queries {
395
447
}
396
448
397
449
// We use this for the forever-red node.
398
- pub fn Red ( ) -> DepKindStruct {
450
+ pub fn Red < ' tcx> ( ) -> DepKindStruct < ' tcx> {
399
451
DepKindStruct {
400
452
is_anon: false ,
401
453
is_eval_always: false ,
@@ -405,7 +457,7 @@ macro_rules! define_queries {
405
457
}
406
458
}
407
459
408
- pub fn TraitSelect ( ) -> DepKindStruct {
460
+ pub fn TraitSelect < ' tcx> ( ) -> DepKindStruct < ' tcx> {
409
461
DepKindStruct {
410
462
is_anon: true ,
411
463
is_eval_always: false ,
@@ -415,7 +467,7 @@ macro_rules! define_queries {
415
467
}
416
468
}
417
469
418
- pub fn CompileCodegenUnit ( ) -> DepKindStruct {
470
+ pub fn CompileCodegenUnit < ' tcx> ( ) -> DepKindStruct < ' tcx> {
419
471
DepKindStruct {
420
472
is_anon: false ,
421
473
is_eval_always: false ,
@@ -425,7 +477,7 @@ macro_rules! define_queries {
425
477
}
426
478
}
427
479
428
- pub fn CompileMonoItem ( ) -> DepKindStruct {
480
+ pub fn CompileMonoItem < ' tcx> ( ) -> DepKindStruct < ' tcx> {
429
481
DepKindStruct {
430
482
is_anon: false ,
431
483
is_eval_always: false ,
@@ -435,60 +487,15 @@ macro_rules! define_queries {
435
487
}
436
488
}
437
489
438
- $( pub ( crate ) fn $name( ) -> DepKindStruct {
439
- let is_anon = is_anon!( [ $( $modifiers) * ] ) ;
440
- let is_eval_always = is_eval_always!( [ $( $modifiers) * ] ) ;
441
-
442
- let fingerprint_style =
443
- <<queries:: $name<' _> as QueryConfig >:: Key as DepNodeParams <TyCtxt <' _>>>:: fingerprint_style( ) ;
444
-
445
- if is_anon || !fingerprint_style. reconstructible( ) {
446
- return DepKindStruct {
447
- is_anon,
448
- is_eval_always,
449
- fingerprint_style,
450
- force_from_dep_node: None ,
451
- try_load_from_on_disk_cache: None ,
452
- }
453
- }
454
-
455
- #[ inline( always) ]
456
- fn recover<' tcx>( tcx: TyCtxt <' tcx>, dep_node: DepNode ) -> Option <<queries:: $name<' tcx> as QueryConfig >:: Key > {
457
- <<queries:: $name<' _> as QueryConfig >:: Key as DepNodeParams <TyCtxt <' _>>>:: recover( tcx, & dep_node)
458
- }
459
-
460
- fn force_from_dep_node( tcx: TyCtxt <' _>, dep_node: DepNode ) -> bool {
461
- if let Some ( key) = recover( tcx, dep_node) {
462
- #[ cfg( debug_assertions) ]
463
- let _guard = tracing:: span!( tracing:: Level :: TRACE , stringify!( $name) , ?key) . entered( ) ;
464
- let tcx = QueryCtxt :: from_tcx( tcx) ;
465
- force_query:: <queries:: $name<' _>, _>( tcx, key, dep_node) ;
466
- true
467
- } else {
468
- false
469
- }
470
- }
471
-
472
- fn try_load_from_on_disk_cache( tcx: TyCtxt <' _>, dep_node: DepNode ) {
473
- debug_assert!( tcx. dep_graph. is_green( & dep_node) ) ;
474
-
475
- let key = recover( tcx, dep_node) . unwrap_or_else( || panic!( "Failed to recover key for {:?} with hash {}" , dep_node, dep_node. hash) ) ;
476
- if queries:: $name:: cache_on_disk( tcx, & key) {
477
- let _ = tcx. $name( key) ;
478
- }
479
- }
480
-
481
- DepKindStruct {
482
- is_anon,
483
- is_eval_always,
484
- fingerprint_style,
485
- force_from_dep_node: Some ( force_from_dep_node) ,
486
- try_load_from_on_disk_cache: Some ( try_load_from_on_disk_cache) ,
487
- }
490
+ $( pub ( crate ) fn $name<' tcx>( ) -> DepKindStruct <' tcx> {
491
+ $crate:: plumbing:: query_callback:: <queries:: $name<' tcx>>(
492
+ is_anon!( [ $( $modifiers) * ] ) ,
493
+ is_eval_always!( [ $( $modifiers) * ] ) ,
494
+ )
488
495
} ) *
489
496
}
490
497
491
- pub fn query_callbacks<' tcx>( arena: & ' tcx Arena <' tcx>) -> & ' tcx [ DepKindStruct ] {
498
+ pub fn query_callbacks<' tcx>( arena: & ' tcx Arena <' tcx>) -> & ' tcx [ DepKindStruct < ' tcx> ] {
492
499
arena. alloc_from_iter( make_dep_kind_array!( query_callbacks) )
493
500
}
494
501
}
@@ -531,9 +538,14 @@ macro_rules! define_queries_struct {
531
538
let mut jobs = QueryMap :: default ( ) ;
532
539
533
540
$(
541
+ let make_query = |tcx, key| {
542
+ let kind = dep_graph:: DepKind :: $name;
543
+ let name = stringify!( $name) ;
544
+ $crate:: plumbing:: create_query_frame( tcx, queries:: $name:: describe, key, kind, name)
545
+ } ;
534
546
self . $name. try_collect_active_jobs(
535
547
tcx,
536
- make_query:: $name ,
548
+ make_query,
537
549
& mut jobs,
538
550
) ?;
539
551
) *
0 commit comments