@@ -428,6 +428,7 @@ fn try_execute_query<CTX, C>(
428428 key : C :: Key ,
429429 lookup : QueryLookup ,
430430 query : & QueryVtable < CTX , C :: Key , C :: Value > ,
431+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
431432) -> C :: Stored
432433where
433434 C : QueryCache ,
@@ -457,7 +458,7 @@ where
457458 // Fast path for when incr. comp. is off.
458459 if !dep_graph. is_fully_enabled ( ) {
459460 let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
460- let result = tcx. start_query ( job. id , None , || query . compute ( tcx, key) ) ;
461+ let result = tcx. start_query ( job. id , None , || compute ( * tcx. dep_context ( ) , key) ) ;
461462 let dep_node_index = dep_graph. next_virtual_depnode_index ( ) ;
462463 prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
463464 return job. complete ( result, dep_node_index) ;
@@ -468,8 +469,9 @@ where
468469
469470 let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
470471 tcx. start_query ( job. id , diagnostics, || {
471- dep_graph
472- . with_anon_task ( * tcx. dep_context ( ) , query. dep_kind , || query. compute ( tcx, key) )
472+ dep_graph. with_anon_task ( * tcx. dep_context ( ) , query. dep_kind , || {
473+ compute ( * tcx. dep_context ( ) , key)
474+ } )
473475 } )
474476 } ) ;
475477
@@ -501,6 +503,7 @@ where
501503 dep_node_index,
502504 & dep_node,
503505 query,
506+ compute,
504507 ) ,
505508 dep_node_index,
506509 )
@@ -511,7 +514,7 @@ where
511514 }
512515 }
513516
514- let ( result, dep_node_index) = force_query_with_job ( tcx, key, job, dep_node, query) ;
517+ let ( result, dep_node_index) = force_query_with_job ( tcx, key, job, dep_node, query, compute ) ;
515518 dep_graph. read_index ( dep_node_index) ;
516519 result
517520}
@@ -523,6 +526,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
523526 dep_node_index : DepNodeIndex ,
524527 dep_node : & DepNode < CTX :: DepKind > ,
525528 query : & QueryVtable < CTX , K , V > ,
529+ compute : fn ( CTX :: DepContext , K ) -> V ,
526530) -> V
527531where
528532 CTX : QueryContext ,
@@ -565,7 +569,7 @@ where
565569 let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
566570
567571 // The dep-graph for this computation is already in-place.
568- let result = tcx. dep_context ( ) . dep_graph ( ) . with_ignore ( || query . compute ( tcx, key) ) ;
572+ let result = tcx. dep_context ( ) . dep_graph ( ) . with_ignore ( || compute ( * tcx. dep_context ( ) , key) ) ;
569573
570574 prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
571575
@@ -627,6 +631,7 @@ fn force_query_with_job<C, CTX>(
627631 job : JobOwner < ' _ , CTX :: DepKind , C > ,
628632 dep_node : DepNode < CTX :: DepKind > ,
629633 query : & QueryVtable < CTX , C :: Key , C :: Value > ,
634+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
630635) -> ( C :: Stored , DepNodeIndex )
631636where
632637 C : QueryCache ,
@@ -653,17 +658,17 @@ where
653658 if query. eval_always {
654659 tcx. dep_context ( ) . dep_graph ( ) . with_eval_always_task (
655660 dep_node,
656- tcx,
661+ * tcx. dep_context ( ) ,
657662 key,
658- query . compute ,
663+ compute,
659664 query. hash_result ,
660665 )
661666 } else {
662667 tcx. dep_context ( ) . dep_graph ( ) . with_task (
663668 dep_node,
664- tcx,
669+ * tcx. dep_context ( ) ,
665670 key,
666- query . compute ,
671+ compute,
667672 query. hash_result ,
668673 )
669674 }
@@ -690,13 +695,14 @@ fn get_query_impl<CTX, C>(
690695 key : C :: Key ,
691696 lookup : QueryLookup ,
692697 query : & QueryVtable < CTX , C :: Key , C :: Value > ,
698+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
693699) -> C :: Stored
694700where
695701 CTX : QueryContext ,
696702 C : QueryCache ,
697703 C :: Key : DepNodeParams < CTX :: DepContext > ,
698704{
699- try_execute_query ( tcx, state, cache, span, key, lookup, query)
705+ try_execute_query ( tcx, state, cache, span, key, lookup, query, compute )
700706}
701707
702708/// Ensure that either this query has all green inputs or been executed.
@@ -744,8 +750,10 @@ fn force_query_impl<CTX, C>(
744750 tcx : CTX ,
745751 state : & QueryState < CTX :: DepKind , C :: Key > ,
746752 cache : & QueryCacheStore < C > ,
753+ key : C :: Key ,
747754 dep_node : DepNode < CTX :: DepKind > ,
748755 query : & QueryVtable < CTX , C :: Key , C :: Value > ,
756+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
749757) -> bool
750758where
751759 C : QueryCache ,
@@ -754,18 +762,6 @@ where
754762{
755763 debug_assert ! ( !query. anon) ;
756764
757- if !<C :: Key as DepNodeParams < CTX :: DepContext > >:: can_reconstruct_query_key ( ) {
758- return false ;
759- }
760-
761- let key = if let Some ( key) =
762- <C :: Key as DepNodeParams < CTX :: DepContext > >:: recover ( * tcx. dep_context ( ) , & dep_node)
763- {
764- key
765- } else {
766- return false ;
767- } ;
768-
769765 // We may be concurrently trying both execute and force a query.
770766 // Ensure that only one of them runs the query.
771767 let cached = cache. cache . lookup ( cache, & key, |_, index| {
@@ -798,7 +794,7 @@ where
798794 TryGetJob :: JobCompleted ( _) => return true ,
799795 } ;
800796
801- force_query_with_job ( tcx, key, job, dep_node, query) ;
797+ force_query_with_job ( tcx, key, job, dep_node, query, compute ) ;
802798
803799 true
804800}
@@ -828,8 +824,17 @@ where
828824 }
829825
830826 debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
831- let value =
832- get_query_impl ( tcx, Q :: query_state ( tcx) , Q :: query_cache ( tcx) , span, key, lookup, query) ;
827+ let compute = Q :: compute_fn ( tcx, & key) ;
828+ let value = get_query_impl (
829+ tcx,
830+ Q :: query_state ( tcx) ,
831+ Q :: query_cache ( tcx) ,
832+ span,
833+ key,
834+ lookup,
835+ query,
836+ compute,
837+ ) ;
833838 Some ( value)
834839}
835840
@@ -843,5 +848,26 @@ where
843848 return false ;
844849 }
845850
846- force_query_impl ( tcx, Q :: query_state ( tcx) , Q :: query_cache ( tcx) , * dep_node, & Q :: VTABLE )
851+ if !<Q :: Key as DepNodeParams < CTX :: DepContext > >:: can_reconstruct_query_key ( ) {
852+ return false ;
853+ }
854+
855+ let key = if let Some ( key) =
856+ <Q :: Key as DepNodeParams < CTX :: DepContext > >:: recover ( * tcx. dep_context ( ) , & dep_node)
857+ {
858+ key
859+ } else {
860+ return false ;
861+ } ;
862+
863+ let compute = Q :: compute_fn ( tcx, & key) ;
864+ force_query_impl (
865+ tcx,
866+ Q :: query_state ( tcx) ,
867+ Q :: query_cache ( tcx) ,
868+ key,
869+ * dep_node,
870+ & Q :: VTABLE ,
871+ compute,
872+ )
847873}
0 commit comments