@@ -27,14 +27,15 @@ pub trait QueryConfig {
2727pub ( super ) trait QueryDescription < ' tcx > : QueryConfig {
2828 fn describe ( tcx : TyCtxt , key : Self :: Key ) -> String ;
2929
30+ #[ inline]
3031 fn cache_on_disk ( _: Self :: Key ) -> bool {
3132 false
3233 }
3334
3435 fn try_load_from_disk ( _: TyCtxt < ' _ , ' tcx , ' tcx > ,
3536 _: SerializedDepNodeIndex )
3637 -> Option < Self :: Value > {
37- bug ! ( "QueryDescription::load_from_disk() called for unsupport query." )
38+ bug ! ( "QueryDescription::load_from_disk() called for an unsupported query." )
3839 }
3940}
4041
@@ -166,6 +167,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
166167 fn describe ( _tcx : TyCtxt , instance : ty:: Instance < ' tcx > ) -> String {
167168 format ! ( "computing the symbol for `{}`" , instance)
168169 }
170+
171+ #[ inline]
172+ fn cache_on_disk ( _: Self :: Key ) -> bool {
173+ true
174+ }
175+
176+ #[ inline]
177+ fn try_load_from_disk < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
178+ id : SerializedDepNodeIndex )
179+ -> Option < Self :: Value > {
180+ tcx. on_disk_query_result_cache . try_load_query_result ( tcx, id)
181+ }
169182}
170183
171184impl < ' tcx > QueryDescription < ' tcx > for queries:: describe_def < ' tcx > {
@@ -234,6 +247,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_sta
234247 format ! ( "const checking if rvalue is promotable to static `{}`" ,
235248 tcx. item_path_str( def_id) )
236249 }
250+
251+ #[ inline]
252+ fn cache_on_disk ( _: Self :: Key ) -> bool {
253+ true
254+ }
255+
256+ #[ inline]
257+ fn try_load_from_disk < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
258+ id : SerializedDepNodeIndex )
259+ -> Option < Self :: Value > {
260+ tcx. on_disk_query_result_cache . try_load_query_result ( tcx, id)
261+ }
237262}
238263
239264impl < ' tcx > QueryDescription < ' tcx > for queries:: rvalue_promotable_map < ' tcx > {
@@ -254,6 +279,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> {
254279 fn describe ( tcx : TyCtxt , key : ( ty:: ParamEnv < ' tcx > , ty:: PolyTraitRef < ' tcx > ) ) -> String {
255280 format ! ( "checking if `{}` fulfills its obligations" , tcx. item_path_str( key. 1 . def_id( ) ) )
256281 }
282+
283+ #[ inline]
284+ fn cache_on_disk ( _: Self :: Key ) -> bool {
285+ true
286+ }
287+
288+ #[ inline]
289+ fn try_load_from_disk < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
290+ id : SerializedDepNodeIndex )
291+ -> Option < Self :: Value > {
292+ tcx. on_disk_query_result_cache . try_load_query_result ( tcx, id)
293+ }
257294}
258295
259296impl < ' tcx > QueryDescription < ' tcx > for queries:: trait_impls_of < ' tcx > {
@@ -567,3 +604,42 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
567604 }
568605}
569606
607+ impl < ' tcx > QueryDescription < ' tcx > for queries:: optimized_mir < ' tcx > {
608+ #[ inline]
609+ fn cache_on_disk ( def_id : Self :: Key ) -> bool {
610+ def_id. is_local ( )
611+ }
612+
613+ fn try_load_from_disk < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
614+ id : SerializedDepNodeIndex )
615+ -> Option < Self :: Value > {
616+ let mir: Option < :: mir:: Mir < ' tcx > > = tcx. on_disk_query_result_cache
617+ . try_load_query_result ( tcx, id) ;
618+ mir. map ( |x| tcx. alloc_mir ( x) )
619+ }
620+ }
621+
622+ macro_rules! impl_disk_cacheable_query(
623+ ( $query_name: ident, |$key: tt| $cond: expr) => {
624+ impl <' tcx> QueryDescription <' tcx> for queries:: $query_name<' tcx> {
625+ #[ inline]
626+ fn cache_on_disk( $key: Self :: Key ) -> bool {
627+ $cond
628+ }
629+
630+ #[ inline]
631+ fn try_load_from_disk<' a>( tcx: TyCtxt <' a, ' tcx, ' tcx>,
632+ id: SerializedDepNodeIndex )
633+ -> Option <Self :: Value > {
634+ tcx. on_disk_query_result_cache. try_load_query_result( tcx, id)
635+ }
636+ }
637+ }
638+ ) ;
639+
640+ impl_disk_cacheable_query ! ( unsafety_check_result, |def_id| def_id. is_local( ) ) ;
641+ impl_disk_cacheable_query ! ( borrowck, |def_id| def_id. is_local( ) ) ;
642+ impl_disk_cacheable_query ! ( mir_borrowck, |def_id| def_id. is_local( ) ) ;
643+ impl_disk_cacheable_query ! ( mir_const_qualif, |def_id| def_id. is_local( ) ) ;
644+ impl_disk_cacheable_query ! ( contains_extern_indicator, |_| true ) ;
645+ impl_disk_cacheable_query ! ( def_symbol_name, |_| true ) ;
0 commit comments