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 :: simplify:: remove_dead_blocks;
137
135
use crate :: MirPass ;
138
- use rustc_data_structures:: fx:: FxHashMap ;
136
+ use rustc_data_structures:: fx:: { FxIndexMap , IndexEntry , IndexOccupiedEntry } ;
139
137
use rustc_index:: bit_set:: BitSet ;
140
138
use rustc_middle:: mir:: visit:: { MutVisitor , PlaceContext , Visitor } ;
141
139
use rustc_middle:: mir:: HasLocalDecls ;
@@ -212,7 +210,7 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
212
210
let mut merged_locals: BitSet < Local > = BitSet :: new_empty ( body. local_decls . len ( ) ) ;
213
211
214
212
// 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 ( ) ;
216
214
217
215
for ( src, candidates) in candidates. c . iter ( ) {
218
216
if merged_locals. contains ( * src) {
@@ -257,8 +255,8 @@ impl<'tcx> MirPass<'tcx> for DestinationPropagation {
257
255
/// frequently. Everything with a `&'alloc` lifetime points into here.
258
256
#[ derive( Default ) ]
259
257
struct 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 > > ,
262
260
write_info : WriteInfo ,
263
261
// PERF: Do this for `MaybeLiveLocals` allocations too.
264
262
}
@@ -279,11 +277,11 @@ struct Candidates<'alloc> {
279
277
///
280
278
/// We will still report that we would like to merge `_1` and `_2` in an attempt to allow us to
281
279
/// remove that assignment.
282
- c : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
280
+ c : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
283
281
/// A reverse index of the `c` set; if the `c` set contains `a => Place { local: b, proj }`,
284
282
/// then this contains `b => a`.
285
283
// PERF: Possibly these should be `SmallVec`s?
286
- reverse : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
284
+ reverse : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
287
285
}
288
286
289
287
//////////////////////////////////////////////////////////
@@ -294,7 +292,7 @@ struct Candidates<'alloc> {
294
292
fn apply_merges < ' tcx > (
295
293
body : & mut Body < ' tcx > ,
296
294
tcx : TyCtxt < ' tcx > ,
297
- merges : & FxHashMap < Local , Local > ,
295
+ merges : & FxIndexMap < Local , Local > ,
298
296
merged_locals : & BitSet < Local > ,
299
297
) {
300
298
let mut merger = Merger { tcx, merges, merged_locals } ;
@@ -303,7 +301,7 @@ fn apply_merges<'tcx>(
303
301
304
302
struct Merger < ' a , ' tcx > {
305
303
tcx : TyCtxt < ' tcx > ,
306
- merges : & ' a FxHashMap < Local , Local > ,
304
+ merges : & ' a FxIndexMap < Local , Local > ,
307
305
merged_locals : & ' a BitSet < Local > ,
308
306
}
309
307
@@ -386,7 +384,7 @@ impl<'alloc> Candidates<'alloc> {
386
384
387
385
/// `vec_filter_candidates` but for an `Entry`
388
386
fn entry_filter_candidates (
389
- mut entry : OccupiedEntry < ' _ , Local , Vec < Local > > ,
387
+ mut entry : IndexOccupiedEntry < ' _ , Local , Vec < Local > > ,
390
388
p : Local ,
391
389
f : impl FnMut ( Local ) -> CandidateFilter ,
392
390
at : Location ,
@@ -406,7 +404,7 @@ impl<'alloc> Candidates<'alloc> {
406
404
at : Location ,
407
405
) {
408
406
// 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) {
410
408
Self :: entry_filter_candidates ( entry, p, & mut f, at) ;
411
409
}
412
410
// And the cases where `p` appears as a `dest`
@@ -419,7 +417,7 @@ impl<'alloc> Candidates<'alloc> {
419
417
if f ( * src) == CandidateFilter :: Keep {
420
418
return true ;
421
419
}
422
- let Entry :: Occupied ( entry) = self . c . entry ( * src) else {
420
+ let IndexEntry :: Occupied ( entry) = self . c . entry ( * src) else {
423
421
return false ;
424
422
} ;
425
423
Self :: entry_filter_candidates (
@@ -728,8 +726,8 @@ fn places_to_candidate_pair<'tcx>(
728
726
fn find_candidates < ' alloc , ' tcx > (
729
727
body : & Body < ' tcx > ,
730
728
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 > > ,
733
731
) -> Candidates < ' alloc > {
734
732
candidates. clear ( ) ;
735
733
candidates_reverse. clear ( ) ;
@@ -751,7 +749,7 @@ fn find_candidates<'alloc, 'tcx>(
751
749
752
750
struct FindAssignments < ' a , ' alloc , ' tcx > {
753
751
body : & ' a Body < ' tcx > ,
754
- candidates : & ' alloc mut FxHashMap < Local , Vec < Local > > ,
752
+ candidates : & ' alloc mut FxIndexMap < Local , Vec < Local > > ,
755
753
borrowed : & ' a BitSet < Local > ,
756
754
}
757
755
0 commit comments