@@ -2,7 +2,7 @@ use crate::ty::query::QueryDescription;
22use crate :: ty:: query:: queries;
33use crate :: ty:: { self , ParamEnvAnd , Ty , TyCtxt } ;
44use crate :: ty:: subst:: SubstsRef ;
5- use crate :: dep_graph:: SerializedDepNodeIndex ;
5+ use crate :: dep_graph:: { RecoverKey , DepKind , DepNode , SerializedDepNodeIndex } ;
66use crate :: hir:: def_id:: { CrateNum , DefId , DefIndex } ;
77use crate :: mir;
88use crate :: mir:: interpret:: GlobalId ;
@@ -33,13 +33,13 @@ rustc_queries! {
3333 Other {
3434 /// Records the type of every item.
3535 query type_of( key: DefId ) -> Ty <' tcx> {
36- cache { key. is_local( ) }
36+ cache_on_disk_if { key. is_local( ) }
3737 }
3838
3939 /// Maps from the `DefId` of an item (trait/struct/enum/fn) to its
4040 /// associated generics.
4141 query generics_of( key: DefId ) -> & ' tcx ty:: Generics {
42- cache { key. is_local( ) }
42+ cache_on_disk_if { key. is_local( ) }
4343 load_cached( tcx, id) {
4444 let generics: Option <ty:: Generics > = tcx. queries. on_disk_cache
4545 . try_load_query_result( tcx, id) ;
@@ -62,7 +62,9 @@ rustc_queries! {
6262 /// predicate gets in the way of some checks, which are intended
6363 /// to operate over only the actual where-clauses written by the
6464 /// 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+ }
6668
6769 query native_libraries( _: CrateNum ) -> Lrc <Vec <NativeLibrary >> {
6870 desc { "looking up the native libraries of a linked crate" }
@@ -93,7 +95,7 @@ rustc_queries! {
9395 /// of the MIR qualify_consts pass. The actual meaning of
9496 /// the value isn't known except to the pass itself.
9597 query mir_const_qualif( key: DefId ) -> ( u8 , & ' tcx BitSet <mir:: Local >) {
96- cache { key. is_local( ) }
98+ cache_on_disk_if { key. is_local( ) }
9799 }
98100
99101 /// Fetch the MIR for a given `DefId` right after it's built - this includes
@@ -115,7 +117,7 @@ rustc_queries! {
115117 /// MIR after our optimization passes have run. This is MIR that is ready
116118 /// for codegen. This is also the only query that can fetch non-local MIR, at present.
117119 query optimized_mir( key: DefId ) -> & ' tcx mir:: Body <' tcx> {
118- cache { key. is_local( ) }
120+ cache_on_disk_if { key. is_local( ) }
119121 load_cached( tcx, id) {
120122 let mir: Option <crate :: mir:: Body <' tcx>> = tcx. queries. on_disk_cache
121123 . try_load_query_result( tcx, id) ;
@@ -285,7 +287,9 @@ rustc_queries! {
285287
286288 TypeChecking {
287289 /// 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+ }
289293
290294 /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error
291295 query unsafe_derive_on_repr_packed( _: DefId ) -> ( ) { }
@@ -348,7 +352,7 @@ rustc_queries! {
348352 }
349353
350354 query typeck_tables_of( key: DefId ) -> & ' tcx ty:: TypeckTables <' tcx> {
351- cache { key. is_local( ) }
355+ cache_on_disk_if { key. is_local( ) }
352356 load_cached( tcx, id) {
353357 let typeck_tables: Option <ty:: TypeckTables <' tcx>> = tcx
354358 . queries. on_disk_cache
@@ -360,7 +364,9 @@ rustc_queries! {
360364 }
361365
362366 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+ }
364370 }
365371
366372 TypeChecking {
@@ -372,11 +378,15 @@ rustc_queries! {
372378 }
373379
374380 BorrowChecking {
375- query borrowck( _: DefId ) -> & ' tcx BorrowCheckResult { }
381+ query borrowck( key: DefId ) -> & ' tcx BorrowCheckResult {
382+ cache_on_disk_if { key. is_local( ) }
383+ }
376384
377385 /// Borrow-checks the function body. If this is a closure, returns
378386 /// 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+ }
380390 }
381391
382392 TypeChecking {
@@ -412,9 +422,9 @@ rustc_queries! {
412422 "const-evaluating `{}`" ,
413423 tcx. def_path_str( key. value. instance. def. def_id( ) )
414424 }
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+ opt_result . map_or ( true , |r| r . is_ok ( ) )
418428 }
419429 }
420430
@@ -427,9 +437,9 @@ rustc_queries! {
427437 "const-evaluating + checking `{}`" ,
428438 tcx. def_path_str( key. value. instance. def. def_id( ) )
429439 }
430- cache { true }
431- load_cached ( tcx , id ) {
432- tcx . queries . on_disk_cache . try_load_query_result ( tcx , id ) . map ( Ok )
440+ cache_on_disk_if ( _ , opt_result ) {
441+ // Only store results without errors
442+ opt_result . map_or ( true , |r| r . is_ok ( ) )
433443 }
434444 }
435445
@@ -453,7 +463,9 @@ rustc_queries! {
453463 }
454464
455465 TypeChecking {
456- query check_match( _: DefId ) -> ( ) { }
466+ query check_match( key: DefId ) -> ( ) {
467+ cache_on_disk_if { key. is_local( ) }
468+ }
457469
458470 /// Performs part of the privacy check and computes "access levels".
459471 query privacy_access_levels( _: CrateNum ) -> & ' tcx AccessLevels {
@@ -483,7 +495,7 @@ rustc_queries! {
483495 query symbol_name( key: ty:: Instance <' tcx>) -> ty:: SymbolName {
484496 no_force
485497 desc { "computing the symbol for `{}`" , key }
486- cache { true }
498+ cache_on_disk_if { true }
487499 }
488500
489501 query def_kind( _: DefId ) -> Option <DefKind > { }
@@ -501,7 +513,9 @@ rustc_queries! {
501513 }
502514
503515 Codegen {
504- query codegen_fn_attrs( _: DefId ) -> CodegenFnAttrs { }
516+ query codegen_fn_attrs( _: DefId ) -> CodegenFnAttrs {
517+ cache_on_disk_if { true }
518+ }
505519 }
506520
507521 Other {
@@ -519,7 +533,7 @@ rustc_queries! {
519533 "const checking if rvalue is promotable to static `{}`" ,
520534 tcx. def_path_str( key)
521535 }
522- cache { true }
536+ cache_on_disk_if { true }
523537 }
524538 query rvalue_promotable_map( key: DefId ) -> & ' tcx ItemLocalSet {
525539 desc { |tcx|
@@ -548,7 +562,7 @@ rustc_queries! {
548562 key: ( ty:: ParamEnv <' tcx>, ty:: PolyTraitRef <' tcx>)
549563 ) -> Vtable <' tcx, ( ) > {
550564 no_force
551- cache { true }
565+ cache_on_disk_if { true }
552566 desc { |tcx|
553567 "checking if `{}` fulfills its obligations" ,
554568 tcx. def_path_str( key. 1 . def_id( ) )
@@ -560,7 +574,9 @@ rustc_queries! {
560574 query trait_impls_of( key: DefId ) -> & ' tcx ty:: trait_def:: TraitImpls {
561575 desc { |tcx| "trait impls of `{}`" , tcx. def_path_str( key) }
562576 }
563- query specialization_graph_of( _: DefId ) -> & ' tcx specialization_graph:: Graph { }
577+ query specialization_graph_of( _: DefId ) -> & ' tcx specialization_graph:: Graph {
578+ cache_on_disk_if { true }
579+ }
564580 query is_object_safe( key: DefId ) -> bool {
565581 desc { |tcx| "determine object safety of trait `{}`" , tcx. def_path_str( key) }
566582 }
0 commit comments