@@ -248,13 +248,8 @@ where
248248 return TryGetJob :: Cycle ( value) ;
249249 }
250250
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" ) ) ;
258253
259254 if let Some ( prof_timer) = _query_blocked_prof_timer. take ( ) {
260255 prof_timer. finish_with_query_invocation_id ( cached. 1 . into ( ) ) ;
@@ -356,35 +351,28 @@ where
356351/// It returns the shard index and a lock guard to the shard,
357352/// which will be used if the query is not in the cache and we need
358353/// to compute it.
359- fn try_get_cached < CTX , C , R , OnHit , OnMiss > (
354+ fn try_get_cached < ' a , CTX , C , R , OnHit > (
360355 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 ,
363358 // `on_hit` can be called while holding a lock to the query cache
364359 on_hit : OnHit ,
365- on_miss : OnMiss ,
366- ) -> R
360+ ) -> Result < R , QueryLookup < ' a , CTX :: DepKind , CTX :: Query , C :: Key , C :: Sharded > >
367361where
368362 C : QueryCache ,
369363 CTX : QueryContext ,
370364 OnHit : FnOnce ( & C :: Stored , DepNodeIndex ) -> R ,
371- OnMiss : FnOnce ( C :: Key , QueryLookup < ' _ , CTX :: DepKind , CTX :: Query , C :: Key , C :: Sharded > ) -> R ,
372365{
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+ } )
388376}
389377
390378fn try_execute_query < CTX , C > (
@@ -626,16 +614,14 @@ where
626614 C : QueryCache ,
627615 C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
628616{
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+ }
639625}
640626
641627/// Ensure that either this query has all green inputs or been executed.
@@ -694,25 +680,24 @@ fn force_query_impl<CTX, C>(
694680 // We may be concurrently trying both execute and force a query.
695681 // Ensure that only one of them runs the query.
696682
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) ;
716701}
717702
718703pub enum QueryMode {
0 commit comments