@@ -212,9 +212,7 @@ where
212212 goal : Goal < I , I :: Predicate > ,
213213 span : I :: Span ,
214214 ) -> ( 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- } )
215+ evaluate_root_goal_for_proof_tree ( self , goal, span)
218216 }
219217}
220218
@@ -324,11 +322,11 @@ where
324322 cx : I ,
325323 search_graph : & ' a mut SearchGraph < D > ,
326324 canonical_input : CanonicalInput < I > ,
327- canonical_goal_evaluation : & mut inspect:: GoalEvaluationBuilder < D > ,
325+ proof_tree_builder : & mut inspect:: ProofTreeBuilder < D > ,
328326 f : impl FnOnce ( & mut EvalCtxt < ' _ , D > , Goal < I , I :: Predicate > ) -> R ,
329327 ) -> R {
330328 let ( ref delegate, input, var_values) = D :: build_with_canonical ( cx, & canonical_input) ;
331-
329+ let inspect = proof_tree_builder . new_evaluation_step ( var_values ) ;
332330 for & ( key, ty) in & input. predefined_opaques_in_body . opaque_types {
333331 let prev = delegate. register_hidden_type_in_storage ( key, ty, I :: Span :: dummy ( ) ) ;
334332 // It may be possible that two entries in the opaque type storage end up
@@ -359,12 +357,12 @@ where
359357 nested_goals : Default :: default ( ) ,
360358 origin_span : I :: Span :: dummy ( ) ,
361359 tainted : Ok ( ( ) ) ,
362- inspect : canonical_goal_evaluation . new_goal_evaluation_step ( var_values ) ,
360+ inspect,
363361 } ;
364362
365363 let result = f ( & mut ecx, input. goal ) ;
366364 ecx. inspect . probe_final_state ( ecx. delegate , ecx. max_input_universe ) ;
367- canonical_goal_evaluation . goal_evaluation_step ( ecx. inspect ) ;
365+ proof_tree_builder . finish_evaluation_step ( ecx. inspect ) ;
368366
369367 // When creating a query response we clone the opaque type constraints
370368 // instead of taking them. This would cause an ICE here, since we have
@@ -434,12 +432,13 @@ where
434432 let opaque_types = self . delegate . clone_opaque_types_lookup_table ( ) ;
435433 let ( goal, opaque_types) = eager_resolve_vars ( self . delegate , ( goal, opaque_types) ) ;
436434
437- let ( orig_values, canonical_goal) = self . canonicalize_goal ( goal, opaque_types) ;
435+ let ( orig_values, canonical_goal) =
436+ Self :: canonicalize_goal ( self . delegate , goal, opaque_types) ;
438437 let canonical_result = self . search_graph . evaluate_goal (
439438 self . cx ( ) ,
440439 canonical_goal,
441440 self . step_kind_for_source ( source) ,
442- & mut inspect:: GoalEvaluationBuilder :: new_noop ( ) ,
441+ & mut inspect:: ProofTreeBuilder :: new_noop ( ) ,
443442 ) ;
444443 let response = match canonical_result {
445444 Err ( e) => return Err ( e) ,
@@ -449,8 +448,13 @@ where
449448 let has_changed =
450449 if !has_only_region_constraints ( response) { HasChanged :: Yes } else { HasChanged :: No } ;
451450
452- let ( normalization_nested_goals, certainty) =
453- self . instantiate_and_apply_query_response ( goal. param_env , & orig_values, response) ;
451+ let ( normalization_nested_goals, certainty) = Self :: instantiate_and_apply_query_response (
452+ self . delegate ,
453+ goal. param_env ,
454+ & orig_values,
455+ response,
456+ self . origin_span ,
457+ ) ;
454458
455459 // FIXME: We previously had an assert here that checked that recomputing
456460 // a goal after applying its constraints did not change its response.
@@ -514,35 +518,6 @@ where
514518 ) )
515519 }
516520
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 = inspect:: GoalEvaluationBuilder :: new ( 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-
546521 pub ( super ) fn compute_goal ( & mut self , goal : Goal < I , I :: Predicate > ) -> QueryResult < I > {
547522 let Goal { param_env, predicate } = goal;
548523 let kind = predicate. kind ( ) ;
@@ -1293,3 +1268,62 @@ where
12931268 if predicate. allow_normalization ( ) { predicate. super_fold_with ( self ) } else { predicate }
12941269 }
12951270}
1271+
1272+ /// Do not call this directly, use the `tcx` query instead.
1273+ pub fn evaluate_root_goal_for_proof_tree_raw_provider <
1274+ D : SolverDelegate < Interner = I > ,
1275+ I : Interner ,
1276+ > (
1277+ cx : I ,
1278+ canonical_goal : CanonicalInput < I > ,
1279+ ) -> ( QueryResult < I > , I :: ProbeRef ) {
1280+ let mut inspect = inspect:: ProofTreeBuilder :: new ( ) ;
1281+ let canonical_result = SearchGraph :: < D > :: evaluate_root_goal_for_proof_tree (
1282+ cx,
1283+ cx. recursion_limit ( ) ,
1284+ canonical_goal,
1285+ & mut inspect,
1286+ ) ;
1287+ let final_revision = inspect. unwrap ( ) ;
1288+ ( canonical_result, cx. mk_probe_ref ( final_revision) )
1289+ }
1290+
1291+ /// Evaluate a goal to build a proof tree.
1292+ ///
1293+ /// This is a copy of [EvalCtxt::evaluate_goal_raw] which avoids relying on the
1294+ /// [EvalCtxt] and uses a separate cache.
1295+ pub ( super ) fn evaluate_root_goal_for_proof_tree < D : SolverDelegate < Interner = I > , I : Interner > (
1296+ delegate : & D ,
1297+ goal : Goal < I , I :: Predicate > ,
1298+ origin_span : I :: Span ,
1299+ ) -> ( Result < NestedNormalizationGoals < I > , NoSolution > , inspect:: GoalEvaluation < I > ) {
1300+ let opaque_types = delegate. clone_opaque_types_lookup_table ( ) ;
1301+ let ( goal, opaque_types) = eager_resolve_vars ( delegate, ( goal, opaque_types) ) ;
1302+
1303+ let ( orig_values, canonical_goal) = EvalCtxt :: canonicalize_goal ( delegate, goal, opaque_types) ;
1304+
1305+ let ( canonical_result, final_revision) =
1306+ delegate. cx ( ) . evaluate_root_goal_for_proof_tree_raw ( canonical_goal) ;
1307+
1308+ let proof_tree = inspect:: GoalEvaluation {
1309+ uncanonicalized_goal : goal,
1310+ orig_values,
1311+ final_revision,
1312+ result : canonical_result,
1313+ } ;
1314+
1315+ let response = match canonical_result {
1316+ Err ( e) => return ( Err ( e) , proof_tree) ,
1317+ Ok ( response) => response,
1318+ } ;
1319+
1320+ let ( normalization_nested_goals, _certainty) = EvalCtxt :: instantiate_and_apply_query_response (
1321+ delegate,
1322+ goal. param_env ,
1323+ & proof_tree. orig_values ,
1324+ response,
1325+ origin_span,
1326+ ) ;
1327+
1328+ ( Ok ( normalization_nested_goals) , proof_tree)
1329+ }
0 commit comments