@@ -202,6 +202,40 @@ impl<'tcx> TyCtxt<'tcx> {
202
202
}
203
203
}
204
204
205
+ #[ inline]
206
+ fn query_get_at < ' tcx , Cache > (
207
+ tcx : TyCtxt < ' tcx > ,
208
+ execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
209
+ query_cache : & Cache ,
210
+ span : Span ,
211
+ key : Cache :: Key ,
212
+ ) -> Cache :: Value
213
+ where
214
+ Cache : QueryCache ,
215
+ {
216
+ let key = key. into_query_param ( ) ;
217
+ match try_get_cached ( tcx, query_cache, & key) {
218
+ Some ( value) => value,
219
+ None => execute_query ( tcx, span, key, QueryMode :: Get ) . unwrap ( ) ,
220
+ }
221
+ }
222
+
223
+ #[ inline]
224
+ fn query_ensure < ' tcx , Cache > (
225
+ tcx : TyCtxt < ' tcx > ,
226
+ execute_query : fn ( TyCtxt < ' tcx > , Span , Cache :: Key , QueryMode ) -> Option < Cache :: Value > ,
227
+ query_cache : & Cache ,
228
+ key : Cache :: Key ,
229
+ check_cache : bool ,
230
+ ) where
231
+ Cache : QueryCache ,
232
+ {
233
+ let key = key. into_query_param ( ) ;
234
+ if try_get_cached ( tcx, query_cache, & key) . is_none ( ) {
235
+ execute_query ( tcx, DUMMY_SP , key, QueryMode :: Ensure { check_cache } ) ;
236
+ }
237
+ }
238
+
205
239
macro_rules! query_helper_param_ty {
206
240
( DefId ) => { impl IntoQueryParam <DefId > } ;
207
241
( LocalDefId ) => { impl IntoQueryParam <LocalDefId > } ;
@@ -407,35 +441,27 @@ macro_rules! define_callbacks {
407
441
$( $( #[ $attr] ) *
408
442
#[ inline( always) ]
409
443
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
410
- let key = key. into_query_param( ) ;
411
-
412
- match try_get_cached( self . tcx, & self . tcx. query_system. caches. $name, & key) {
413
- Some ( _) => return ,
414
- None => ( self . tcx. query_system. fns. engine. $name) (
415
- self . tcx,
416
- DUMMY_SP ,
417
- key,
418
- QueryMode :: Ensure { check_cache: false } ,
419
- ) ,
420
- } ;
444
+ query_ensure(
445
+ self . tcx,
446
+ self . tcx. query_system. fns. engine. $name,
447
+ & self . tcx. query_system. caches. $name,
448
+ key. into_query_param( ) ,
449
+ false ,
450
+ ) ;
421
451
} ) *
422
452
}
423
453
424
454
impl <' tcx> TyCtxtEnsureWithValue <' tcx> {
425
455
$( $( #[ $attr] ) *
426
456
#[ inline( always) ]
427
457
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) {
428
- let key = key. into_query_param( ) ;
429
-
430
- match try_get_cached( self . tcx, & self . tcx. query_system. caches. $name, & key) {
431
- Some ( _) => return ,
432
- None => ( self . tcx. query_system. fns. engine. $name) (
433
- self . tcx,
434
- DUMMY_SP ,
435
- key,
436
- QueryMode :: Ensure { check_cache: true } ,
437
- ) ,
438
- } ;
458
+ query_ensure(
459
+ self . tcx,
460
+ self . tcx. query_system. fns. engine. $name,
461
+ & self . tcx. query_system. caches. $name,
462
+ key. into_query_param( ) ,
463
+ true ,
464
+ ) ;
439
465
} ) *
440
466
}
441
467
@@ -454,16 +480,13 @@ macro_rules! define_callbacks {
454
480
#[ inline( always) ]
455
481
pub fn $name( self , key: query_helper_param_ty!( $( $K) * ) ) -> $V
456
482
{
457
- let key = key. into_query_param( ) ;
458
-
459
- restore:: <$V>( match try_get_cached( self . tcx, & self . tcx. query_system. caches. $name, & key) {
460
- Some ( value) => value,
461
- None => ( self . tcx. query_system. fns. engine. $name) (
462
- self . tcx,
463
- self . span,
464
- key, QueryMode :: Get
465
- ) . unwrap( ) ,
466
- } )
483
+ restore:: <$V>( query_get_at(
484
+ self . tcx,
485
+ self . tcx. query_system. fns. engine. $name,
486
+ & self . tcx. query_system. caches. $name,
487
+ self . span,
488
+ key. into_query_param( ) ,
489
+ ) )
467
490
} ) *
468
491
}
469
492
0 commit comments