@@ -22,8 +22,9 @@ use crate::delegate::SolverDelegate;
22
22
use crate :: solve:: inspect:: { self , ProofTreeBuilder } ;
23
23
use crate :: solve:: search_graph:: SearchGraph ;
24
24
use crate :: solve:: {
25
- CanonicalInput , Certainty , FIXPOINT_STEP_LIMIT , Goal , GoalEvaluationKind , GoalSource ,
26
- HasChanged , NestedNormalizationGoals , NoSolution , QueryInput , QueryResult ,
25
+ CanonicalGoalCacheKey , CanonicalInput , Certainty , FIXPOINT_STEP_LIMIT , Goal ,
26
+ GoalEvaluationKind , GoalSource , HasChanged , NestedNormalizationGoals , NoSolution , QueryInput ,
27
+ QueryResult ,
27
28
} ;
28
29
29
30
pub ( super ) mod canonical;
@@ -115,7 +116,7 @@ where
115
116
116
117
pub ( super ) search_graph : & ' a mut SearchGraph < D > ,
117
118
118
- nested_goals : Vec < ( GoalSource , Goal < I , I :: Predicate > ) > ,
119
+ nested_goals : Vec < ( GoalSource , Goal < I , I :: Predicate > , Option < CanonicalGoalCacheKey < I > > ) > ,
119
120
120
121
pub ( super ) origin_span : I :: Span ,
121
122
@@ -147,8 +148,9 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
147
148
goal : Goal < Self :: Interner , <Self :: Interner as Interner >:: Predicate > ,
148
149
generate_proof_tree : GenerateProofTree ,
149
150
span : <Self :: Interner as Interner >:: Span ,
151
+ cache_key : Option < CanonicalGoalCacheKey < Self :: Interner > > ,
150
152
) -> (
151
- Result < ( HasChanged , Certainty ) , NoSolution > ,
153
+ Result < ( HasChanged , Certainty , CanonicalGoalCacheKey < Self :: Interner > ) , NoSolution > ,
152
154
Option < inspect:: GoalEvaluation < Self :: Interner > > ,
153
155
) ;
154
156
@@ -171,8 +173,17 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
171
173
& self ,
172
174
goal : Goal < Self :: Interner , <Self :: Interner as Interner >:: Predicate > ,
173
175
generate_proof_tree : GenerateProofTree ,
176
+ cache_key : Option < CanonicalGoalCacheKey < Self :: Interner > > ,
174
177
) -> (
175
- Result < ( NestedNormalizationGoals < Self :: Interner > , HasChanged , Certainty ) , NoSolution > ,
178
+ Result <
179
+ (
180
+ NestedNormalizationGoals < Self :: Interner > ,
181
+ HasChanged ,
182
+ Certainty ,
183
+ CanonicalGoalCacheKey < Self :: Interner > ,
184
+ ) ,
185
+ NoSolution ,
186
+ > ,
176
187
Option < inspect:: GoalEvaluation < Self :: Interner > > ,
177
188
) ;
178
189
}
@@ -188,9 +199,13 @@ where
188
199
goal : Goal < I , I :: Predicate > ,
189
200
generate_proof_tree : GenerateProofTree ,
190
201
span : I :: Span ,
191
- ) -> ( Result < ( HasChanged , Certainty ) , NoSolution > , Option < inspect:: GoalEvaluation < I > > ) {
202
+ cache_key : Option < CanonicalGoalCacheKey < I > > ,
203
+ ) -> (
204
+ Result < ( HasChanged , Certainty , CanonicalGoalCacheKey < I > ) , NoSolution > ,
205
+ Option < inspect:: GoalEvaluation < I > > ,
206
+ ) {
192
207
EvalCtxt :: enter_root ( self , self . cx ( ) . recursion_limit ( ) , generate_proof_tree, span, |ecx| {
193
- ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal)
208
+ ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, cache_key )
194
209
} )
195
210
}
196
211
@@ -201,7 +216,7 @@ where
201
216
) -> bool {
202
217
self . probe ( || {
203
218
EvalCtxt :: enter_root ( self , root_depth, GenerateProofTree :: No , I :: Span :: dummy ( ) , |ecx| {
204
- ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal)
219
+ ecx. evaluate_goal ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, None )
205
220
} )
206
221
. 0
207
222
} )
@@ -213,16 +228,22 @@ where
213
228
& self ,
214
229
goal : Goal < I , I :: Predicate > ,
215
230
generate_proof_tree : GenerateProofTree ,
231
+ cache_key : Option < CanonicalGoalCacheKey < I > > ,
216
232
) -> (
217
- Result < ( NestedNormalizationGoals < I > , HasChanged , Certainty ) , NoSolution > ,
233
+ Result <
234
+ ( NestedNormalizationGoals < I > , HasChanged , Certainty , CanonicalGoalCacheKey < I > ) ,
235
+ NoSolution ,
236
+ > ,
218
237
Option < inspect:: GoalEvaluation < I > > ,
219
238
) {
220
239
EvalCtxt :: enter_root (
221
240
self ,
222
241
self . cx ( ) . recursion_limit ( ) ,
223
242
generate_proof_tree,
224
243
I :: Span :: dummy ( ) ,
225
- |ecx| ecx. evaluate_goal_raw ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal) ,
244
+ |ecx| {
245
+ ecx. evaluate_goal_raw ( GoalEvaluationKind :: Root , GoalSource :: Misc , goal, cache_key)
246
+ } ,
226
247
)
227
248
}
228
249
}
@@ -447,11 +468,12 @@ where
447
468
goal_evaluation_kind : GoalEvaluationKind ,
448
469
source : GoalSource ,
449
470
goal : Goal < I , I :: Predicate > ,
450
- ) -> Result < ( HasChanged , Certainty ) , NoSolution > {
451
- let ( normalization_nested_goals, has_changed, certainty) =
452
- self . evaluate_goal_raw ( goal_evaluation_kind, source, goal) ?;
471
+ cache_key : Option < CanonicalGoalCacheKey < I > > ,
472
+ ) -> Result < ( HasChanged , Certainty , CanonicalGoalCacheKey < I > ) , NoSolution > {
473
+ let ( normalization_nested_goals, has_changed, certainty, cache_key) =
474
+ self . evaluate_goal_raw ( goal_evaluation_kind, source, goal, cache_key) ?;
453
475
assert ! ( normalization_nested_goals. is_empty( ) ) ;
454
- Ok ( ( has_changed, certainty) )
476
+ Ok ( ( has_changed, certainty, cache_key ) )
455
477
}
456
478
457
479
/// Recursively evaluates `goal`, returning the nested goals in case
@@ -466,8 +488,12 @@ where
466
488
goal_evaluation_kind : GoalEvaluationKind ,
467
489
source : GoalSource ,
468
490
goal : Goal < I , I :: Predicate > ,
469
- ) -> Result < ( NestedNormalizationGoals < I > , HasChanged , Certainty ) , NoSolution > {
470
- let ( orig_values, canonical_goal) = self . canonicalize_goal ( goal) ;
491
+ cache_key : Option < CanonicalGoalCacheKey < I > > ,
492
+ ) -> Result <
493
+ ( NestedNormalizationGoals < I > , HasChanged , Certainty , CanonicalGoalCacheKey < I > ) ,
494
+ NoSolution ,
495
+ > {
496
+ let ( orig_values, canonical_goal) = self . canonicalize_goal ( goal, cache_key) ;
471
497
let mut goal_evaluation =
472
498
self . inspect . new_goal_evaluation ( goal, & orig_values, goal_evaluation_kind) ;
473
499
let canonical_response = EvalCtxt :: evaluate_canonical_goal (
@@ -488,6 +514,7 @@ where
488
514
let has_changed =
489
515
if !has_only_region_constraints ( response) { HasChanged :: Yes } else { HasChanged :: No } ;
490
516
517
+ let cache_orig_values = self . cx ( ) . mk_args ( & orig_values) ;
491
518
let ( normalization_nested_goals, certainty) =
492
519
self . instantiate_and_apply_query_response ( goal. param_env , orig_values, response) ;
493
520
self . inspect . goal_evaluation ( goal_evaluation) ;
@@ -502,7 +529,12 @@ where
502
529
// Once we have decided on how to handle trait-system-refactor-initiative#75,
503
530
// we should re-add an assert here.
504
531
505
- Ok ( ( normalization_nested_goals, has_changed, certainty) )
532
+ Ok ( (
533
+ normalization_nested_goals,
534
+ has_changed,
535
+ certainty,
536
+ CanonicalGoalCacheKey { canonical_goal, orig_values : cache_orig_values } ,
537
+ ) )
506
538
}
507
539
508
540
fn compute_goal ( & mut self , goal : Goal < I , I :: Predicate > ) -> QueryResult < I > {
@@ -602,7 +634,7 @@ where
602
634
let cx = self . cx ( ) ;
603
635
// If this loop did not result in any progress, what's our final certainty.
604
636
let mut unchanged_certainty = Some ( Certainty :: Yes ) ;
605
- for ( source, goal) in mem:: take ( & mut self . nested_goals ) {
637
+ for ( source, goal, cache_key ) in mem:: take ( & mut self . nested_goals ) {
606
638
if let Some ( has_changed) = self . delegate . compute_goal_fast_path ( goal, self . origin_span )
607
639
{
608
640
if matches ! ( has_changed, HasChanged :: Yes ) {
@@ -630,11 +662,16 @@ where
630
662
let unconstrained_goal =
631
663
goal. with ( cx, ty:: NormalizesTo { alias : pred. alias , term : unconstrained_rhs } ) ;
632
664
633
- let ( NestedNormalizationGoals ( nested_goals) , _, certainty) =
634
- self . evaluate_goal_raw ( GoalEvaluationKind :: Nested , source, unconstrained_goal) ?;
665
+ let ( NestedNormalizationGoals ( nested_goals) , _, certainty, _) = self
666
+ . evaluate_goal_raw (
667
+ GoalEvaluationKind :: Nested ,
668
+ source,
669
+ unconstrained_goal,
670
+ None ,
671
+ ) ?;
635
672
// Add the nested goals from normalization to our own nested goals.
636
673
trace ! ( ?nested_goals) ;
637
- self . nested_goals . extend ( nested_goals) ;
674
+ self . nested_goals . extend ( nested_goals. into_iter ( ) . map ( | ( s , g ) | ( s , g , None ) ) ) ;
638
675
639
676
// Finally, equate the goal's RHS with the unconstrained var.
640
677
//
@@ -668,21 +705,21 @@ where
668
705
match certainty {
669
706
Certainty :: Yes => { }
670
707
Certainty :: Maybe ( _) => {
671
- self . nested_goals . push ( ( source, with_resolved_vars) ) ;
708
+ self . nested_goals . push ( ( source, with_resolved_vars, None ) ) ;
672
709
unchanged_certainty = unchanged_certainty. map ( |c| c. and ( certainty) ) ;
673
710
}
674
711
}
675
712
} else {
676
- let ( has_changed, certainty) =
677
- self . evaluate_goal ( GoalEvaluationKind :: Nested , source, goal) ?;
713
+ let ( has_changed, certainty, cache_key ) =
714
+ self . evaluate_goal ( GoalEvaluationKind :: Nested , source, goal, cache_key ) ?;
678
715
if has_changed == HasChanged :: Yes {
679
716
unchanged_certainty = None ;
680
717
}
681
718
682
719
match certainty {
683
720
Certainty :: Yes => { }
684
721
Certainty :: Maybe ( _) => {
685
- self . nested_goals . push ( ( source, goal) ) ;
722
+ self . nested_goals . push ( ( source, goal, Some ( cache_key ) ) ) ;
686
723
unchanged_certainty = unchanged_certainty. map ( |c| c. and ( certainty) ) ;
687
724
}
688
725
}
@@ -706,7 +743,7 @@ where
706
743
goal. predicate =
707
744
goal. predicate . fold_with ( & mut ReplaceAliasWithInfer :: new ( self , source, goal. param_env ) ) ;
708
745
self . inspect . add_goal ( self . delegate , self . max_input_universe , source, goal) ;
709
- self . nested_goals . push ( ( source, goal) ) ;
746
+ self . nested_goals . push ( ( source, goal, None ) ) ;
710
747
}
711
748
712
749
#[ instrument( level = "trace" , skip( self , goals) ) ]
0 commit comments