@@ -428,6 +428,7 @@ fn try_execute_query<CTX, C>(
428
428
key : C :: Key ,
429
429
lookup : QueryLookup ,
430
430
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
431
+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
431
432
) -> C :: Stored
432
433
where
433
434
C : QueryCache ,
@@ -457,7 +458,7 @@ where
457
458
// Fast path for when incr. comp. is off.
458
459
if !dep_graph. is_fully_enabled ( ) {
459
460
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) ) ;
461
462
let dep_node_index = dep_graph. next_virtual_depnode_index ( ) ;
462
463
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
463
464
return job. complete ( result, dep_node_index) ;
@@ -468,8 +469,9 @@ where
468
469
469
470
let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
470
471
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
+ } )
473
475
} )
474
476
} ) ;
475
477
@@ -501,6 +503,7 @@ where
501
503
dep_node_index,
502
504
& dep_node,
503
505
query,
506
+ compute,
504
507
) ,
505
508
dep_node_index,
506
509
)
@@ -511,7 +514,7 @@ where
511
514
}
512
515
}
513
516
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 ) ;
515
518
dep_graph. read_index ( dep_node_index) ;
516
519
result
517
520
}
@@ -523,6 +526,7 @@ fn load_from_disk_and_cache_in_memory<CTX, K, V: Debug>(
523
526
dep_node_index : DepNodeIndex ,
524
527
dep_node : & DepNode < CTX :: DepKind > ,
525
528
query : & QueryVtable < CTX , K , V > ,
529
+ compute : fn ( CTX :: DepContext , K ) -> V ,
526
530
) -> V
527
531
where
528
532
CTX : QueryContext ,
@@ -565,7 +569,7 @@ where
565
569
let prof_timer = tcx. dep_context ( ) . profiler ( ) . query_provider ( ) ;
566
570
567
571
// 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) ) ;
569
573
570
574
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
571
575
@@ -627,6 +631,7 @@ fn force_query_with_job<C, CTX>(
627
631
job : JobOwner < ' _ , CTX :: DepKind , C > ,
628
632
dep_node : DepNode < CTX :: DepKind > ,
629
633
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
634
+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
630
635
) -> ( C :: Stored , DepNodeIndex )
631
636
where
632
637
C : QueryCache ,
@@ -653,17 +658,17 @@ where
653
658
if query. eval_always {
654
659
tcx. dep_context ( ) . dep_graph ( ) . with_eval_always_task (
655
660
dep_node,
656
- tcx,
661
+ * tcx. dep_context ( ) ,
657
662
key,
658
- query . compute ,
663
+ compute,
659
664
query. hash_result ,
660
665
)
661
666
} else {
662
667
tcx. dep_context ( ) . dep_graph ( ) . with_task (
663
668
dep_node,
664
- tcx,
669
+ * tcx. dep_context ( ) ,
665
670
key,
666
- query . compute ,
671
+ compute,
667
672
query. hash_result ,
668
673
)
669
674
}
@@ -690,13 +695,14 @@ fn get_query_impl<CTX, C>(
690
695
key : C :: Key ,
691
696
lookup : QueryLookup ,
692
697
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
698
+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
693
699
) -> C :: Stored
694
700
where
695
701
CTX : QueryContext ,
696
702
C : QueryCache ,
697
703
C :: Key : DepNodeParams < CTX :: DepContext > ,
698
704
{
699
- try_execute_query ( tcx, state, cache, span, key, lookup, query)
705
+ try_execute_query ( tcx, state, cache, span, key, lookup, query, compute )
700
706
}
701
707
702
708
/// Ensure that either this query has all green inputs or been executed.
@@ -744,8 +750,10 @@ fn force_query_impl<CTX, C>(
744
750
tcx : CTX ,
745
751
state : & QueryState < CTX :: DepKind , C :: Key > ,
746
752
cache : & QueryCacheStore < C > ,
753
+ key : C :: Key ,
747
754
dep_node : DepNode < CTX :: DepKind > ,
748
755
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
756
+ compute : fn ( CTX :: DepContext , C :: Key ) -> C :: Value ,
749
757
) -> bool
750
758
where
751
759
C : QueryCache ,
@@ -754,18 +762,6 @@ where
754
762
{
755
763
debug_assert ! ( !query. anon) ;
756
764
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
-
769
765
// We may be concurrently trying both execute and force a query.
770
766
// Ensure that only one of them runs the query.
771
767
let cached = cache. cache . lookup ( cache, & key, |_, index| {
@@ -798,7 +794,7 @@ where
798
794
TryGetJob :: JobCompleted ( _) => return true ,
799
795
} ;
800
796
801
- force_query_with_job ( tcx, key, job, dep_node, query) ;
797
+ force_query_with_job ( tcx, key, job, dep_node, query, compute ) ;
802
798
803
799
true
804
800
}
@@ -828,8 +824,17 @@ where
828
824
}
829
825
830
826
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
+ ) ;
833
838
Some ( value)
834
839
}
835
840
@@ -843,5 +848,26 @@ where
843
848
return false ;
844
849
}
845
850
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
+ )
847
873
}
0 commit comments