@@ -263,6 +263,12 @@ impl CandidateHeadUsages {
263263}
264264
265265#[ derive( Debug , Clone , Copy ) ]
266+ pub enum IncreaseDepthForNested {
267+ Yes ,
268+ No ,
269+ }
270+
271+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord ) ]
266272struct AvailableDepth ( usize ) ;
267273impl AvailableDepth {
268274 /// Returns the remaining depth allowed for nested goals.
@@ -276,6 +282,13 @@ impl AvailableDepth {
276282 stack : & Stack < D :: Cx > ,
277283 ) -> Option < AvailableDepth > {
278284 if let Some ( last) = stack. last ( ) {
285+ match last. increase_depth_for_nested {
286+ IncreaseDepthForNested :: Yes => { }
287+ IncreaseDepthForNested :: No => {
288+ return Some ( last. available_depth ) ;
289+ }
290+ }
291+
279292 if last. available_depth . 0 == 0 {
280293 return None ;
281294 }
@@ -566,7 +579,7 @@ impl<X: Cx> EvaluationResult<X> {
566579 encountered_overflow,
567580 // Unlike `encountered_overflow`, we share `heads`, `required_depth`,
568581 // and `nested_goals` between evaluations.
569- required_depth : final_entry. required_depth ,
582+ required_depth : final_entry. required_depth ( ) ,
570583 heads : final_entry. heads ,
571584 nested_goals : final_entry. nested_goals ,
572585 // We only care about the final result.
@@ -597,7 +610,7 @@ pub struct SearchGraph<D: Delegate<Cx = X>, X: Cx = <D as Delegate>::Cx> {
597610/// don't need to track the nested goals used while computing a provisional
598611/// cache entry.
599612enum UpdateParentGoalCtxt < ' a , X : Cx > {
600- Ordinary ( & ' a NestedGoals < X > ) ,
613+ Ordinary { nested_goals : & ' a NestedGoals < X > , min_reachable_available_depth : AvailableDepth } ,
601614 CycleOnStack ( X :: Input ) ,
602615 ProvisionalCacheHit ,
603616}
@@ -619,13 +632,11 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
619632 fn update_parent_goal (
620633 stack : & mut Stack < X > ,
621634 step_kind_from_parent : PathKind ,
622- required_depth_for_nested : usize ,
623635 heads : impl Iterator < Item = ( StackDepth , CycleHead ) > ,
624636 encountered_overflow : bool ,
625637 context : UpdateParentGoalCtxt < ' _ , X > ,
626638 ) {
627639 if let Some ( ( parent_index, parent) ) = stack. last_mut_with_index ( ) {
628- parent. required_depth = parent. required_depth . max ( required_depth_for_nested + 1 ) ;
629640 parent. encountered_overflow |= encountered_overflow;
630641
631642 for ( head_index, head) in heads {
@@ -650,7 +661,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
650661 }
651662 }
652663 let parent_depends_on_cycle = match context {
653- UpdateParentGoalCtxt :: Ordinary ( nested_goals) => {
664+ UpdateParentGoalCtxt :: Ordinary { nested_goals, min_reachable_available_depth } => {
665+ parent. min_reached_available_depth =
666+ parent. min_reached_available_depth . min ( min_reachable_available_depth) ;
654667 parent. nested_goals . extend_from_child ( step_kind_from_parent, nested_goals) ;
655668 !nested_goals. is_empty ( )
656669 }
@@ -739,8 +752,9 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
739752 input,
740753 step_kind_from_parent,
741754 available_depth,
755+ min_reached_available_depth : available_depth,
742756 provisional_result : None ,
743- required_depth : 0 ,
757+ increase_depth_for_nested : IncreaseDepthForNested :: Yes ,
744758 heads : Default :: default ( ) ,
745759 encountered_overflow : false ,
746760 usages : None ,
@@ -761,6 +775,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
761775 cx : X ,
762776 input : X :: Input ,
763777 step_kind_from_parent : PathKind ,
778+ increase_depth_for_nested : IncreaseDepthForNested ,
764779 inspect : & mut D :: ProofTreeBuilder ,
765780 ) -> X :: Result {
766781 let Some ( available_depth) =
@@ -816,7 +831,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
816831 step_kind_from_parent,
817832 available_depth,
818833 provisional_result : None ,
819- required_depth : 0 ,
834+ min_reached_available_depth : available_depth,
835+ increase_depth_for_nested,
820836 heads : Default :: default ( ) ,
821837 encountered_overflow : false ,
822838 usages : None ,
@@ -838,10 +854,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> {
838854 Self :: update_parent_goal (
839855 & mut self . stack ,
840856 step_kind_from_parent,
841- evaluation_result. required_depth ,
842857 evaluation_result. heads . iter ( ) ,
843858 evaluation_result. encountered_overflow ,
844- UpdateParentGoalCtxt :: Ordinary ( & evaluation_result. nested_goals ) ,
859+ UpdateParentGoalCtxt :: Ordinary {
860+ nested_goals : & evaluation_result. nested_goals ,
861+ min_reachable_available_depth : AvailableDepth (
862+ available_depth. 0 - evaluation_result. required_depth ,
863+ ) ,
864+ } ,
845865 ) ;
846866 let result = evaluation_result. result ;
847867
@@ -1116,7 +1136,6 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
11161136 Self :: update_parent_goal (
11171137 & mut self . stack ,
11181138 step_kind_from_parent,
1119- 0 ,
11201139 heads. iter ( ) ,
11211140 encountered_overflow,
11221141 UpdateParentGoalCtxt :: ProvisionalCacheHit ,
@@ -1239,10 +1258,14 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
12391258 Self :: update_parent_goal (
12401259 & mut self . stack ,
12411260 step_kind_from_parent,
1242- required_depth,
12431261 heads,
12441262 encountered_overflow,
1245- UpdateParentGoalCtxt :: Ordinary ( nested_goals) ,
1263+ UpdateParentGoalCtxt :: Ordinary {
1264+ nested_goals,
1265+ min_reachable_available_depth : AvailableDepth (
1266+ available_depth. 0 - required_depth,
1267+ ) ,
1268+ } ,
12461269 ) ;
12471270
12481271 debug ! ( ?required_depth, "global cache hit" ) ;
@@ -1271,7 +1294,6 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
12711294 Self :: update_parent_goal (
12721295 & mut self . stack ,
12731296 step_kind_from_parent,
1274- 0 ,
12751297 iter:: once ( ( head_index, head) ) ,
12761298 false ,
12771299 UpdateParentGoalCtxt :: CycleOnStack ( input) ,
@@ -1407,7 +1429,8 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D, X> {
14071429 provisional_result : Some ( result) ,
14081430 // We can keep these goals from previous iterations as they are only
14091431 // ever read after finalizing this evaluation.
1410- required_depth : stack_entry. required_depth ,
1432+ min_reached_available_depth : stack_entry. min_reached_available_depth ,
1433+ increase_depth_for_nested : stack_entry. increase_depth_for_nested ,
14111434 heads : stack_entry. heads ,
14121435 nested_goals : stack_entry. nested_goals ,
14131436 // We reset these two fields when rerunning this goal. We could
0 commit comments