@@ -210,8 +210,7 @@ struct TransformVisitor<'tcx> {
210
210
remap : FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , usize ) > ,
211
211
212
212
// A map from a suspension point in a block to the locals which have live storage at that point
213
- // FIXME(eddyb) This should use `IndexVec<BasicBlock, Option<_>>`.
214
- storage_liveness : FxHashMap < BasicBlock , liveness:: LiveVarSet > ,
213
+ storage_liveness : IndexVec < BasicBlock , Option < liveness:: LiveVarSet > > ,
215
214
216
215
// A list of suspension points, generated during the transform
217
216
suspension_points : Vec < SuspensionPoint < ' tcx > > ,
@@ -338,7 +337,7 @@ impl MutVisitor<'tcx> for TransformVisitor<'tcx> {
338
337
resume,
339
338
resume_arg,
340
339
drop,
341
- storage_liveness : self . storage_liveness . get ( & block) . unwrap ( ) . clone ( ) ,
340
+ storage_liveness : self . storage_liveness [ block] . clone ( ) . unwrap ( ) ,
342
341
} ) ;
343
342
344
343
VariantIdx :: new ( state)
@@ -404,8 +403,7 @@ fn replace_local<'tcx>(
404
403
is_block_tail : None ,
405
404
local_info : LocalInfo :: Other ,
406
405
} ;
407
- let new_local = Local :: new ( body. local_decls . len ( ) ) ;
408
- body. local_decls . push ( new_decl) ;
406
+ let new_local = body. local_decls . push ( new_decl) ;
409
407
body. local_decls . swap ( local, new_local) ;
410
408
411
409
RenameLocalVisitor { from : local, to : new_local, tcx } . visit_body ( body) ;
@@ -431,7 +429,7 @@ struct LivenessInfo {
431
429
432
430
/// For every suspending block, the locals which are storage-live across
433
431
/// that suspension point.
434
- storage_liveness : FxHashMap < BasicBlock , liveness:: LiveVarSet > ,
432
+ storage_liveness : IndexVec < BasicBlock , Option < liveness:: LiveVarSet > > ,
435
433
}
436
434
437
435
fn locals_live_across_suspend_points (
@@ -472,7 +470,7 @@ fn locals_live_across_suspend_points(
472
470
let mut liveness = liveness:: liveness_of_locals ( body) ;
473
471
liveness:: dump_mir ( tcx, "generator_liveness" , source, body_ref, & liveness) ;
474
472
475
- let mut storage_liveness_map = FxHashMap :: default ( ) ;
473
+ let mut storage_liveness_map = IndexVec :: from_elem ( None , body . basic_blocks ( ) ) ;
476
474
let mut live_locals_at_suspension_points = Vec :: new ( ) ;
477
475
478
476
for ( block, data) in body. basic_blocks ( ) . iter_enumerated ( ) {
@@ -502,7 +500,7 @@ fn locals_live_across_suspend_points(
502
500
503
501
// Store the storage liveness for later use so we can restore the state
504
502
// after a suspension point
505
- storage_liveness_map. insert ( block, storage_liveness) ;
503
+ storage_liveness_map[ block] = Some ( storage_liveness) ;
506
504
507
505
requires_storage_cursor. seek_before ( loc) ;
508
506
let storage_required = requires_storage_cursor. get ( ) . clone ( ) ;
@@ -690,7 +688,7 @@ fn compute_layout<'tcx>(
690
688
) -> (
691
689
FxHashMap < Local , ( Ty < ' tcx > , VariantIdx , usize ) > ,
692
690
GeneratorLayout < ' tcx > ,
693
- FxHashMap < BasicBlock , liveness:: LiveVarSet > ,
691
+ IndexVec < BasicBlock , Option < liveness:: LiveVarSet > > ,
694
692
) {
695
693
// Use a liveness analysis to compute locals which are live across a suspension point
696
694
let LivenessInfo {
@@ -925,14 +923,12 @@ fn create_generator_drop_shim<'tcx>(
925
923
}
926
924
927
925
fn insert_term_block < ' tcx > ( body : & mut Body < ' tcx > , kind : TerminatorKind < ' tcx > ) -> BasicBlock {
928
- let term_block = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
929
926
let source_info = source_info ( body) ;
930
927
body. basic_blocks_mut ( ) . push ( BasicBlockData {
931
928
statements : Vec :: new ( ) ,
932
929
terminator : Some ( Terminator { source_info, kind } ) ,
933
930
is_cleanup : false ,
934
- } ) ;
935
- term_block
931
+ } )
936
932
}
937
933
938
934
fn insert_panic_block < ' tcx > (
@@ -1030,9 +1026,8 @@ fn create_generator_resume_function<'tcx>(
1030
1026
1031
1027
// Poison the generator when it unwinds
1032
1028
if can_unwind {
1033
- let poison_block = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
1034
1029
let source_info = source_info ( body) ;
1035
- body. basic_blocks_mut ( ) . push ( BasicBlockData {
1030
+ let poison_block = body. basic_blocks_mut ( ) . push ( BasicBlockData {
1036
1031
statements : vec ! [ transform. set_discr( VariantIdx :: new( POISONED ) , source_info) ] ,
1037
1032
terminator : Some ( Terminator { source_info, kind : TerminatorKind :: Resume } ) ,
1038
1033
is_cleanup : true ,
@@ -1105,21 +1100,19 @@ fn source_info(body: &Body<'_>) -> SourceInfo {
1105
1100
fn insert_clean_drop ( body : & mut Body < ' _ > ) -> BasicBlock {
1106
1101
let return_block = insert_term_block ( body, TerminatorKind :: Return ) ;
1107
1102
1108
- // Create a block to destroy an unresumed generators. This can only destroy upvars.
1109
- let drop_clean = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
1110
1103
let term = TerminatorKind :: Drop {
1111
1104
location : Place :: from ( SELF_ARG ) ,
1112
1105
target : return_block,
1113
1106
unwind : None ,
1114
1107
} ;
1115
1108
let source_info = source_info ( body) ;
1109
+
1110
+ // Create a block to destroy an unresumed generators. This can only destroy upvars.
1116
1111
body. basic_blocks_mut ( ) . push ( BasicBlockData {
1117
1112
statements : Vec :: new ( ) ,
1118
1113
terminator : Some ( Terminator { source_info, kind : term } ) ,
1119
1114
is_cleanup : false ,
1120
- } ) ;
1121
-
1122
- drop_clean
1115
+ } )
1123
1116
}
1124
1117
1125
1118
/// An operation that can be performed on a generator.
@@ -1151,7 +1144,6 @@ fn create_cases<'tcx>(
1151
1144
. filter_map ( |point| {
1152
1145
// Find the target for this suspension point, if applicable
1153
1146
operation. target_block ( point) . map ( |target| {
1154
- let block = BasicBlock :: new ( body. basic_blocks ( ) . len ( ) ) ;
1155
1147
let mut statements = Vec :: new ( ) ;
1156
1148
1157
1149
// Create StorageLive instructions for locals with live storage
@@ -1186,7 +1178,7 @@ fn create_cases<'tcx>(
1186
1178
}
1187
1179
1188
1180
// Then jump to the real target
1189
- body. basic_blocks_mut ( ) . push ( BasicBlockData {
1181
+ let block = body. basic_blocks_mut ( ) . push ( BasicBlockData {
1190
1182
statements,
1191
1183
terminator : Some ( Terminator {
1192
1184
source_info,
0 commit comments