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 :: simplify:: remove_dead_blocks;
137135use crate :: MirPass ;
138- use rustc_data_structures:: fx:: FxHashMap ;
136+ use rustc_data_structures:: fx:: { FxIndexMap , IndexEntry , IndexOccupiedEntry } ;
139137use rustc_index:: bit_set:: BitSet ;
140138use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
141139use rustc_middle:: mir:: HasLocalDecls ;
@@ -212,7 +210,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
212210 let mut merged_locals: BitSet < Local > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
213211
214212 // This is the set of merges we will apply this round. It is a subset of the candidates.
215- let mut merges = FxHashMap :: default ( ) ;
213+ let mut merges = FxIndexMap :: default ( ) ;
216214
217215 for ( src, candidates) in candidates. c . iter ( ) {
218216 if merged_locals. contains ( * src) {
@@ -257,8 +255,8 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
257255/// frequently. Everything with a `&'alloc` lifetime points into here.
258256#[ derive( Default ) ]
259257struct Allocations {
260- candidates : FxHashMap < Local , Vec < Local > > ,
261- candidates_reverse : FxHashMap < Local , Vec < Local > > ,
258+ candidates : FxIndexMap < Local , Vec < Local > > ,
259+ candidates_reverse : FxIndexMap < Local , Vec < Local > > ,
262260 write_info : WriteInfo ,
263261 // PERF: Do this for `MaybeLiveLocals` allocations too.
264262}
@@ -279,11 +277,11 @@ struct Candidates<'alloc> {
279277 ///
280278 /// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
281279 /// remove that assignment.
282- c : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
280+ c : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
283281 /// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
284282 /// then this contains `b => a`.
285283 // PERF: Possibly these should be `SmallVec`s?
286- reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
284+ reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
287285}
288286
289287//////////////////////////////////////////////////////////
@@ -294,7 +292,7 @@ struct Candidates<'alloc> {
294292fn apply_merges < ' tcx > (
295293 body : & mut Body < ' tcx > ,
296294 tcx : TyCtxt < ' tcx > ,
297- merges : & FxHashMap < Local , Local > ,
295+ merges : & FxIndexMap < Local , Local > ,
298296 merged_locals : & BitSet < Local > ,
299297) {
300298 let mut merger = Merger { tcx, merges, merged_locals } ;
@@ -303,7 +301,7 @@ fn apply_merges<'tcx>(
303301
304302struct Merger < ' a , ' tcx > {
305303 tcx : TyCtxt < ' tcx > ,
306- merges : & ' a FxHashMap < Local , Local > ,
304+ merges : & ' a FxIndexMap < Local , Local > ,
307305 merged_locals : & ' a BitSet < Local > ,
308306}
309307
@@ -386,7 +384,7 @@ impl<'alloc> Candidates<'alloc> {
386384
387385 /// `vec_filter_candidates` but for an `Entry`
388386 fn entry_filter_candidates (
389- mut entry : OccupiedEntry < ' _ , Local , Vec < Local > > ,
387+ mut entry : IndexOccupiedEntry < ' _ , Local , Vec < Local > > ,
390388 p : Local ,
391389 f : impl FnMut ( Local ) -> CandidateFilter ,
392390 at : Location ,
@@ -406,7 +404,7 @@ impl<'alloc> Candidates<'alloc> {
406404 at : Location ,
407405 ) {
408406 // Cover the cases where `p` appears as a `src`
409- if let Entry :: Occupied ( entry) = self . c . entry ( p) {
407+ if let IndexEntry :: Occupied ( entry) = self . c . entry ( p) {
410408 Self :: entry_filter_candidates ( entry, p, & mut f, at) ;
411409 }
412410 // And the cases where `p` appears as a `dest`
@@ -419,7 +417,7 @@ impl<'alloc> Candidates<'alloc> {
419417 if f ( * src) == CandidateFilter :: Keep {
420418 return true ;
421419 }
422- let Entry :: Occupied ( entry) = self . c . entry ( * src) else {
420+ let IndexEntry :: Occupied ( entry) = self . c . entry ( * src) else {
423421 return false ;
424422 } ;
425423 Self :: entry_filter_candidates (
@@ -728,8 +726,8 @@ fn places_to_candidate_pair<'tcx>(
728726fn find_candidates < ' alloc , ' tcx > (
729727 body : & Body < ' tcx > ,
730728 borrowed : & BitSet < Local > ,
731- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
732- candidates_reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
729+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
730+ candidates_reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
733731) -> Candidates < ' alloc > {
734732 candidates. clear ( ) ;
735733 candidates_reverse. clear ( ) ;
@@ -751,7 +749,7 @@ fn find_candidates<'alloc, 'tcx>(
751749
752750struct FindAssignments < ' a , ' alloc , ' tcx > {
753751 body : & ' a Body < ' tcx > ,
754- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
752+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
755753 borrowed : & ' a BitSet < Local > ,
756754}
757755
0 commit comments