@@ -58,7 +58,7 @@ use crate::deref_separator::deref_finder;
58
58
use crate :: errors;
59
59
use crate :: pass_manager as pm;
60
60
use crate :: simplify;
61
- use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
61
+ use rustc_data_structures:: fx:: FxHashSet ;
62
62
use rustc_errors:: pluralize;
63
63
use rustc_hir as hir;
64
64
use rustc_hir:: lang_items:: LangItem ;
@@ -236,8 +236,7 @@ struct TransformVisitor<'tcx> {
236
236
discr_ty : Ty < ' tcx > ,
237
237
238
238
// Mapping from Local to (type of local, coroutine struct index)
239
- // FIXME(eddyb) This should use `IndexVec<Local, Option<_>>`.
240
- remap : FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , FieldIdx ) > ,
239
+ remap : IndexVec < Local , Option < ( Ty < ' tcx > , VariantIdx , FieldIdx ) > > ,
241
240
242
241
// A map from a suspension point in a block to the locals which have live storage at that point
243
242
storage_liveness : IndexVec < BasicBlock , Option < BitSet < Local > > > ,
@@ -485,7 +484,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
485
484
}
486
485
487
486
fn visit_local ( & mut self , local : & mut Local , _: PlaceContext , _: Location ) {
488
- assert_eq ! ( self . remap. get ( local) , None ) ;
487
+ assert ! ( ! self . remap. contains ( * local) ) ;
489
488
}
490
489
491
490
fn visit_place (
@@ -495,7 +494,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
495
494
_location : Location ,
496
495
) {
497
496
// Replace an Local in the remap with a coroutine struct access
498
- if let Some ( & ( ty, variant_index, idx) ) = self . remap . get ( & place. local ) {
497
+ if let Some ( & Some ( ( ty, variant_index, idx) ) ) = self . remap . get ( place. local ) {
499
498
replace_base ( place, self . make_field ( variant_index, idx, ty) , self . tcx ) ;
500
499
}
501
500
}
@@ -504,7 +503,7 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
504
503
// Remove StorageLive and StorageDead statements for remapped locals
505
504
data. retain_statements ( |s| match s. kind {
506
505
StatementKind :: StorageLive ( l) | StatementKind :: StorageDead ( l) => {
507
- !self . remap . contains_key ( & l)
506
+ !self . remap . contains ( l)
508
507
}
509
508
_ => true ,
510
509
} ) ;
@@ -529,21 +528,17 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> {
529
528
530
529
// The resume arg target location might itself be remapped if its base local is
531
530
// live across a yield.
532
- let resume_arg =
533
- if let Some ( & ( ty, variant, idx) ) = self . remap . get ( & resume_arg. local ) {
534
- replace_base ( & mut resume_arg, self . make_field ( variant, idx, ty) , self . tcx ) ;
535
- resume_arg
536
- } else {
537
- resume_arg
538
- } ;
531
+ if let Some ( & Some ( ( ty, variant, idx) ) ) = self . remap . get ( resume_arg. local ) {
532
+ replace_base ( & mut resume_arg, self . make_field ( variant, idx, ty) , self . tcx ) ;
533
+ }
539
534
540
535
let storage_liveness: GrowableBitSet < Local > =
541
536
self . storage_liveness [ block] . clone ( ) . unwrap ( ) . into ( ) ;
542
537
543
538
for i in 0 ..self . always_live_locals . domain_size ( ) {
544
539
let l = Local :: new ( i) ;
545
540
let needs_storage_dead = storage_liveness. contains ( l)
546
- && !self . remap . contains_key ( & l)
541
+ && !self . remap . contains ( l)
547
542
&& !self . always_live_locals . contains ( l) ;
548
543
if needs_storage_dead {
549
544
data. statements
@@ -1037,7 +1032,7 @@ fn compute_layout<'tcx>(
1037
1032
liveness : LivenessInfo ,
1038
1033
body : & Body < ' tcx > ,
1039
1034
) -> (
1040
- FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , FieldIdx ) > ,
1035
+ IndexVec < Local , Option < ( Ty < ' tcx > , VariantIdx , FieldIdx ) > > ,
1041
1036
CoroutineLayout < ' tcx > ,
1042
1037
IndexVec < BasicBlock , Option < BitSet < Local > > > ,
1043
1038
) {
@@ -1098,7 +1093,7 @@ fn compute_layout<'tcx>(
1098
1093
// Create a map from local indices to coroutine struct indices.
1099
1094
let mut variant_fields: IndexVec < VariantIdx , IndexVec < FieldIdx , CoroutineSavedLocal > > =
1100
1095
iter:: repeat ( IndexVec :: new ( ) ) . take ( RESERVED_VARIANTS ) . collect ( ) ;
1101
- let mut remap = FxHashMap :: default ( ) ;
1096
+ let mut remap = IndexVec :: from_elem_n ( None , saved_locals . domain_size ( ) ) ;
1102
1097
for ( suspension_point_idx, live_locals) in live_locals_at_suspension_points. iter ( ) . enumerate ( ) {
1103
1098
let variant_index = VariantIdx :: from ( RESERVED_VARIANTS + suspension_point_idx) ;
1104
1099
let mut fields = IndexVec :: new ( ) ;
@@ -1109,7 +1104,7 @@ fn compute_layout<'tcx>(
1109
1104
// around inside coroutines, so it doesn't matter which variant
1110
1105
// index we access them by.
1111
1106
let idx = FieldIdx :: from_usize ( idx) ;
1112
- remap. entry ( locals[ saved_local] ) . or_insert ( ( tys[ saved_local] . ty , variant_index, idx) ) ;
1107
+ remap[ locals[ saved_local] ] = Some ( ( tys[ saved_local] . ty , variant_index, idx) ) ;
1113
1108
}
1114
1109
variant_fields. push ( fields) ;
1115
1110
variant_source_info. push ( source_info_at_suspension_points[ suspension_point_idx] ) ;
@@ -1121,7 +1116,9 @@ fn compute_layout<'tcx>(
1121
1116
for var in & body. var_debug_info {
1122
1117
let VarDebugInfoContents :: Place ( place) = & var. value else { continue } ;
1123
1118
let Some ( local) = place. as_local ( ) else { continue } ;
1124
- let Some ( & ( _, variant, field) ) = remap. get ( & local) else { continue } ;
1119
+ let Some ( & Some ( ( _, variant, field) ) ) = remap. get ( local) else {
1120
+ continue ;
1121
+ } ;
1125
1122
1126
1123
let saved_local = variant_fields[ variant] [ field] ;
1127
1124
field_names. get_or_insert_with ( saved_local, || var. name ) ;
@@ -1524,7 +1521,7 @@ fn create_cases<'tcx>(
1524
1521
for i in 0 ..( body. local_decls . len ( ) ) {
1525
1522
let l = Local :: new ( i) ;
1526
1523
let needs_storage_live = point. storage_liveness . contains ( l)
1527
- && !transform. remap . contains_key ( & l)
1524
+ && !transform. remap . contains ( l)
1528
1525
&& !transform. always_live_locals . contains ( l) ;
1529
1526
if needs_storage_live {
1530
1527
statements
0 commit comments