131
131
//! [attempt 2]: https://github.com/rust-lang/rust/pull/71003
132
132
//! [attempt 3]: https://github.com/rust-lang/rust/pull/72632
133
133
134
- use std:: collections:: hash_map:: { Entry , OccupiedEntry } ;
135
-
136
134
use crate :: MirPass ;
137
- use rustc_data_structures:: fx:: FxHashMap ;
135
+ use rustc_data_structures:: fx:: { FxIndexMap , IndexEntry , IndexOccupiedEntry } ;
138
136
use rustc_index:: bit_set:: BitSet ;
139
137
use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
140
138
use rustc_middle:: mir:: HasLocalDecls ;
@@ -211,7 +209,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
211
209
let mut merged_locals: BitSet < Local > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
212
210
213
211
// 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 ( ) ;
215
213
216
214
for ( src, candidates) in candidates. c . iter ( ) {
217
215
if merged_locals. contains ( * src) {
@@ -250,8 +248,8 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
250
248
/// frequently. Everything with a `&'alloc` lifetime points into here.
251
249
#[ derive( Default ) ]
252
250
struct 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 > > ,
255
253
write_info : WriteInfo ,
256
254
// PERF: Do this for `MaybeLiveLocals` allocations too.
257
255
}
@@ -272,11 +270,11 @@ struct Candidates<'alloc> {
272
270
///
273
271
/// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
274
272
/// remove that assignment.
275
- c : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
273
+ c : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
276
274
/// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
277
275
/// then this contains `b => a`.
278
276
// PERF: Possibly these should be `SmallVec`s?
279
- reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
277
+ reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
280
278
}
281
279
282
280
//////////////////////////////////////////////////////////
@@ -287,7 +285,7 @@ struct Candidates<'alloc> {
287
285
fn apply_merges < ' tcx > (
288
286
body : & mut Body < ' tcx > ,
289
287
tcx : TyCtxt < ' tcx > ,
290
- merges : & FxHashMap < Local , Local > ,
288
+ merges : & FxIndexMap < Local , Local > ,
291
289
merged_locals : & BitSet < Local > ,
292
290
) {
293
291
let mut merger = Merger { tcx, merges, merged_locals } ;
@@ -296,7 +294,7 @@ fn apply_merges<'tcx>(
296
294
297
295
struct Merger < ' a , ' tcx > {
298
296
tcx : TyCtxt < ' tcx > ,
299
- merges : & ' a FxHashMap < Local , Local > ,
297
+ merges : & ' a FxIndexMap < Local , Local > ,
300
298
merged_locals : & ' a BitSet < Local > ,
301
299
}
302
300
@@ -379,7 +377,7 @@ impl<'alloc> Candidates<'alloc> {
379
377
380
378
/// `vec_filter_candidates` but for an `Entry`
381
379
fn entry_filter_candidates (
382
- mut entry : OccupiedEntry < ' _ , Local , Vec < Local > > ,
380
+ mut entry : IndexOccupiedEntry < ' _ , Local , Vec < Local > > ,
383
381
p : Local ,
384
382
f : impl FnMut ( Local ) -> CandidateFilter ,
385
383
at : Location ,
@@ -399,7 +397,7 @@ impl<'alloc> Candidates<'alloc> {
399
397
at : Location ,
400
398
) {
401
399
// 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) {
403
401
Self :: entry_filter_candidates ( entry, p, & mut f, at) ;
404
402
}
405
403
// And the cases where `p` appears as a `dest`
@@ -412,7 +410,7 @@ impl<'alloc> Candidates<'alloc> {
412
410
if f ( * src) == CandidateFilter :: Keep {
413
411
return true ;
414
412
}
415
- let Entry :: Occupied ( entry) = self . c . entry ( * src) else {
413
+ let IndexEntry :: Occupied ( entry) = self . c . entry ( * src) else {
416
414
return false ;
417
415
} ;
418
416
Self :: entry_filter_candidates (
@@ -721,8 +719,8 @@ fn places_to_candidate_pair<'tcx>(
721
719
fn find_candidates < ' alloc , ' tcx > (
722
720
body : & Body < ' tcx > ,
723
721
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 > > ,
726
724
) -> Candidates < ' alloc > {
727
725
candidates. clear ( ) ;
728
726
candidates_reverse. clear ( ) ;
@@ -744,7 +742,7 @@ fn find_candidates<'alloc, 'tcx>(
744
742
745
743
struct FindAssignments < ' a , ' alloc , ' tcx > {
746
744
body : & ' a Body < ' tcx > ,
747
- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
745
+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
748
746
borrowed : & ' a BitSet < Local > ,
749
747
}
750
748
0 commit comments