131131//! [attempt 2]: https://github.com/rust-lang/rust/pull/71003
132132//! [attempt 3]: https://github.com/rust-lang/rust/pull/72632
133133
134- use std:: collections:: hash_map:: { Entry , OccupiedEntry } ;
135-
136134use crate :: MirPass ;
137- use rustc_data_structures:: fx:: FxHashMap ;
135+ use rustc_data_structures:: fx:: { FxIndexMap , IndexEntry , IndexOccupiedEntry } ;
138136use rustc_index:: bit_set:: BitSet ;
139137use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
140138use rustc_middle:: mir:: HasLocalDecls ;
@@ -211,7 +209,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
211209 let mut merged_locals: BitSet < Local > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
212210
213211 // This is the set of merges we will apply this round. It is a subset of the candidates.
214- let mut merges = FxHashMap :: default ( ) ;
212+ let mut merges = FxIndexMap :: default ( ) ;
215213
216214 for ( src, candidates) in candidates. c . iter ( ) {
217215 if merged_locals. contains ( * src) {
@@ -250,8 +248,8 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
250248/// frequently. Everything with a `&'alloc` lifetime points into here.
251249#[ derive( Default ) ]
252250struct Allocations {
253- candidates : FxHashMap < Local , Vec < Local > > ,
254- candidates_reverse : FxHashMap < Local , Vec < Local > > ,
251+ candidates : FxIndexMap < Local , Vec < Local > > ,
252+ candidates_reverse : FxIndexMap < Local , Vec < Local > > ,
255253 write_info : WriteInfo ,
256254 // PERF: Do this for `MaybeLiveLocals` allocations too.
257255}
@@ -272,11 +270,11 @@ struct Candidates<'alloc> {
272270 ///
273271 /// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
274272 /// remove that assignment.
275- c : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
273+ c : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
276274 /// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
277275 /// then this contains `b => a`.
278276 // PERF: Possibly these should be `SmallVec`s?
279- reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
277+ reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
280278}
281279
282280//////////////////////////////////////////////////////////
@@ -287,7 +285,7 @@ struct Candidates<'alloc> {
287285fn apply_merges < ' tcx > (
288286 body : & mut Body < ' tcx > ,
289287 tcx : TyCtxt < ' tcx > ,
290- merges : & FxHashMap < Local , Local > ,
288+ merges : & FxIndexMap < Local , Local > ,
291289 merged_locals : & BitSet < Local > ,
292290) {
293291 let mut merger = Merger { tcx, merges, merged_locals } ;
@@ -296,7 +294,7 @@ fn apply_merges<'tcx>(
296294
297295struct Merger < ' a , ' tcx > {
298296 tcx : TyCtxt < ' tcx > ,
299- merges : & ' a FxHashMap < Local , Local > ,
297+ merges : & ' a FxIndexMap < Local , Local > ,
300298 merged_locals : & ' a BitSet < Local > ,
301299}
302300
@@ -379,7 +377,7 @@ impl<'alloc> Candidates<'alloc> {
379377
380378 /// `vec_filter_candidates` but for an `Entry`
381379 fn entry_filter_candidates (
382- mut entry : OccupiedEntry < ' _ , Local , Vec < Local > > ,
380+ mut entry : IndexOccupiedEntry < ' _ , Local , Vec < Local > > ,
383381 p : Local ,
384382 f : impl FnMut ( Local ) -> CandidateFilter ,
385383 at : Location ,
@@ -399,7 +397,7 @@ impl<'alloc> Candidates<'alloc> {
399397 at : Location ,
400398 ) {
401399 // Cover the cases where `p` appears as a `src`
402- if let Entry :: Occupied ( entry) = self . c . entry ( p) {
400+ if let IndexEntry :: Occupied ( entry) = self . c . entry ( p) {
403401 Self :: entry_filter_candidates ( entry, p, & mut f, at) ;
404402 }
405403 // And the cases where `p` appears as a `dest`
@@ -412,7 +410,7 @@ impl<'alloc> Candidates<'alloc> {
412410 if f ( * src) == CandidateFilter :: Keep {
413411 return true ;
414412 }
415- let Entry :: Occupied ( entry) = self . c . entry ( * src) else {
413+ let IndexEntry :: Occupied ( entry) = self . c . entry ( * src) else {
416414 return false ;
417415 } ;
418416 Self :: entry_filter_candidates (
@@ -721,8 +719,8 @@ fn places_to_candidate_pair<'tcx>(
721719fn find_candidates < ' alloc , ' tcx > (
722720 body : & Body < ' tcx > ,
723721 borrowed : & BitSet < Local > ,
724- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
725- candidates_reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
722+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
723+ candidates_reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
726724) -> Candidates < ' alloc > {
727725 candidates. clear ( ) ;
728726 candidates_reverse. clear ( ) ;
@@ -744,7 +742,7 @@ fn find_candidates<'alloc, 'tcx>(
744742
745743struct FindAssignments < ' a , ' alloc , ' tcx > {
746744 body : & ' a Body < ' tcx > ,
747- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
745+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
748746 borrowed : & ' a BitSet < Local > ,
749747}
750748
0 commit comments