@@ -235,10 +235,6 @@ enum NodeState {
235235 /// This obligation was resolved to an error. Error nodes are
236236 /// removed from the vector by the compression step.
237237 Error ,
238-
239- /// This is a temporary state used in DFS loops to detect cycles,
240- /// it should not exist outside of these DFSes.
241- OnDfsStack ,
242238}
243239
244240#[ derive( Debug ) ]
@@ -491,7 +487,6 @@ impl<O: ForestObligation> ObligationForest<O> {
491487 NodeState :: Pending => { } ,
492488 NodeState :: Success => self . find_cycles_from_node ( & mut stack, processor, index) ,
493489 NodeState :: Waiting | NodeState :: Done | NodeState :: Error => { } ,
494- NodeState :: OnDfsStack => self . find_cycles_from_node ( & mut stack, processor, index) ,
495490 }
496491 }
497492
@@ -506,20 +501,25 @@ impl<O: ForestObligation> ObligationForest<O> {
506501 {
507502 let node = & self . nodes [ index] ;
508503 match node. state . get ( ) {
509- NodeState :: OnDfsStack => {
510- let rpos = stack. iter ( ) . rposition ( |& n| n == index) . unwrap ( ) ;
511- processor. process_backedge ( stack[ rpos..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
512- PhantomData ) ;
513- }
514504 NodeState :: Success => {
515- node. state . set ( NodeState :: OnDfsStack ) ;
516- stack. push ( index) ;
517- for & index in node. dependents . iter ( ) {
518- self . find_cycles_from_node ( stack, processor, index) ;
505+ match stack. iter ( ) . rposition ( |& n| n == index) {
506+ None => {
507+ stack. push ( index) ;
508+ for & index in node. dependents . iter ( ) {
509+ self . find_cycles_from_node ( stack, processor, index) ;
510+ }
511+ stack. pop ( ) ;
512+ node. state . set ( NodeState :: Done ) ;
513+ }
514+ Some ( rpos) => {
515+ // Cycle detected.
516+ processor. process_backedge (
517+ stack[ rpos..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
518+ PhantomData
519+ ) ;
520+ }
519521 }
520- stack. pop ( ) ;
521- node. state . set ( NodeState :: Done ) ;
522- } ,
522+ }
523523 NodeState :: Waiting | NodeState :: Pending => {
524524 // This node is still reachable from some pending node. We
525525 // will get to it when they are all processed.
@@ -598,7 +598,7 @@ impl<O: ForestObligation> ObligationForest<O> {
598598
599599 fn mark_as_waiting_from ( & self , node : & Node < O > ) {
600600 match node. state . get ( ) {
601- NodeState :: Waiting | NodeState :: Error | NodeState :: OnDfsStack => return ,
601+ NodeState :: Waiting | NodeState :: Error => return ,
602602 NodeState :: Success => node. state . set ( NodeState :: Waiting ) ,
603603 NodeState :: Pending | NodeState :: Done => { } ,
604604 }
@@ -659,7 +659,7 @@ impl<O: ForestObligation> ObligationForest<O> {
659659 dead_nodes += 1 ;
660660 self . insert_into_error_cache ( index) ;
661661 }
662- NodeState :: OnDfsStack | NodeState :: Success => unreachable ! ( )
662+ NodeState :: Success => unreachable ! ( )
663663 }
664664 }
665665
0 commit comments