@@ -27,14 +27,15 @@ pub trait QueryConfig {
27
27
pub ( super ) trait QueryDescription < ' tcx > : QueryConfig {
28
28
fn describe ( tcx : TyCtxt , key : Self :: Key ) -> String ;
29
29
30
+ #[ inline]
30
31
fn cache_on_disk ( _: Self :: Key ) -> bool {
31
32
false
32
33
}
33
34
34
35
fn try_load_from_disk ( _: TyCtxt < ' _ , ' tcx , ' tcx > ,
35
36
_: SerializedDepNodeIndex )
36
37
-> Option < Self :: Value > {
37
- bug ! ( "QueryDescription::load_from_disk() called for unsupport query." )
38
+ bug ! ( "QueryDescription::load_from_disk() called for an unsupported query." )
38
39
}
39
40
}
40
41
@@ -166,6 +167,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::symbol_name<'tcx> {
166
167
fn describe ( _tcx : TyCtxt , instance : ty:: Instance < ' tcx > ) -> String {
167
168
format ! ( "computing the symbol for `{}`" , instance)
168
169
}
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
+ }
169
182
}
170
183
171
184
impl < ' tcx > QueryDescription < ' tcx > for queries:: describe_def < ' tcx > {
@@ -234,6 +247,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::const_is_rvalue_promotable_to_sta
234
247
format ! ( "const checking if rvalue is promotable to static `{}`" ,
235
248
tcx. item_path_str( def_id) )
236
249
}
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
+ }
237
262
}
238
263
239
264
impl < ' tcx > QueryDescription < ' tcx > for queries:: rvalue_promotable_map < ' tcx > {
@@ -254,6 +279,18 @@ impl<'tcx> QueryDescription<'tcx> for queries::trans_fulfill_obligation<'tcx> {
254
279
fn describe ( tcx : TyCtxt , key : ( ty:: ParamEnv < ' tcx > , ty:: PolyTraitRef < ' tcx > ) ) -> String {
255
280
format ! ( "checking if `{}` fulfills its obligations" , tcx. item_path_str( key. 1 . def_id( ) ) )
256
281
}
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
+ }
257
294
}
258
295
259
296
impl < ' tcx > QueryDescription < ' tcx > for queries:: trait_impls_of < ' tcx > {
@@ -567,3 +604,42 @@ impl<'tcx> QueryDescription<'tcx> for queries::typeck_tables_of<'tcx> {
567
604
}
568
605
}
569
606
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