@@ -43,7 +43,16 @@ pub trait ObligationProcessor {
43
43
obligation : & mut Self :: Obligation )
44
44
-> Result < Option < Vec < Self :: Obligation > > , Self :: Error > ;
45
45
46
- fn process_backedge < ' c , I > ( & mut self , cycle : I ,
46
+ /// As we do the cycle check, we invoke this callback when we
47
+ /// encounter an actual cycle. `cycle` is an iterator that starts
48
+ /// at the start of the cycle in the stack and walks **toward the
49
+ /// top**.
50
+ ///
51
+ /// In other words, if we had O1 which required O2 which required
52
+ /// O3 which required O1, we would give an iterator yielding O1,
53
+ /// O2, O3 (O1 is not yielded twice).
54
+ fn process_backedge < ' c , I > ( & mut self ,
55
+ cycle : I ,
47
56
_marker : PhantomData < & ' c Self :: Obligation > )
48
57
where I : Clone + Iterator < Item =& ' c Self :: Obligation > ;
49
58
}
@@ -239,8 +248,8 @@ impl<O: ForestObligation> ObligationForest<O> {
239
248
}
240
249
}
241
250
Entry :: Vacant ( v) => {
242
- debug ! ( "register_obligation_at({:?}, {:?}) - ok" ,
243
- obligation, parent) ;
251
+ debug ! ( "register_obligation_at({:?}, {:?}) - ok, new index is {} " ,
252
+ obligation, parent, self . nodes . len ( ) ) ;
244
253
v. insert ( NodeIndex :: new ( self . nodes . len ( ) ) ) ;
245
254
self . cache_list . push ( obligation. as_predicate ( ) . clone ( ) ) ;
246
255
self . nodes . push ( Node :: new ( parent, obligation) ) ;
@@ -376,6 +385,9 @@ impl<O: ForestObligation> ObligationForest<O> {
376
385
where P : ObligationProcessor < Obligation =O >
377
386
{
378
387
let mut stack = self . scratch . take ( ) . unwrap ( ) ;
388
+ debug_assert ! ( stack. is_empty( ) ) ;
389
+
390
+ debug ! ( "process_cycles()" ) ;
379
391
380
392
for index in 0 ..self . nodes . len ( ) {
381
393
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
@@ -389,6 +401,9 @@ impl<O: ForestObligation> ObligationForest<O> {
389
401
}
390
402
}
391
403
404
+ debug ! ( "process_cycles: complete" ) ;
405
+
406
+ debug_assert ! ( stack. is_empty( ) ) ;
392
407
self . scratch = Some ( stack) ;
393
408
}
394
409
@@ -402,21 +417,6 @@ impl<O: ForestObligation> ObligationForest<O> {
402
417
NodeState :: OnDfsStack => {
403
418
let index =
404
419
stack. iter ( ) . rposition ( |n| * n == index) . unwrap ( ) ;
405
- // I need a Clone closure
406
- #[ derive( Clone ) ]
407
- struct GetObligation < ' a , O : ' a > ( & ' a [ Node < O > ] ) ;
408
- impl < ' a , ' b , O > FnOnce < ( & ' b usize , ) > for GetObligation < ' a , O > {
409
- type Output = & ' a O ;
410
- extern "rust-call" fn call_once ( self , args : ( & ' b usize , ) ) -> & ' a O {
411
- & self . 0 [ * args. 0 ] . obligation
412
- }
413
- }
414
- impl < ' a , ' b , O > FnMut < ( & ' b usize , ) > for GetObligation < ' a , O > {
415
- extern "rust-call" fn call_mut ( & mut self , args : ( & ' b usize , ) ) -> & ' a O {
416
- & self . 0 [ * args. 0 ] . obligation
417
- }
418
- }
419
-
420
420
processor. process_backedge ( stack[ index..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
421
421
PhantomData ) ;
422
422
}
@@ -645,3 +645,20 @@ impl<O> Node<O> {
645
645
}
646
646
}
647
647
}
648
+
649
+ // I need a Clone closure
650
+ #[ derive( Clone ) ]
651
+ struct GetObligation < ' a , O : ' a > ( & ' a [ Node < O > ] ) ;
652
+
653
+ impl < ' a , ' b , O > FnOnce < ( & ' b usize , ) > for GetObligation < ' a , O > {
654
+ type Output = & ' a O ;
655
+ extern "rust-call" fn call_once ( self , args : ( & ' b usize , ) ) -> & ' a O {
656
+ & self . 0 [ * args. 0 ] . obligation
657
+ }
658
+ }
659
+
660
+ impl < ' a , ' b , O > FnMut < ( & ' b usize , ) > for GetObligation < ' a , O > {
661
+ extern "rust-call" fn call_mut ( & mut self , args : ( & ' b usize , ) ) -> & ' a O {
662
+ & self . 0 [ * args. 0 ] . obligation
663
+ }
664
+ }
0 commit comments