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