55//! see the comment on [ProofTreeBuilder].
66
77use std:: marker:: PhantomData ;
8- use std:: mem;
98
109use derive_where:: derive_where;
1110use rustc_type_ir:: inherent:: * ;
12- use rustc_type_ir:: { self as ty, search_graph , Interner } ;
11+ use rustc_type_ir:: { self as ty, Interner } ;
1312
1413use crate :: delegate:: SolverDelegate ;
1514use crate :: solve:: eval_ctxt:: canonical;
@@ -94,31 +93,10 @@ impl<I: Interner> WipGoalEvaluation<I> {
9493 }
9594}
9695
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-
11896#[ derive_where( PartialEq , Eq , Debug ; I : Interner ) ]
11997struct WipCanonicalGoalEvaluation < I : Interner > {
12098 goal : CanonicalInput < I > ,
121- kind : Option < WipCanonicalGoalEvaluationKind < I > > ,
99+ encountered_overflow : bool ,
122100 /// Only used for uncached goals. After we finished evaluating
123101 /// the goal, this is interned and moved into `kind`.
124102 final_revision : Option < WipCanonicalGoalEvaluationStep < I > > ,
@@ -127,25 +105,17 @@ struct WipCanonicalGoalEvaluation<I: Interner> {
127105
128106impl < I : Interner > WipCanonicalGoalEvaluation < I > {
129107 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( ) ) ;
135112 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 ( ) ;
144115 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+ }
149119 }
150120}
151121
@@ -308,7 +278,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
308278 ) -> ProofTreeBuilder < D > {
309279 self . nested ( || WipCanonicalGoalEvaluation {
310280 goal,
311- kind : None ,
281+ encountered_overflow : false ,
312282 final_revision : None ,
313283 result : None ,
314284 } )
@@ -329,11 +299,11 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
329299 }
330300 }
331301
332- pub fn canonical_goal_evaluation_kind ( & mut self , kind : WipCanonicalGoalEvaluationKind < I > ) {
302+ pub fn canonical_goal_evaluation_overflow ( & mut self ) {
333303 if let Some ( this) = self . as_mut ( ) {
334304 match this {
335305 DebugSolver :: CanonicalGoalEvaluation ( canonical_goal_evaluation) => {
336- assert_eq ! ( canonical_goal_evaluation. kind . replace ( kind ) , None ) ;
306+ canonical_goal_evaluation. encountered_overflow = true ;
337307 }
338308 _ => unreachable ! ( ) ,
339309 } ;
@@ -547,51 +517,3 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> ProofTreeBuilder<D> {
547517 }
548518 }
549519}
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