5
5
//! see the comment on [ProofTreeBuilder].
6
6
7
7
use std:: marker:: PhantomData ;
8
- use std:: mem;
9
8
10
9
use derive_where:: derive_where;
11
10
use rustc_type_ir:: inherent:: * ;
12
- use rustc_type_ir:: { self as ty, search_graph , Interner } ;
11
+ use rustc_type_ir:: { self as ty, Interner } ;
13
12
14
13
use crate :: delegate:: SolverDelegate ;
15
14
use crate :: solve:: eval_ctxt:: canonical;
@@ -94,31 +93,10 @@ impl<I: Interner> WipGoalEvaluation<I> {
94
93
}
95
94
}
96
95
97
- #[ derive_where( PartialEq , Eq ; I : Interner ) ]
98
- pub ( in crate :: solve) enum WipCanonicalGoalEvaluationKind < I : Interner > {
99
- Overflow ,
100
- CycleInStack ,
101
- ProvisionalCacheHit ,
102
- Interned { final_revision : I :: CanonicalGoalEvaluationStepRef } ,
103
- }
104
-
105
- impl < I : Interner > std:: fmt:: Debug for WipCanonicalGoalEvaluationKind < I > {
106
- fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
107
- match self {
108
- Self :: Overflow => write ! ( f, "Overflow" ) ,
109
- Self :: CycleInStack => write ! ( f, "CycleInStack" ) ,
110
- Self :: ProvisionalCacheHit => write ! ( f, "ProvisionalCacheHit" ) ,
111
- Self :: Interned { final_revision : _ } => {
112
- f. debug_struct ( "Interned" ) . finish_non_exhaustive ( )
113
- }
114
- }
115
- }
116
- }
117
-
118
96
#[ derive_where( PartialEq , Eq , Debug ; I : Interner ) ]
119
97
struct WipCanonicalGoalEvaluation < I : Interner > {
120
98
goal : CanonicalInput < I > ,
121
- kind : Option < WipCanonicalGoalEvaluationKind < I > > ,
99
+ encountered_overflow : bool ,
122
100
/// Only used for uncached goals. After we finished evaluating
123
101
/// the goal, this is interned and moved into `kind`.
124
102
final_revision : Option < WipCanonicalGoalEvaluationStep < I > > ,
@@ -127,25 +105,17 @@ struct WipCanonicalGoalEvaluation<I: Interner> {
127
105
128
106
impl < I : Interner > WipCanonicalGoalEvaluation < I > {
129
107
fn finalize ( self ) -> inspect:: CanonicalGoalEvaluation < I > {
130
- // We've already interned the final revision in
131
- // `fn finalize_canonical_goal_evaluation`.
132
- assert ! ( self . final_revision. is_none( ) ) ;
133
- let kind = match self . kind . unwrap ( ) {
134
- WipCanonicalGoalEvaluationKind :: Overflow => {
108
+ inspect:: CanonicalGoalEvaluation {
109
+ goal : self . goal ,
110
+ kind : if self . encountered_overflow {
111
+ assert ! ( self . final_revision. is_none( ) ) ;
135
112
inspect:: CanonicalGoalEvaluationKind :: Overflow
136
- }
137
- WipCanonicalGoalEvaluationKind :: CycleInStack => {
138
- inspect:: CanonicalGoalEvaluationKind :: CycleInStack
139
- }
140
- WipCanonicalGoalEvaluationKind :: ProvisionalCacheHit => {
141
- inspect:: CanonicalGoalEvaluationKind :: ProvisionalCacheHit
142
- }
143
- WipCanonicalGoalEvaluationKind :: Interned { final_revision } => {
113
+ } else {
114
+ let final_revision = self . final_revision . unwrap ( ) . finalize ( ) ;
144
115
inspect:: CanonicalGoalEvaluationKind :: Evaluation { final_revision }
145
- }
146
- } ;
147
-
148
- inspect:: CanonicalGoalEvaluation { goal : self . goal , kind, result : self . result . unwrap ( ) }
116
+ } ,
117
+ result : self . result . unwrap ( ) ,
118
+ }
149
119
}
150
120
}
151
121
@@ -308,7 +278,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
308
278
) -> ProofTreeBuilder < D > {
309
279
self . nested ( || WipCanonicalGoalEvaluation {
310
280
goal,
311
- kind : None ,
281
+ encountered_overflow : false ,
312
282
final_revision : None ,
313
283
result : None ,
314
284
} )
@@ -329,11 +299,11 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
329
299
}
330
300
}
331
301
332
- pub fn canonical_goal_evaluation_kind ( & mut self , kind : WipCanonicalGoalEvaluationKind < I > ) {
302
+ pub fn canonical_goal_evaluation_overflow ( & mut self ) {
333
303
if let Some ( this) = self . as_mut ( ) {
334
304
match this {
335
305
DebugSolver :: CanonicalGoalEvaluation ( canonical_goal_evaluation) => {
336
- assert_eq ! ( canonical_goal_evaluation. kind . replace ( kind ) , None ) ;
306
+ canonical_goal_evaluation. encountered_overflow = true ;
337
307
}
338
308
_ => unreachable ! ( ) ,
339
309
} ;
@@ -547,51 +517,3 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
547
517
}
548
518
}
549
519
}
550
-
551
- impl < D , I > search_graph:: ProofTreeBuilder < I > for ProofTreeBuilder < D >
552
- where
553
- D : SolverDelegate < Interner = I > ,
554
- I : Interner ,
555
- {
556
- fn try_apply_proof_tree (
557
- & mut self ,
558
- proof_tree : Option < I :: CanonicalGoalEvaluationStepRef > ,
559
- ) -> bool {
560
- if !self . is_noop ( ) {
561
- if let Some ( final_revision) = proof_tree {
562
- let kind = WipCanonicalGoalEvaluationKind :: Interned { final_revision } ;
563
- self . canonical_goal_evaluation_kind ( kind) ;
564
- true
565
- } else {
566
- false
567
- }
568
- } else {
569
- true
570
- }
571
- }
572
-
573
- fn on_provisional_cache_hit ( & mut self ) {
574
- self . canonical_goal_evaluation_kind ( WipCanonicalGoalEvaluationKind :: ProvisionalCacheHit ) ;
575
- }
576
-
577
- fn on_cycle_in_stack ( & mut self ) {
578
- self . canonical_goal_evaluation_kind ( WipCanonicalGoalEvaluationKind :: CycleInStack ) ;
579
- }
580
-
581
- fn finalize_canonical_goal_evaluation (
582
- & mut self ,
583
- tcx : I ,
584
- ) -> Option < I :: CanonicalGoalEvaluationStepRef > {
585
- self . as_mut ( ) . map ( |this| match this {
586
- DebugSolver :: CanonicalGoalEvaluation ( evaluation) => {
587
- let final_revision = mem:: take ( & mut evaluation. final_revision ) . unwrap ( ) ;
588
- let final_revision =
589
- tcx. intern_canonical_goal_evaluation_step ( final_revision. finalize ( ) ) ;
590
- let kind = WipCanonicalGoalEvaluationKind :: Interned { final_revision } ;
591
- assert_eq ! ( evaluation. kind. replace( kind) , None ) ;
592
- final_revision
593
- }
594
- _ => unreachable ! ( ) ,
595
- } )
596
- }
597
- }
0 commit comments