@@ -248,13 +248,8 @@ where
248
248
return TryGetJob :: Cycle ( value) ;
249
249
}
250
250
251
- let cached = try_get_cached (
252
- tcx,
253
- state,
254
- ( * key) . clone ( ) ,
255
- |value, index| ( value. clone ( ) , index) ,
256
- |_, _| panic ! ( "value must be in cache after waiting" ) ,
257
- ) ;
251
+ let cached = try_get_cached ( tcx, state, key, |value, index| ( value. clone ( ) , index) )
252
+ . unwrap_or_else ( |_| panic ! ( "value must be in cache after waiting" ) ) ;
258
253
259
254
if let Some ( prof_timer) = _query_blocked_prof_timer. take ( ) {
260
255
prof_timer. finish_with_query_invocation_id ( cached. 1 . into ( ) ) ;
@@ -356,35 +351,28 @@ where
356
351
/// It returns the shard index and a lock guard to the shard,
357
352
/// which will be used if the query is not in the cache and we need
358
353
/// to compute it.
359
- fn try_get_cached < CTX , C , R , OnHit , OnMiss > (
354
+ fn try_get_cached < ' a , CTX , C , R , OnHit > (
360
355
tcx : CTX ,
361
- state : & QueryState < CTX :: DepKind , CTX :: Query , C > ,
362
- key : C :: Key ,
356
+ state : & ' a QueryState < CTX :: DepKind , CTX :: Query , C > ,
357
+ key : & C :: Key ,
363
358
// `on_hit` can be called while holding a lock to the query cache
364
359
on_hit : OnHit ,
365
- on_miss : OnMiss ,
366
- ) -> R
360
+ ) -> Result < R , QueryLookup < ' a , CTX :: DepKind , CTX :: Query , C :: Key , C :: Sharded > >
367
361
where
368
362
C : QueryCache ,
369
363
CTX : QueryContext ,
370
364
OnHit : FnOnce ( & C :: Stored , DepNodeIndex ) -> R ,
371
- OnMiss : FnOnce ( C :: Key , QueryLookup < ' _ , CTX :: DepKind , CTX :: Query , C :: Key , C :: Sharded > ) -> R ,
372
365
{
373
- state. cache . lookup (
374
- state,
375
- key,
376
- |value, index| {
377
- if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
378
- tcx. profiler ( ) . query_cache_hit ( index. into ( ) ) ;
379
- }
380
- #[ cfg( debug_assertions) ]
381
- {
382
- state. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
383
- }
384
- on_hit ( value, index)
385
- } ,
386
- on_miss,
387
- )
366
+ state. cache . lookup ( state, & key, |value, index| {
367
+ if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
368
+ tcx. profiler ( ) . query_cache_hit ( index. into ( ) ) ;
369
+ }
370
+ #[ cfg( debug_assertions) ]
371
+ {
372
+ state. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
373
+ }
374
+ on_hit ( value, index)
375
+ } )
388
376
}
389
377
390
378
fn try_execute_query < CTX , C > (
@@ -626,16 +614,14 @@ where
626
614
C : QueryCache ,
627
615
C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
628
616
{
629
- try_get_cached (
630
- tcx,
631
- state,
632
- key,
633
- |value, index| {
634
- tcx. dep_graph ( ) . read_index ( index) ;
635
- value. clone ( )
636
- } ,
637
- |key, lookup| try_execute_query ( tcx, state, span, key, lookup, query) ,
638
- )
617
+ let cached = try_get_cached ( tcx, state, & key, |value, index| {
618
+ tcx. dep_graph ( ) . read_index ( index) ;
619
+ value. clone ( )
620
+ } ) ;
621
+ match cached {
622
+ Ok ( value) => value,
623
+ Err ( lookup) => try_execute_query ( tcx, state, span, key, lookup, query) ,
624
+ }
639
625
}
640
626
641
627
/// Ensure that either this query has all green inputs or been executed.
@@ -694,25 +680,24 @@ fn force_query_impl<CTX, C>(
694
680
// We may be concurrently trying both execute and force a query.
695
681
// Ensure that only one of them runs the query.
696
682
697
- try_get_cached (
698
- tcx,
699
- state,
700
- key,
701
- |_, _| {
702
- // Cache hit, do nothing
703
- } ,
704
- |key, lookup| {
705
- let job = match JobOwner :: < ' _ , CTX :: DepKind , CTX :: Query , C > :: try_start (
706
- tcx, state, span, & key, lookup, query,
707
- ) {
708
- TryGetJob :: NotYetStarted ( job) => job,
709
- TryGetJob :: Cycle ( _) => return ,
710
- #[ cfg( parallel_compiler) ]
711
- TryGetJob :: JobCompleted ( _) => return ,
712
- } ;
713
- force_query_with_job ( tcx, key, job, dep_node, query) ;
714
- } ,
715
- ) ;
683
+ let cached = try_get_cached ( tcx, state, & key, |_, _| {
684
+ // Cache hit, do nothing
685
+ } ) ;
686
+
687
+ let lookup = match cached {
688
+ Ok ( ( ) ) => return ,
689
+ Err ( lookup) => lookup,
690
+ } ;
691
+
692
+ let job = match JobOwner :: < ' _ , CTX :: DepKind , CTX :: Query , C > :: try_start (
693
+ tcx, state, span, & key, lookup, query,
694
+ ) {
695
+ TryGetJob :: NotYetStarted ( job) => job,
696
+ TryGetJob :: Cycle ( _) => return ,
697
+ #[ cfg( parallel_compiler) ]
698
+ TryGetJob :: JobCompleted ( _) => return ,
699
+ } ;
700
+ force_query_with_job ( tcx, key, job, dep_node, query) ;
716
701
}
717
702
718
703
pub enum QueryMode {
0 commit comments