@@ -295,14 +295,15 @@ impl<O: ForestObligation> ObligationForest<O> {
295
295
debug ! ( "register_obligation_at({:?}, {:?}) - duplicate of {:?}!" ,
296
296
obligation, parent, o. get( ) ) ;
297
297
let node = & mut self . nodes [ o. get ( ) . get ( ) ] ;
298
- if let Some ( parent ) = parent {
298
+ if let Some ( parent_index ) = parent {
299
299
// If the node is already in `waiting_cache`, it's already
300
300
// been marked with a parent. (It's possible that parent
301
301
// has been cleared by `apply_rewrites`, though.) So just
302
302
// dump `parent` into `node.dependents`... unless it's
303
303
// already in `node.dependents` or `node.parent`.
304
- if !node. dependents . contains ( & parent) && Some ( parent) != node. parent {
305
- node. dependents . push ( parent) ;
304
+ if !node. dependents . contains ( & parent_index) &&
305
+ Some ( parent_index) != node. parent {
306
+ node. dependents . push ( parent_index) ;
306
307
}
307
308
}
308
309
if let NodeState :: Error = node. state . get ( ) {
@@ -316,9 +317,8 @@ impl<O: ForestObligation> ObligationForest<O> {
316
317
obligation, parent, self . nodes. len( ) ) ;
317
318
318
319
let obligation_tree_id = match parent {
319
- Some ( p) => {
320
- let parent_node = & self . nodes [ p. get ( ) ] ;
321
- parent_node. obligation_tree_id
320
+ Some ( parent_index) => {
321
+ self . nodes [ parent_index. get ( ) ] . obligation_tree_id
322
322
}
323
323
None => self . obligation_tree_id_generator . next ( ) . unwrap ( )
324
324
} ;
@@ -346,9 +346,9 @@ impl<O: ForestObligation> ObligationForest<O> {
346
346
/// This cannot be done during a snapshot.
347
347
pub fn to_errors < E : Clone > ( & mut self , error : E ) -> Vec < Error < O , E > > {
348
348
let mut errors = vec ! [ ] ;
349
- for index in 0 ..self . nodes . len ( ) {
350
- if let NodeState :: Pending = self . nodes [ index ] . state . get ( ) {
351
- let backtrace = self . error_at ( index ) ;
349
+ for i in 0 ..self . nodes . len ( ) {
350
+ if let NodeState :: Pending = self . nodes [ i ] . state . get ( ) {
351
+ let backtrace = self . error_at ( i ) ;
352
352
errors. push ( Error {
353
353
error : error. clone ( ) ,
354
354
backtrace,
@@ -393,16 +393,16 @@ impl<O: ForestObligation> ObligationForest<O> {
393
393
let mut errors = vec ! [ ] ;
394
394
let mut stalled = true ;
395
395
396
- for index in 0 ..self . nodes . len ( ) {
397
- debug ! ( "process_obligations: node {} == {:?}" , index , self . nodes[ index ] ) ;
396
+ for i in 0 ..self . nodes . len ( ) {
397
+ debug ! ( "process_obligations: node {} == {:?}" , i , self . nodes[ i ] ) ;
398
398
399
- let result = match self . nodes [ index ] {
399
+ let result = match self . nodes [ i ] {
400
400
Node { ref state, ref mut obligation, .. } if state. get ( ) == NodeState :: Pending =>
401
401
processor. process_obligation ( obligation) ,
402
402
_ => continue
403
403
} ;
404
404
405
- debug ! ( "process_obligations: node {} got result {:?}" , index , result) ;
405
+ debug ! ( "process_obligations: node {} got result {:?}" , i , result) ;
406
406
407
407
match result {
408
408
ProcessResult :: Unchanged => {
@@ -411,23 +411,23 @@ impl<O: ForestObligation> ObligationForest<O> {
411
411
ProcessResult :: Changed ( children) => {
412
412
// We are not (yet) stalled.
413
413
stalled = false ;
414
- self . nodes [ index ] . state . set ( NodeState :: Success ) ;
414
+ self . nodes [ i ] . state . set ( NodeState :: Success ) ;
415
415
416
416
for child in children {
417
417
let st = self . register_obligation_at (
418
418
child,
419
- Some ( NodeIndex :: new ( index ) )
419
+ Some ( NodeIndex :: new ( i ) )
420
420
) ;
421
421
if let Err ( ( ) ) = st {
422
422
// error already reported - propagate it
423
423
// to our node.
424
- self . error_at ( index ) ;
424
+ self . error_at ( i ) ;
425
425
}
426
426
}
427
427
}
428
428
ProcessResult :: Error ( err) => {
429
429
stalled = false ;
430
- let backtrace = self . error_at ( index ) ;
430
+ let backtrace = self . error_at ( i ) ;
431
431
errors. push ( Error {
432
432
error : err,
433
433
backtrace,
@@ -473,15 +473,15 @@ impl<O: ForestObligation> ObligationForest<O> {
473
473
474
474
debug ! ( "process_cycles()" ) ;
475
475
476
- for index in 0 ..self . nodes . len ( ) {
476
+ for i in 0 ..self . nodes . len ( ) {
477
477
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
478
478
// hot and the state is almost always `Pending` or `Waiting`. It's
479
479
// a win to handle the no-op cases immediately to avoid the cost of
480
480
// the function call.
481
- let state = self . nodes [ index ] . state . get ( ) ;
481
+ let state = self . nodes [ i ] . state . get ( ) ;
482
482
match state {
483
483
NodeState :: Waiting | NodeState :: Pending | NodeState :: Done | NodeState :: Error => { } ,
484
- _ => self . find_cycles_from_node ( & mut stack, processor, index ) ,
484
+ _ => self . find_cycles_from_node ( & mut stack, processor, i ) ,
485
485
}
486
486
}
487
487
@@ -491,24 +491,22 @@ impl<O: ForestObligation> ObligationForest<O> {
491
491
self . scratch = Some ( stack) ;
492
492
}
493
493
494
- fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > ,
495
- processor : & mut P , index : usize )
494
+ fn find_cycles_from_node < P > ( & self , stack : & mut Vec < usize > , processor : & mut P , i : usize )
496
495
where P : ObligationProcessor < Obligation =O >
497
496
{
498
- let node = & self . nodes [ index ] ;
497
+ let node = & self . nodes [ i ] ;
499
498
let state = node. state . get ( ) ;
500
499
match state {
501
500
NodeState :: OnDfsStack => {
502
- let index =
503
- stack. iter ( ) . rposition ( |n| * n == index) . unwrap ( ) ;
504
- processor. process_backedge ( stack[ index..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
501
+ let i = stack. iter ( ) . rposition ( |n| * n == i) . unwrap ( ) ;
502
+ processor. process_backedge ( stack[ i..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
505
503
PhantomData ) ;
506
504
}
507
505
NodeState :: Success => {
508
506
node. state . set ( NodeState :: OnDfsStack ) ;
509
- stack. push ( index ) ;
510
- for dependent in node. parent . iter ( ) . chain ( node. dependents . iter ( ) ) {
511
- self . find_cycles_from_node ( stack, processor, dependent . get ( ) ) ;
507
+ stack. push ( i ) ;
508
+ for index in node. parent . iter ( ) . chain ( node. dependents . iter ( ) ) {
509
+ self . find_cycles_from_node ( stack, processor, index . get ( ) ) ;
512
510
}
513
511
stack. pop ( ) ;
514
512
node. state . set ( NodeState :: Done ) ;
@@ -525,33 +523,32 @@ impl<O: ForestObligation> ObligationForest<O> {
525
523
526
524
/// Returns a vector of obligations for `p` and all of its
527
525
/// ancestors, putting them into the error state in the process.
528
- fn error_at ( & mut self , p : usize ) -> Vec < O > {
526
+ fn error_at ( & mut self , mut i : usize ) -> Vec < O > {
529
527
let mut error_stack = self . scratch . take ( ) . unwrap ( ) ;
530
528
let mut trace = vec ! [ ] ;
531
529
532
- let mut n = p;
533
530
loop {
534
- self . nodes [ n] . state . set ( NodeState :: Error ) ;
535
- trace. push ( self . nodes [ n] . obligation . clone ( ) ) ;
536
- error_stack. extend ( self . nodes [ n] . dependents . iter ( ) . map ( |x| x. get ( ) ) ) ;
531
+ let node = & self . nodes [ i] ;
532
+ node. state . set ( NodeState :: Error ) ;
533
+ trace. push ( node. obligation . clone ( ) ) ;
534
+ error_stack. extend ( node. dependents . iter ( ) . map ( |index| index. get ( ) ) ) ;
537
535
538
- // loop to the parent
539
- match self . nodes [ n ] . parent {
540
- Some ( q ) => n = q . get ( ) ,
536
+ // Loop to the parent.
537
+ match node . parent {
538
+ Some ( parent_index ) => i = parent_index . get ( ) ,
541
539
None => break
542
540
}
543
541
}
544
542
545
543
while let Some ( i) = error_stack. pop ( ) {
546
- match self . nodes [ i] . state . get ( ) {
544
+ let node = & self . nodes [ i] ;
545
+ match node. state . get ( ) {
547
546
NodeState :: Error => continue ,
548
547
_ => self . nodes [ i] . state . set ( NodeState :: Error ) ,
549
548
}
550
549
551
- let node = & self . nodes [ i] ;
552
-
553
550
error_stack. extend (
554
- node. parent . iter ( ) . chain ( node. dependents . iter ( ) ) . map ( |x| x . get ( ) )
551
+ node. parent . iter ( ) . chain ( node. dependents . iter ( ) ) . map ( |index| index . get ( ) )
555
552
) ;
556
553
}
557
554
@@ -689,34 +686,34 @@ impl<O: ForestObligation> ObligationForest<O> {
689
686
690
687
for node in & mut self . nodes {
691
688
if let Some ( index) = node. parent {
692
- let new_index = node_rewrites[ index. get ( ) ] ;
693
- if new_index >= nodes_len {
689
+ let new_i = node_rewrites[ index. get ( ) ] ;
690
+ if new_i >= nodes_len {
694
691
// parent dead due to error
695
692
node. parent = None ;
696
693
} else {
697
- node. parent = Some ( NodeIndex :: new ( new_index ) ) ;
694
+ node. parent = Some ( NodeIndex :: new ( new_i ) ) ;
698
695
}
699
696
}
700
697
701
698
let mut i = 0 ;
702
699
while i < node. dependents . len ( ) {
703
- let new_index = node_rewrites[ node. dependents [ i] . get ( ) ] ;
704
- if new_index >= nodes_len {
700
+ let new_i = node_rewrites[ node. dependents [ i] . get ( ) ] ;
701
+ if new_i >= nodes_len {
705
702
node. dependents . swap_remove ( i) ;
706
703
} else {
707
- node. dependents [ i] = NodeIndex :: new ( new_index ) ;
704
+ node. dependents [ i] = NodeIndex :: new ( new_i ) ;
708
705
i += 1 ;
709
706
}
710
707
}
711
708
}
712
709
713
710
let mut kill_list = vec ! [ ] ;
714
711
for ( predicate, index) in & mut self . waiting_cache {
715
- let new_index = node_rewrites[ index. get ( ) ] ;
716
- if new_index >= nodes_len {
712
+ let new_i = node_rewrites[ index. get ( ) ] ;
713
+ if new_i >= nodes_len {
717
714
kill_list. push ( predicate. clone ( ) ) ;
718
715
} else {
719
- * index = NodeIndex :: new ( new_index ) ;
716
+ * index = NodeIndex :: new ( new_i ) ;
720
717
}
721
718
}
722
719
0 commit comments