@@ -2,7 +2,7 @@ use crate::ty::query::QueryDescription;
2
2
use crate :: ty:: query:: queries;
3
3
use crate :: ty:: { self , ParamEnvAnd , Ty , TyCtxt } ;
4
4
use crate :: ty:: subst:: SubstsRef ;
5
- use crate :: dep_graph:: SerializedDepNodeIndex ;
5
+ use crate :: dep_graph:: { RecoverKey , DepKind , DepNode , SerializedDepNodeIndex } ;
6
6
use crate :: hir:: def_id:: { CrateNum , DefId , DefIndex } ;
7
7
use crate :: mir;
8
8
use crate :: mir:: interpret:: GlobalId ;
@@ -33,13 +33,13 @@ rustc_queries! {
33
33
Other {
34
34
/// Records the type of every item.
35
35
query type_of( key: DefId ) -> Ty <' tcx> {
36
- cache { key. is_local( ) }
36
+ cache_on_disk_if { key. is_local( ) }
37
37
}
38
38
39
39
/// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
40
40
/// associated generics.
41
41
query generics_of( key: DefId ) -> & ' tcx ty:: Generics {
42
- cache { key. is_local( ) }
42
+ cache_on_disk_if { key. is_local( ) }
43
43
load_cached( tcx, id) {
44
44
let generics: Option <ty:: Generics > = tcx. queries. on_disk_cache
45
45
. try_load_query_result( tcx, id) ;
@@ -62,7 +62,9 @@ rustc_queries! {
62
62
/// predicate gets in the way of some checks, which are intended
63
63
/// to operate over only the actual where-clauses written by the
64
64
/// user.)
65
- query predicates_of( _: DefId ) -> & ' tcx ty:: GenericPredicates <' tcx> { }
65
+ query predicates_of( key: DefId ) -> & ' tcx ty:: GenericPredicates <' tcx> {
66
+ cache_on_disk_if { key. is_local( ) }
67
+ }
66
68
67
69
query native_libraries( _: CrateNum ) -> Lrc <Vec <NativeLibrary >> {
68
70
desc { "looking up the native libraries of a linked crate" }
@@ -93,7 +95,7 @@ rustc_queries! {
93
95
/// of the MIR qualify_consts pass. The actual meaning of
94
96
/// the value isn't known except to the pass itself.
95
97
query mir_const_qualif( key: DefId ) -> ( u8 , & ' tcx BitSet <mir:: Local >) {
96
- cache { key. is_local( ) }
98
+ cache_on_disk_if { key. is_local( ) }
97
99
}
98
100
99
101
/// Fetch the MIR for a given `DefId` right after it's built - this includes
@@ -115,7 +117,7 @@ rustc_queries! {
115
117
/// MIR after our optimization passes have run. This is MIR that is ready
116
118
/// for codegen. This is also the only query that can fetch non-local MIR, at present.
117
119
query optimized_mir( key: DefId ) -> & ' tcx mir:: Body <' tcx> {
118
- cache { key. is_local( ) }
120
+ cache_on_disk_if { key. is_local( ) }
119
121
load_cached( tcx, id) {
120
122
let mir: Option <crate :: mir:: Body <' tcx>> = tcx. queries. on_disk_cache
121
123
. try_load_query_result( tcx, id) ;
@@ -285,7 +287,9 @@ rustc_queries! {
285
287
286
288
TypeChecking {
287
289
/// The result of unsafety-checking this `DefId`.
288
- query unsafety_check_result( _: DefId ) -> mir:: UnsafetyCheckResult { }
290
+ query unsafety_check_result( key: DefId ) -> mir:: UnsafetyCheckResult {
291
+ cache_on_disk_if { key. is_local( ) }
292
+ }
289
293
290
294
/// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
291
295
query unsafe_derive_on_repr_packed( _: DefId ) -> ( ) { }
@@ -348,7 +352,7 @@ rustc_queries! {
348
352
}
349
353
350
354
query typeck_tables_of( key: DefId ) -> & ' tcx ty:: TypeckTables <' tcx> {
351
- cache { key. is_local( ) }
355
+ cache_on_disk_if { key. is_local( ) }
352
356
load_cached( tcx, id) {
353
357
let typeck_tables: Option <ty:: TypeckTables <' tcx>> = tcx
354
358
. queries. on_disk_cache
@@ -360,7 +364,9 @@ rustc_queries! {
360
364
}
361
365
362
366
Other {
363
- query used_trait_imports( _: DefId ) -> & ' tcx DefIdSet { }
367
+ query used_trait_imports( key: DefId ) -> & ' tcx DefIdSet {
368
+ cache_on_disk_if { key. is_local( ) }
369
+ }
364
370
}
365
371
366
372
TypeChecking {
@@ -372,11 +378,15 @@ rustc_queries! {
372
378
}
373
379
374
380
BorrowChecking {
375
- query borrowck( _: DefId ) -> & ' tcx BorrowCheckResult { }
381
+ query borrowck( key: DefId ) -> & ' tcx BorrowCheckResult {
382
+ cache_on_disk_if { key. is_local( ) }
383
+ }
376
384
377
385
/// Borrow-checks the function body. If this is a closure, returns
378
386
/// additional requirements that the closure's creator must verify.
379
- query mir_borrowck( _: DefId ) -> mir:: BorrowCheckResult <' tcx> { }
387
+ query mir_borrowck( key: DefId ) -> mir:: BorrowCheckResult <' tcx> {
388
+ cache_on_disk_if( tcx, _) { key. is_local( ) && tcx. is_closure( key) }
389
+ }
380
390
}
381
391
382
392
TypeChecking {
@@ -412,9 +422,10 @@ rustc_queries! {
412
422
"const-evaluating `{}`" ,
413
423
tcx. def_path_str( key. value. instance. def. def_id( ) )
414
424
}
415
- cache { true }
416
- load_cached( tcx, id) {
417
- tcx. queries. on_disk_cache. try_load_query_result( tcx, id) . map( Ok )
425
+ cache_on_disk_if( _, opt_result) {
426
+ // Only store results without errors
427
+ // FIXME: We never store these
428
+ opt_result. map_or( true , |r| r. is_ok( ) )
418
429
}
419
430
}
420
431
@@ -427,9 +438,9 @@ rustc_queries! {
427
438
"const-evaluating + checking `{}`" ,
428
439
tcx. def_path_str( key. value. instance. def. def_id( ) )
429
440
}
430
- cache { true }
431
- load_cached ( tcx , id ) {
432
- tcx . queries . on_disk_cache . try_load_query_result ( tcx , id ) . map ( Ok )
441
+ cache_on_disk_if ( _ , opt_result ) {
442
+ // Only store results without errors
443
+ opt_result . map_or ( true , |r| r . is_ok ( ) )
433
444
}
434
445
}
435
446
@@ -453,7 +464,9 @@ rustc_queries! {
453
464
}
454
465
455
466
TypeChecking {
456
- query check_match( _: DefId ) -> ( ) { }
467
+ query check_match( key: DefId ) -> ( ) {
468
+ cache_on_disk_if { key. is_local( ) }
469
+ }
457
470
458
471
/// Performs part of the privacy check and computes "access levels".
459
472
query privacy_access_levels( _: CrateNum ) -> & ' tcx AccessLevels {
@@ -483,7 +496,7 @@ rustc_queries! {
483
496
query symbol_name( key: ty:: Instance <' tcx>) -> ty:: SymbolName {
484
497
no_force
485
498
desc { "computing the symbol for `{}`" , key }
486
- cache { true }
499
+ cache_on_disk_if { true }
487
500
}
488
501
489
502
query def_kind( _: DefId ) -> Option <DefKind > { }
@@ -501,7 +514,9 @@ rustc_queries! {
501
514
}
502
515
503
516
Codegen {
504
- query codegen_fn_attrs( _: DefId ) -> CodegenFnAttrs { }
517
+ query codegen_fn_attrs( _: DefId ) -> CodegenFnAttrs {
518
+ cache_on_disk_if { true }
519
+ }
505
520
}
506
521
507
522
Other {
@@ -519,7 +534,7 @@ rustc_queries! {
519
534
"const checking if rvalue is promotable to static `{}`" ,
520
535
tcx. def_path_str( key)
521
536
}
522
- cache { true }
537
+ cache_on_disk_if { true }
523
538
}
524
539
query rvalue_promotable_map( key: DefId ) -> & ' tcx ItemLocalSet {
525
540
desc { |tcx|
@@ -548,7 +563,7 @@ rustc_queries! {
548
563
key: ( ty:: ParamEnv <' tcx>, ty:: PolyTraitRef <' tcx>)
549
564
) -> Vtable <' tcx, ( ) > {
550
565
no_force
551
- cache { true }
566
+ cache_on_disk_if { true }
552
567
desc { |tcx|
553
568
"checking if `{}` fulfills its obligations" ,
554
569
tcx. def_path_str( key. 1 . def_id( ) )
@@ -560,7 +575,9 @@ rustc_queries! {
560
575
query trait_impls_of( key: DefId ) -> & ' tcx ty:: trait_def:: TraitImpls {
561
576
desc { |tcx| "trait impls of `{}`" , tcx. def_path_str( key) }
562
577
}
563
- query specialization_graph_of( _: DefId ) -> & ' tcx specialization_graph:: Graph { }
578
+ query specialization_graph_of( _: DefId ) -> & ' tcx specialization_graph:: Graph {
579
+ cache_on_disk_if { true }
580
+ }
564
581
query is_object_safe( key: DefId ) -> bool {
565
582
desc { |tcx| "determine object safety of trait `{}`" , tcx. def_path_str( key) }
566
583
}
0 commit comments