@@ -19,7 +19,6 @@ use std::hash::Hash;
19
19
use std:: marker:: PhantomData ;
20
20
21
21
use derive_where:: derive_where;
22
- use rustc_index:: { Idx , IndexVec } ;
23
22
#[ cfg( feature = "nightly" ) ]
24
23
use rustc_macros:: { Decodable_NoContext , Encodable_NoContext , HashStable_NoContext } ;
25
24
use tracing:: debug;
@@ -497,14 +496,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
497
496
fn update_parent_goal (
498
497
stack : & mut Stack < X > ,
499
498
step_kind_from_parent : PathKind ,
500
- reached_depth : StackDepth ,
499
+ required_depth_for_nested : usize ,
501
500
heads : & CycleHeads ,
502
501
encountered_overflow : bool ,
503
502
context : UpdateParentGoalCtxt < ' _ , X > ,
504
503
) {
505
504
if let Some ( parent_index) = stack. last_index ( ) {
506
505
let parent = & mut stack[ parent_index] ;
507
- parent. reached_depth = parent. reached_depth . max ( reached_depth ) ;
506
+ parent. required_depth = parent. required_depth . max ( required_depth_for_nested + 1 ) ;
508
507
parent. encountered_overflow |= encountered_overflow;
509
508
510
509
parent. heads . extend_from_child ( parent_index, step_kind_from_parent, heads) ;
@@ -612,20 +611,18 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
612
611
return result;
613
612
}
614
613
615
- // Unfortunate, it looks like we actually have to compute this goalrar.
616
- let depth = self . stack . next_index ( ) ;
617
- let entry = StackEntry {
614
+ // Unfortunate, it looks like we actually have to compute this goal.
615
+ self . stack . push ( StackEntry {
618
616
input,
619
617
step_kind_from_parent,
620
618
available_depth,
621
- reached_depth : depth ,
619
+ required_depth : 0 ,
622
620
heads : Default :: default ( ) ,
623
621
encountered_overflow : false ,
624
622
has_been_used : None ,
625
623
nested_goals : Default :: default ( ) ,
626
624
provisional_result : None ,
627
- } ;
628
- assert_eq ! ( self . stack. push( entry) , depth) ;
625
+ } ) ;
629
626
630
627
// This is for global caching, so we properly track query dependencies.
631
628
// Everything that affects the `result` should be performed within this
@@ -642,7 +639,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
642
639
Self :: update_parent_goal (
643
640
& mut self . stack ,
644
641
final_entry. step_kind_from_parent ,
645
- final_entry. reached_depth ,
642
+ final_entry. required_depth ,
646
643
& final_entry. heads ,
647
644
final_entry. encountered_overflow ,
648
645
UpdateParentGoalCtxt :: Ordinary ( & final_entry. nested_goals ) ,
@@ -824,14 +821,10 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
824
821
// A provisional cache entry is only valid if the current path from its
825
822
// highest cycle head to the goal is the same.
826
823
if path_from_head == Self :: cycle_path_kind ( & self . stack , step_kind_from_parent, head) {
827
- // While we don't have to track the full depth of the provisional cache entry,
828
- // we do have to increment the required depth by one as we'd have already failed
829
- // with overflow otherwise
830
- let next_index = self . stack . next_index ( ) ;
831
824
Self :: update_parent_goal (
832
825
& mut self . stack ,
833
826
step_kind_from_parent,
834
- next_index ,
827
+ 1 ,
835
828
heads,
836
829
encountered_overflow,
837
830
UpdateParentGoalCtxt :: ProvisionalCacheHit ,
@@ -947,7 +940,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
947
940
available_depth : AvailableDepth ,
948
941
) -> Option < X :: Result > {
949
942
cx. with_global_cache ( |cache| {
950
- let CacheData { result, additional_depth , encountered_overflow, nested_goals } = cache
943
+ let CacheData { result, required_depth , encountered_overflow, nested_goals } = cache
951
944
. get ( cx, input, available_depth, |nested_goals| {
952
945
Self :: candidate_is_applicable (
953
946
& self . stack ,
@@ -957,23 +950,19 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
957
950
)
958
951
} ) ?;
959
952
960
- // Update the reached depth of the current goal to make sure
961
- // its state is the same regardless of whether we've used the
962
- // global cache or not.
963
- let reached_depth = self . stack . next_index ( ) . plus ( additional_depth) ;
964
953
// We don't move cycle participants to the global cache, so the
965
954
// cycle heads are always empty.
966
955
let heads = Default :: default ( ) ;
967
956
Self :: update_parent_goal (
968
957
& mut self . stack ,
969
958
step_kind_from_parent,
970
- reached_depth ,
959
+ required_depth ,
971
960
& heads,
972
961
encountered_overflow,
973
962
UpdateParentGoalCtxt :: Ordinary ( nested_goals) ,
974
963
) ;
975
964
976
- debug ! ( ?additional_depth , "global cache hit" ) ;
965
+ debug ! ( ?required_depth , "global cache hit" ) ;
977
966
Some ( result)
978
967
} )
979
968
}
@@ -999,10 +988,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
999
988
1000
989
// Subtle: when encountering a cyclic goal, we still first checked for overflow,
1001
990
// so we have to update the reached depth.
1002
- let next_index = self . stack . next_index ( ) ;
1003
991
let last_index = self . stack . last_index ( ) . unwrap ( ) ;
1004
992
let last = & mut self . stack [ last_index] ;
1005
- last. reached_depth = last. reached_depth . max ( next_index ) ;
993
+ last. required_depth = last. required_depth . max ( 1 ) ;
1006
994
1007
995
last. nested_goals . insert ( input, step_kind_from_parent. into ( ) ) ;
1008
996
last. nested_goals . insert ( last. input , PathsToNested :: EMPTY ) ;
@@ -1137,15 +1125,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
1137
1125
result : X :: Result ,
1138
1126
dep_node : X :: DepNodeIndex ,
1139
1127
) {
1140
- let additional_depth = final_entry. reached_depth . as_usize ( ) - self . stack . len ( ) ;
1141
1128
debug ! ( ?final_entry, ?result, "insert global cache" ) ;
1142
1129
cx. with_global_cache ( |cache| {
1143
1130
cache. insert (
1144
1131
cx,
1145
1132
input,
1146
1133
result,
1147
1134
dep_node,
1148
- additional_depth ,
1135
+ final_entry . required_depth ,
1149
1136
final_entry. encountered_overflow ,
1150
1137
final_entry. nested_goals ,
1151
1138
)
0 commit comments