@@ -19,7 +19,6 @@ use std::hash::Hash;
1919use std:: marker:: PhantomData ;
2020
2121use derive_where:: derive_where;
22- use rustc_index:: { Idx , IndexVec } ;
2322#[ cfg( feature = "nightly" ) ]
2423use rustc_macros:: { Decodable_NoContext , Encodable_NoContext , HashStable_NoContext } ;
2524use tracing:: debug;
@@ -497,14 +496,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
497496 fn update_parent_goal (
498497 stack : & mut Stack < X > ,
499498 step_kind_from_parent : PathKind ,
500- reached_depth : StackDepth ,
499+ required_depth_for_nested : usize ,
501500 heads : & CycleHeads ,
502501 encountered_overflow : bool ,
503502 context : UpdateParentGoalCtxt < ' _ , X > ,
504503 ) {
505504 if let Some ( parent_index) = stack. last_index ( ) {
506505 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 ) ;
508507 parent. encountered_overflow |= encountered_overflow;
509508
510509 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> {
612611 return result;
613612 }
614613
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 {
618616 input,
619617 step_kind_from_parent,
620618 available_depth,
621- reached_depth : depth ,
619+ required_depth : 0 ,
622620 heads : Default :: default ( ) ,
623621 encountered_overflow : false ,
624622 has_been_used : None ,
625623 nested_goals : Default :: default ( ) ,
626624 provisional_result : None ,
627- } ;
628- assert_eq ! ( self . stack. push( entry) , depth) ;
625+ } ) ;
629626
630627 // This is for global caching, so we properly track query dependencies.
631628 // Everything that affects the `result` should be performed within this
@@ -642,7 +639,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
642639 Self :: update_parent_goal (
643640 & mut self . stack ,
644641 final_entry. step_kind_from_parent ,
645- final_entry. reached_depth ,
642+ final_entry. required_depth ,
646643 & final_entry. heads ,
647644 final_entry. encountered_overflow ,
648645 UpdateParentGoalCtxt :: Ordinary ( & final_entry. nested_goals ) ,
@@ -824,14 +821,10 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
824821 // A provisional cache entry is only valid if the current path from its
825822 // highest cycle head to the goal is the same.
826823 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 ( ) ;
831824 Self :: update_parent_goal (
832825 & mut self . stack ,
833826 step_kind_from_parent,
834- next_index ,
827+ 0 ,
835828 heads,
836829 encountered_overflow,
837830 UpdateParentGoalCtxt :: ProvisionalCacheHit ,
@@ -947,7 +940,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
947940 available_depth : AvailableDepth ,
948941 ) -> Option < X :: Result > {
949942 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
951944 . get ( cx, input, available_depth, |nested_goals| {
952945 Self :: candidate_is_applicable (
953946 & self . stack ,
@@ -957,23 +950,19 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
957950 )
958951 } ) ?;
959952
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) ;
964953 // We don't move cycle participants to the global cache, so the
965954 // cycle heads are always empty.
966955 let heads = Default :: default ( ) ;
967956 Self :: update_parent_goal (
968957 & mut self . stack ,
969958 step_kind_from_parent,
970- reached_depth ,
959+ required_depth ,
971960 & heads,
972961 encountered_overflow,
973962 UpdateParentGoalCtxt :: Ordinary ( nested_goals) ,
974963 ) ;
975964
976- debug ! ( ?additional_depth , "global cache hit" ) ;
965+ debug ! ( ?required_depth , "global cache hit" ) ;
977966 Some ( result)
978967 } )
979968 }
@@ -999,10 +988,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
999988
1000989 // Subtle: when encountering a cyclic goal, we still first checked for overflow,
1001990 // so we have to update the reached depth.
1002- let next_index = self . stack . next_index ( ) ;
1003991 let last_index = self . stack . last_index ( ) . unwrap ( ) ;
1004992 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 ) ;
1006994
1007995 last. nested_goals . insert ( input, step_kind_from_parent. into ( ) ) ;
1008996 last. nested_goals . insert ( last. input , PathsToNested :: EMPTY ) ;
@@ -1137,15 +1125,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
11371125 result : X :: Result ,
11381126 dep_node : X :: DepNodeIndex ,
11391127 ) {
1140- let additional_depth = final_entry. reached_depth . as_usize ( ) - self . stack . len ( ) ;
11411128 debug ! ( ?final_entry, ?result, "insert global cache" ) ;
11421129 cx. with_global_cache ( |cache| {
11431130 cache. insert (
11441131 cx,
11451132 input,
11461133 result,
11471134 dep_node,
1148- additional_depth ,
1135+ final_entry . required_depth ,
11491136 final_entry. encountered_overflow ,
11501137 final_entry. nested_goals ,
11511138 )
0 commit comments