@@ -19,8 +19,8 @@ use rustc_data_structures::fx::FxHashSet;
19
19
use rustc_data_structures:: graph:: implementation:: {
20
20
Direction , Graph , NodeIndex , INCOMING , OUTGOING ,
21
21
} ;
22
+ use rustc_index:: bit_set:: BitSet ;
22
23
use rustc_index:: vec:: { Idx , IndexVec } ;
23
- use smallvec:: SmallVec ;
24
24
use std:: fmt;
25
25
use syntax_pos:: Span ;
26
26
@@ -870,21 +870,34 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
870
870
where
871
871
F : FnMut ( & Constraint < ' tcx > ) -> ( bool , bool ) ,
872
872
{
873
- let mut constraints: SmallVec < [ _ ; 16 ] > = self . data . constraints . keys ( ) . collect ( ) ;
873
+ // Using bitsets to track the remaining elements is faster than using a
874
+ // `Vec` by itself (which requires removing elements, which requires
875
+ // element shuffling, which is slow).
876
+ let constraints: Vec < _ > = self . data . constraints . keys ( ) . collect ( ) ;
877
+ let mut live_indices: BitSet < usize > = BitSet :: new_filled ( constraints. len ( ) ) ;
878
+ let mut killed_indices: BitSet < usize > = BitSet :: new_empty ( constraints. len ( ) ) ;
874
879
let mut iteration = 0 ;
875
880
let mut changed = true ;
876
881
while changed {
877
882
changed = false ;
878
883
iteration += 1 ;
879
884
debug ! ( "---- Expansion iteration {}" , iteration) ;
880
- constraints. retain ( |constraint| {
885
+ for index in live_indices. iter ( ) {
886
+ let constraint = constraints[ index] ;
881
887
let ( edge_changed, retain) = body ( constraint) ;
882
888
if edge_changed {
883
889
debug ! ( "updated due to constraint {:?}" , constraint) ;
884
890
changed = true ;
885
891
}
886
- retain
887
- } ) ;
892
+ if !retain {
893
+ let changed = killed_indices. insert ( index) ;
894
+ debug_assert ! ( changed) ;
895
+ }
896
+ }
897
+ live_indices. subtract ( & killed_indices) ;
898
+
899
+ // We could clear `killed_indices` here, but we don't need to and
900
+ // it's cheaper not to.
888
901
}
889
902
debug ! ( "---- Expansion complete after {} iteration(s)" , iteration) ;
890
903
}
0 commit comments