@@ -23,8 +23,7 @@ use crate::solve::inspect::{self, ProofTreeBuilder};
2323use crate :: solve:: search_graph:: SearchGraph ;
2424use crate :: solve:: {
2525 CanonicalInput , Certainty , FIXPOINT_STEP_LIMIT , Goal , GoalEvaluationKind , GoalSource ,
26- HasChanged , NestedNormalizationGoals , NoSolution , PredefinedOpaquesData , QueryInput ,
27- QueryResult ,
26+ HasChanged , NestedNormalizationGoals , NoSolution , QueryInput , QueryResult ,
2827} ;
2928
3029pub ( super ) mod canonical;
9998 current_goal_kind : CurrentGoalKind ,
10099 pub ( super ) var_values : CanonicalVarValues < I > ,
101100
102- predefined_opaques_in_body : I :: PredefinedOpaques ,
103-
104101 /// The highest universe index nameable by the caller.
105102 ///
106103 /// When we enter a new binder inside of the query we create new universes
@@ -111,6 +108,10 @@ where
111108 /// if we have a coinductive cycle and because that's the only way we can return
112109 /// new placeholders to the caller.
113110 pub ( super ) max_input_universe : ty:: UniverseIndex ,
111+ /// The opaque types from the canonical input. We only need to return opaque types
112+ /// which have been added to the storage while evaluating this goal.
113+ pub ( super ) initial_opaque_types_storage_num_entries :
114+ <D :: Infcx as InferCtxtLike >:: OpaqueTypeStorageEntries ,
114115
115116 pub ( super ) search_graph : & ' a mut SearchGraph < D > ,
116117
@@ -305,10 +306,8 @@ where
305306
306307 // Only relevant when canonicalizing the response,
307308 // which we don't do within this evaluation context.
308- predefined_opaques_in_body : delegate
309- . cx ( )
310- . mk_predefined_opaques_in_body ( PredefinedOpaquesData :: default ( ) ) ,
311309 max_input_universe : ty:: UniverseIndex :: ROOT ,
310+ initial_opaque_types_storage_num_entries : Default :: default ( ) ,
312311 variables : Default :: default ( ) ,
313312 var_values : CanonicalVarValues :: dummy ( ) ,
314313 current_goal_kind : CurrentGoalKind :: Misc ,
@@ -342,25 +341,10 @@ where
342341 canonical_goal_evaluation : & mut ProofTreeBuilder < D > ,
343342 f : impl FnOnce ( & mut EvalCtxt < ' _ , D > , Goal < I , I :: Predicate > ) -> R ,
344343 ) -> R {
345- let ( ref delegate, input, var_values) =
346- SolverDelegate :: build_with_canonical ( cx, & canonical_input) ;
347-
348- let mut ecx = EvalCtxt {
349- delegate,
350- variables : canonical_input. canonical . variables ,
351- var_values,
352- current_goal_kind : CurrentGoalKind :: from_query_input ( cx, input) ,
353- predefined_opaques_in_body : input. predefined_opaques_in_body ,
354- max_input_universe : canonical_input. canonical . max_universe ,
355- search_graph,
356- nested_goals : Default :: default ( ) ,
357- origin_span : I :: Span :: dummy ( ) ,
358- tainted : Ok ( ( ) ) ,
359- inspect : canonical_goal_evaluation. new_goal_evaluation_step ( var_values) ,
360- } ;
344+ let ( ref delegate, input, var_values) = D :: build_with_canonical ( cx, & canonical_input) ;
361345
362346 for & ( key, ty) in & input. predefined_opaques_in_body . opaque_types {
363- let prev = ecx . delegate . register_hidden_type_in_storage ( key, ty, ecx . origin_span ) ;
347+ let prev = delegate. register_hidden_type_in_storage ( key, ty, I :: Span :: dummy ( ) ) ;
364348 // It may be possible that two entries in the opaque type storage end up
365349 // with the same key after resolving contained inference variables.
366350 //
@@ -373,13 +357,24 @@ where
373357 // the canonical input. This is more annoying to implement and may cause a
374358 // perf regression, so we do it inside of the query for now.
375359 if let Some ( prev) = prev {
376- debug ! ( ?key, ?ty, ?prev, "ignore duplicate in `opaque_type_storage `" ) ;
360+ debug ! ( ?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage `" ) ;
377361 }
378362 }
379363
380- if !ecx. nested_goals . is_empty ( ) {
381- panic ! ( "prepopulating opaque types shouldn't add goals: {:?}" , ecx. nested_goals) ;
382- }
364+ let initial_opaque_types_storage_num_entries = delegate. opaque_types_storage_num_entries ( ) ;
365+ let mut ecx = EvalCtxt {
366+ delegate,
367+ variables : canonical_input. canonical . variables ,
368+ var_values,
369+ current_goal_kind : CurrentGoalKind :: from_query_input ( cx, input) ,
370+ max_input_universe : canonical_input. canonical . max_universe ,
371+ initial_opaque_types_storage_num_entries,
372+ search_graph,
373+ nested_goals : Default :: default ( ) ,
374+ origin_span : I :: Span :: dummy ( ) ,
375+ tainted : Ok ( ( ) ) ,
376+ inspect : canonical_goal_evaluation. new_goal_evaluation_step ( var_values) ,
377+ } ;
383378
384379 let result = f ( & mut ecx, input. goal ) ;
385380 ecx. inspect . probe_final_state ( ecx. delegate , ecx. max_input_universe ) ;
0 commit comments