@@ -235,10 +235,6 @@ enum NodeState {
235
235
/// This obligation was resolved to an error. Error nodes are
236
236
/// removed from the vector by the compression step.
237
237
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 ,
242
238
}
243
239
244
240
#[ derive( Debug ) ]
@@ -491,7 +487,6 @@ impl<O: ForestObligation> ObligationForest<O> {
491
487
NodeState :: Pending => { } ,
492
488
NodeState :: Success => self . find_cycles_from_node ( & mut stack, processor, index) ,
493
489
NodeState :: Waiting | NodeState :: Done | NodeState :: Error => { } ,
494
- NodeState :: OnDfsStack => self . find_cycles_from_node ( & mut stack, processor, index) ,
495
490
}
496
491
}
497
492
@@ -506,20 +501,25 @@ impl<O: ForestObligation> ObligationForest<O> {
506
501
{
507
502
let node = & self . nodes [ index] ;
508
503
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
- }
514
504
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
+ }
519
521
}
520
- stack. pop ( ) ;
521
- node. state . set ( NodeState :: Done ) ;
522
- } ,
522
+ }
523
523
NodeState :: Waiting | NodeState :: Pending => {
524
524
// This node is still reachable from some pending node. We
525
525
// will get to it when they are all processed.
@@ -598,7 +598,7 @@ impl<O: ForestObligation> ObligationForest<O> {
598
598
599
599
fn mark_as_waiting_from ( & self , node : & Node < O > ) {
600
600
match node. state . get ( ) {
601
- NodeState :: Waiting | NodeState :: Error | NodeState :: OnDfsStack => return ,
601
+ NodeState :: Waiting | NodeState :: Error => return ,
602
602
NodeState :: Success => node. state . set ( NodeState :: Waiting ) ,
603
603
NodeState :: Pending | NodeState :: Done => { } ,
604
604
}
@@ -659,7 +659,7 @@ impl<O: ForestObligation> ObligationForest<O> {
659
659
dead_nodes += 1 ;
660
660
self . insert_into_error_cache ( index) ;
661
661
}
662
- NodeState :: OnDfsStack | NodeState :: Success => unreachable ! ( )
662
+ NodeState :: Success => unreachable ! ( )
663
663
}
664
664
}
665
665
0 commit comments