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