@@ -149,7 +149,7 @@ pub struct ObligationForest<O: ForestObligation> {
149
149
/// A cache of the nodes in `nodes`, indexed by predicate. Unfortunately,
150
150
/// its contents are not guaranteed to match those of `nodes`. See the
151
151
/// comments in `process_obligation` for details.
152
- waiting_cache : FxHashMap < O :: Predicate , usize > ,
152
+ active_cache : FxHashMap < O :: Predicate , usize > ,
153
153
154
154
/// A scratch vector reused in various operations, to avoid allocating new
155
155
/// vectors.
@@ -278,7 +278,7 @@ impl<O: ForestObligation> ObligationForest<O> {
278
278
ObligationForest {
279
279
nodes : vec ! [ ] ,
280
280
done_cache : Default :: default ( ) ,
281
- waiting_cache : Default :: default ( ) ,
281
+ active_cache : Default :: default ( ) ,
282
282
scratch : RefCell :: new ( vec ! [ ] ) ,
283
283
obligation_tree_id_generator : ( 0 ..) . map ( ObligationTreeId ) ,
284
284
error_cache : Default :: default ( ) ,
@@ -303,15 +303,15 @@ impl<O: ForestObligation> ObligationForest<O> {
303
303
return Ok ( ( ) ) ;
304
304
}
305
305
306
- match self . waiting_cache . entry ( obligation. as_predicate ( ) . clone ( ) ) {
306
+ match self . active_cache . entry ( obligation. as_predicate ( ) . clone ( ) ) {
307
307
Entry :: Occupied ( o) => {
308
308
debug ! ( "register_obligation_at({:?}, {:?}) - duplicate of {:?}!" ,
309
309
obligation, parent, o. get( ) ) ;
310
310
let node = & mut self . nodes [ * o. get ( ) ] ;
311
311
if let Some ( parent_index) = parent {
312
- // If the node is already in `waiting_cache `, it has
313
- // already had its chance to be marked with a parent. So if
314
- // it's not already present, just dump `parent` into the
312
+ // If the node is already in `active_cache `, it has already
313
+ // had its chance to be marked with a parent. So if it's
314
+ // not already present, just dump `parent` into the
315
315
// dependents as a non-parent.
316
316
if !node. dependents . contains ( & parent_index) {
317
317
node. dependents . push ( parent_index) ;
@@ -355,10 +355,9 @@ impl<O: ForestObligation> ObligationForest<O> {
355
355
let mut errors = vec ! [ ] ;
356
356
for ( index, node) in self . nodes . iter ( ) . enumerate ( ) {
357
357
if let NodeState :: Pending = node. state . get ( ) {
358
- let backtrace = self . error_at ( index) ;
359
358
errors. push ( Error {
360
359
error : error. clone ( ) ,
361
- backtrace,
360
+ backtrace : self . error_at ( index ) ,
362
361
} ) ;
363
362
}
364
363
}
@@ -406,8 +405,8 @@ impl<O: ForestObligation> ObligationForest<O> {
406
405
407
406
// `processor.process_obligation` can modify the predicate within
408
407
// `node.obligation`, and that predicate is the key used for
409
- // `self.waiting_cache `. This means that `self.waiting_cache ` can
410
- // get out of sync with `nodes`. It's not very common, but it does
408
+ // `self.active_cache `. This means that `self.active_cache ` can get
409
+ // out of sync with `nodes`. It's not very common, but it does
411
410
// happen, and code in `compress` has to allow for it.
412
411
let result = match node. state . get ( ) {
413
412
NodeState :: Pending => processor. process_obligation ( & mut node. obligation ) ,
@@ -439,10 +438,9 @@ impl<O: ForestObligation> ObligationForest<O> {
439
438
}
440
439
ProcessResult :: Error ( err) => {
441
440
stalled = false ;
442
- let backtrace = self . error_at ( index) ;
443
441
errors. push ( Error {
444
442
error : err,
445
- backtrace,
443
+ backtrace : self . error_at ( index ) ,
446
444
} ) ;
447
445
}
448
446
}
@@ -484,13 +482,16 @@ impl<O: ForestObligation> ObligationForest<O> {
484
482
debug ! ( "process_cycles()" ) ;
485
483
486
484
for ( index, node) in self . nodes . iter ( ) . enumerate ( ) {
487
- // For rustc-benchmarks/inflate-0.1.0 this state test is extremely
488
- // hot and the state is almost always `Pending` or `Waiting`. It's
489
- // a win to handle the no-op cases immediately to avoid the cost of
490
- // the function call.
485
+ // For some benchmarks this state test is extremely
486
+ // hot. It's a win to handle the no-op cases immediately to avoid
487
+ // the cost of the function call.
491
488
match node. state . get ( ) {
492
- NodeState :: Waiting | NodeState :: Pending | NodeState :: Done | NodeState :: Error => { } ,
493
- _ => self . find_cycles_from_node ( & mut stack, processor, index) ,
489
+ // Match arms are in order of frequency. Pending, Success and
490
+ // Waiting dominate; the others are rare.
491
+ NodeState :: Pending => { } ,
492
+ NodeState :: Success => self . find_cycles_from_node ( & mut stack, processor, index) ,
493
+ NodeState :: Waiting | NodeState :: Done | NodeState :: Error => { } ,
494
+ NodeState :: OnDfsStack => self . find_cycles_from_node ( & mut stack, processor, index) ,
494
495
}
495
496
}
496
497
@@ -506,8 +507,8 @@ impl<O: ForestObligation> ObligationForest<O> {
506
507
let node = & self . nodes [ index] ;
507
508
match node. state . get ( ) {
508
509
NodeState :: OnDfsStack => {
509
- let index = stack. iter ( ) . rposition ( |& n| n == index) . unwrap ( ) ;
510
- processor. process_backedge ( stack[ index ..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
510
+ let rpos = stack. iter ( ) . rposition ( |& n| n == index) . unwrap ( ) ;
511
+ processor. process_backedge ( stack[ rpos ..] . iter ( ) . map ( GetObligation ( & self . nodes ) ) ,
511
512
PhantomData ) ;
512
513
}
513
514
NodeState :: Success => {
@@ -636,11 +637,11 @@ impl<O: ForestObligation> ObligationForest<O> {
636
637
}
637
638
NodeState :: Done => {
638
639
// This lookup can fail because the contents of
639
- // `self.waiting_cache ` is not guaranteed to match those of
640
+ // `self.active_cache ` is not guaranteed to match those of
640
641
// `self.nodes`. See the comment in `process_obligation`
641
642
// for more details.
642
- if let Some ( ( predicate, _) ) = self . waiting_cache
643
- . remove_entry ( node. obligation . as_predicate ( ) )
643
+ if let Some ( ( predicate, _) ) =
644
+ self . active_cache . remove_entry ( node. obligation . as_predicate ( ) )
644
645
{
645
646
self . done_cache . insert ( predicate) ;
646
647
} else {
@@ -653,7 +654,7 @@ impl<O: ForestObligation> ObligationForest<O> {
653
654
// We *intentionally* remove the node from the cache at this point. Otherwise
654
655
// tests must come up with a different type on every type error they
655
656
// check against.
656
- self . waiting_cache . remove ( node. obligation . as_predicate ( ) ) ;
657
+ self . active_cache . remove ( node. obligation . as_predicate ( ) ) ;
657
658
node_rewrites[ index] = nodes_len;
658
659
dead_nodes += 1 ;
659
660
self . insert_into_error_cache ( index) ;
@@ -697,25 +698,25 @@ impl<O: ForestObligation> ObligationForest<O> {
697
698
let nodes_len = node_rewrites. len ( ) ;
698
699
699
700
for node in & mut self . nodes {
700
- let mut index = 0 ;
701
- while index < node. dependents . len ( ) {
702
- let new_index = node_rewrites[ node. dependents [ index ] ] ;
701
+ let mut i = 0 ;
702
+ while i < node. dependents . len ( ) {
703
+ let new_index = node_rewrites[ node. dependents [ i ] ] ;
703
704
if new_index >= nodes_len {
704
- node. dependents . swap_remove ( index ) ;
705
- if index == 0 && node. has_parent {
705
+ node. dependents . swap_remove ( i ) ;
706
+ if i == 0 && node. has_parent {
706
707
// We just removed the parent.
707
708
node. has_parent = false ;
708
709
}
709
710
} else {
710
- node. dependents [ index ] = new_index;
711
- index += 1 ;
711
+ node. dependents [ i ] = new_index;
712
+ i += 1 ;
712
713
}
713
714
}
714
715
}
715
716
716
- // This updating of `self.waiting_cache ` is necessary because the
717
+ // This updating of `self.active_cache ` is necessary because the
717
718
// removal of nodes within `compress` can fail. See above.
718
- self . waiting_cache . retain ( |_predicate, index| {
719
+ self . active_cache . retain ( |_predicate, index| {
719
720
let new_index = node_rewrites[ * index] ;
720
721
if new_index >= nodes_len {
721
722
false
0 commit comments