@@ -24,9 +24,8 @@ use crate::solve::inspect::{self, ProofTreeBuilder};
2424use crate :: solve:: search_graph:: SearchGraph ;
2525use crate :: solve:: ty:: may_use_unstable_feature;
2626use crate :: solve:: {
27- CanonicalInput , Certainty , FIXPOINT_STEP_LIMIT , Goal , GoalEvaluation , GoalEvaluationKind ,
28- GoalSource , GoalStalledOn , HasChanged , NestedNormalizationGoals , NoSolution , QueryInput ,
29- QueryResult ,
27+ CanonicalInput , Certainty , FIXPOINT_STEP_LIMIT , Goal , GoalEvaluation , GoalSource ,
28+ GoalStalledOn , HasChanged , NestedNormalizationGoals , NoSolution , QueryInput , QueryResult ,
3029} ;
3130
3231pub ( super ) mod canonical;
@@ -172,10 +171,7 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
172171 goal : Goal < Self :: Interner , <Self :: Interner as Interner >:: Predicate > ,
173172 span : <Self :: Interner as Interner >:: Span ,
174173 ) -> (
175- Result <
176- ( NestedNormalizationGoals < Self :: Interner > , GoalEvaluation < Self :: Interner > ) ,
177- NoSolution ,
178- > ,
174+ Result < NestedNormalizationGoals < Self :: Interner > , NoSolution > ,
179175 inspect:: GoalEvaluation < Self :: Interner > ,
180176 ) ;
181177}
@@ -192,14 +188,9 @@ where
192188 span : I :: Span ,
193189 stalled_on : Option < GoalStalledOn < I > > ,
194190 ) -> Result < GoalEvaluation < I > , NoSolution > {
195- EvalCtxt :: enter_root (
196- self ,
197- self . cx ( ) . recursion_limit ( ) ,
198- GenerateProofTree :: No ,
199- span,
200- |ecx| ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, stalled_on) ,
201- )
202- . 0
191+ EvalCtxt :: enter_root ( self , self . cx ( ) . recursion_limit ( ) , span, |ecx| {
192+ ecx. evaluate_goal ( GoalSource :: Misc , goal, stalled_on)
193+ } )
203194 }
204195
205196 fn root_goal_may_hold_with_depth (
@@ -208,10 +199,9 @@ where
208199 goal : Goal < Self :: Interner , <Self :: Interner as Interner >:: Predicate > ,
209200 ) -> bool {
210201 self . probe ( || {
211- EvalCtxt :: enter_root ( self , root_depth, GenerateProofTree :: No , I :: Span :: dummy ( ) , |ecx| {
212- ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, None )
202+ EvalCtxt :: enter_root ( self , root_depth, I :: Span :: dummy ( ) , |ecx| {
203+ ecx. evaluate_goal ( GoalSource :: Misc , goal, None )
213204 } )
214- . 0
215205 } )
216206 . is_ok ( )
217207 }
@@ -221,18 +211,10 @@ where
221211 & self ,
222212 goal : Goal < I , I :: Predicate > ,
223213 span : I :: Span ,
224- ) -> (
225- Result < ( NestedNormalizationGoals < I > , GoalEvaluation < I > ) , NoSolution > ,
226- inspect:: GoalEvaluation < I > ,
227- ) {
228- let ( result, proof_tree) = EvalCtxt :: enter_root (
229- self ,
230- self . cx ( ) . recursion_limit ( ) ,
231- GenerateProofTree :: Yes ,
232- span,
233- |ecx| ecx. evaluate_goal_raw ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, None ) ,
234- ) ;
235- ( result, proof_tree. unwrap ( ) )
214+ ) -> ( Result < NestedNormalizationGoals < I > , NoSolution > , inspect:: GoalEvaluation < I > ) {
215+ EvalCtxt :: enter_root ( self , self . cx ( ) . recursion_limit ( ) , span, |ecx| {
216+ ecx. evaluate_goal_for_proof_tree ( goal)
217+ } )
236218 }
237219}
238220
@@ -301,17 +283,16 @@ where
301283 pub ( super ) fn enter_root < R > (
302284 delegate : & D ,
303285 root_depth : usize ,
304- generate_proof_tree : GenerateProofTree ,
305286 origin_span : I :: Span ,
306287 f : impl FnOnce ( & mut EvalCtxt < ' _ , D > ) -> R ,
307- ) -> ( R , Option < inspect :: GoalEvaluation < I > > ) {
288+ ) -> R {
308289 let mut search_graph = SearchGraph :: new ( root_depth) ;
309290
310291 let mut ecx = EvalCtxt {
311292 delegate,
312293 search_graph : & mut search_graph,
313294 nested_goals : Default :: default ( ) ,
314- inspect : ProofTreeBuilder :: new_maybe_root ( generate_proof_tree ) ,
295+ inspect : ProofTreeBuilder :: new_noop ( ) ,
315296
316297 // Only relevant when canonicalizing the response,
317298 // which we don't do within this evaluation context.
@@ -324,15 +305,12 @@ where
324305 tainted : Ok ( ( ) ) ,
325306 } ;
326307 let result = f ( & mut ecx) ;
327-
328- let proof_tree = ecx. inspect . finalize ( ) ;
329308 assert ! (
330309 ecx. nested_goals. is_empty( ) ,
331310 "root `EvalCtxt` should not have any goals added to it"
332311 ) ;
333-
334312 assert ! ( search_graph. is_empty( ) ) ;
335- ( result, proof_tree )
313+ result
336314 }
337315
338316 /// Creates a nested evaluation context that shares the same search graph as the
@@ -406,13 +384,12 @@ where
406384 /// been constrained and the certainty of the result.
407385 fn evaluate_goal (
408386 & mut self ,
409- goal_evaluation_kind : GoalEvaluationKind ,
410387 source : GoalSource ,
411388 goal : Goal < I , I :: Predicate > ,
412389 stalled_on : Option < GoalStalledOn < I > > ,
413390 ) -> Result < GoalEvaluation < I > , NoSolution > {
414391 let ( normalization_nested_goals, goal_evaluation) =
415- self . evaluate_goal_raw ( goal_evaluation_kind , source, goal, stalled_on) ?;
392+ self . evaluate_goal_raw ( source, goal, stalled_on) ?;
416393 assert ! ( normalization_nested_goals. is_empty( ) ) ;
417394 Ok ( goal_evaluation)
418395 }
@@ -426,7 +403,6 @@ where
426403 /// storage.
427404 pub ( super ) fn evaluate_goal_raw (
428405 & mut self ,
429- goal_evaluation_kind : GoalEvaluationKind ,
430406 source : GoalSource ,
431407 goal : Goal < I , I :: Predicate > ,
432408 stalled_on : Option < GoalStalledOn < I > > ,
@@ -459,16 +435,12 @@ where
459435 let ( goal, opaque_types) = eager_resolve_vars ( self . delegate , ( goal, opaque_types) ) ;
460436
461437 let ( orig_values, canonical_goal) = self . canonicalize_goal ( goal, opaque_types) ;
462- let mut goal_evaluation =
463- self . inspect . new_goal_evaluation ( goal, & orig_values, goal_evaluation_kind) ;
464438 let canonical_result = self . search_graph . evaluate_goal (
465439 self . cx ( ) ,
466440 canonical_goal,
467441 self . step_kind_for_source ( source) ,
468- & mut goal_evaluation ,
442+ & mut ProofTreeBuilder :: new_noop ( ) ,
469443 ) ;
470- goal_evaluation. query_result ( canonical_result) ;
471- self . inspect . goal_evaluation ( goal_evaluation) ;
472444 let response = match canonical_result {
473445 Err ( e) => return Err ( e) ,
474446 Ok ( response) => response,
@@ -542,6 +514,35 @@ where
542514 ) )
543515 }
544516
517+ /// Evaluate a goal to build a proof tree. This is a copy of [EvalCtxt::evaluate_goal_raw].
518+ pub ( super ) fn evaluate_goal_for_proof_tree (
519+ & mut self ,
520+ goal : Goal < I , I :: Predicate > ,
521+ ) -> ( Result < NestedNormalizationGoals < I > , NoSolution > , inspect:: GoalEvaluation < I > ) {
522+ let opaque_types = self . delegate . clone_opaque_types_lookup_table ( ) ;
523+ let ( goal, opaque_types) = eager_resolve_vars ( self . delegate , ( goal, opaque_types) ) ;
524+
525+ let ( orig_values, canonical_goal) = self . canonicalize_goal ( goal, opaque_types) ;
526+ let mut goal_evaluation = ProofTreeBuilder :: new_goal_evaluation ( goal, & orig_values) ;
527+ let canonical_result = self . search_graph . evaluate_goal (
528+ self . cx ( ) ,
529+ canonical_goal,
530+ self . step_kind_for_source ( GoalSource :: Misc ) ,
531+ & mut goal_evaluation,
532+ ) ;
533+ goal_evaluation. query_result ( canonical_result) ;
534+ let proof_tree = goal_evaluation. finalize ( ) ;
535+ let response = match canonical_result {
536+ Err ( e) => return ( Err ( e) , proof_tree) ,
537+ Ok ( response) => response,
538+ } ;
539+
540+ let ( normalization_nested_goals, _certainty) =
541+ self . instantiate_and_apply_query_response ( goal. param_env , & orig_values, response) ;
542+
543+ ( Ok ( normalization_nested_goals) , proof_tree)
544+ }
545+
545546 pub ( super ) fn compute_goal ( & mut self , goal : Goal < I , I :: Predicate > ) -> QueryResult < I > {
546547 let Goal { param_env, predicate } = goal;
547548 let kind = predicate. kind ( ) ;
@@ -676,12 +677,7 @@ where
676677 let (
677678 NestedNormalizationGoals ( nested_goals) ,
678679 GoalEvaluation { goal, certainty, stalled_on, has_changed : _ } ,
679- ) = self . evaluate_goal_raw (
680- GoalEvaluationKind :: Nested ,
681- source,
682- unconstrained_goal,
683- stalled_on,
684- ) ?;
680+ ) = self . evaluate_goal_raw ( source, unconstrained_goal, stalled_on) ?;
685681 // Add the nested goals from normalization to our own nested goals.
686682 trace ! ( ?nested_goals) ;
687683 self . nested_goals . extend ( nested_goals. into_iter ( ) . map ( |( s, g) | ( s, g, None ) ) ) ;
@@ -734,7 +730,7 @@ where
734730 }
735731 } else {
736732 let GoalEvaluation { goal, certainty, has_changed, stalled_on } =
737- self . evaluate_goal ( GoalEvaluationKind :: Nested , source, goal, stalled_on) ?;
733+ self . evaluate_goal ( source, goal, stalled_on) ?;
738734 if has_changed == HasChanged :: Yes {
739735 unchanged_certainty = None ;
740736 }
0 commit comments