@@ -124,7 +124,10 @@ pub struct Scope<'tcx> {
124
124
/// The cache for drop chain on "generator drop" exit.
125
125
cached_generator_drop : Option < BasicBlock > ,
126
126
127
- /// The cache for drop chain on "unwind" exit.
127
+ /// The cache for drop chain on "unwind" exit. This block
128
+ /// contains code to run the current drop and all the preceding
129
+ /// drops (i.e., those having lower index in Drop’s Scope drop
130
+ /// array)
128
131
cached_unwind : CachedBlock ,
129
132
}
130
133
@@ -141,21 +144,7 @@ struct DropData<'tcx> {
141
144
}
142
145
143
146
#[ derive( Debug , Default , Clone , Copy ) ]
144
- pub ( crate ) struct CachedBlock {
145
- /// The cached block for the cleanups-on-diverge path. This block
146
- /// contains code to run the current drop and all the preceding
147
- /// drops (i.e., those having lower index in Drop’s Scope drop
148
- /// array)
149
- unwind : Option < BasicBlock > ,
150
-
151
- /// The cached block for unwinds during cleanups-on-generator-drop path
152
- ///
153
- /// This is split from the standard unwind path here to prevent drop
154
- /// elaboration from creating drop flags that would have to be captured
155
- /// by the generator. I'm not sure how important this optimization is,
156
- /// but it is here.
157
- generator_drop : Option < BasicBlock > ,
158
- }
147
+ pub ( crate ) struct CachedBlock ( Option < BasicBlock > ) ;
159
148
160
149
#[ derive( Debug ) ]
161
150
pub ( crate ) enum DropKind {
@@ -181,24 +170,15 @@ pub struct BreakableScope<'tcx> {
181
170
182
171
impl CachedBlock {
183
172
fn invalidate ( & mut self ) {
184
- self . generator_drop = None ;
185
- self . unwind = None ;
173
+ self . 0 = None ;
186
174
}
187
175
188
- fn get ( & self , generator_drop : bool ) -> Option < BasicBlock > {
189
- if generator_drop {
190
- self . generator_drop
191
- } else {
192
- self . unwind
193
- }
176
+ fn get ( & self ) -> Option < BasicBlock > {
177
+ self . 0
194
178
}
195
179
196
- fn ref_mut ( & mut self , generator_drop : bool ) -> & mut Option < BasicBlock > {
197
- if generator_drop {
198
- & mut self . generator_drop
199
- } else {
200
- & mut self . unwind
201
- }
180
+ fn ref_mut ( & mut self ) -> & mut Option < BasicBlock > {
181
+ & mut self . 0
202
182
}
203
183
}
204
184
@@ -378,7 +358,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
378
358
assert_eq ! ( scope. region_scope, region_scope. 0 ) ;
379
359
380
360
let unwind_to = self . scopes . last ( ) . and_then ( |next_scope| {
381
- next_scope. cached_unwind . get ( false )
361
+ next_scope. cached_unwind . get ( )
382
362
} ) . unwrap_or_else ( || self . resume_block ( ) ) ;
383
363
384
364
unpack ! ( block = build_scope_drops(
@@ -387,7 +367,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
387
367
block,
388
368
unwind_to,
389
369
self . arg_count,
390
- false ,
391
370
) ) ;
392
371
393
372
block. unit ( )
@@ -442,7 +421,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
442
421
}
443
422
} ;
444
423
445
- let unwind_to = next_scope. cached_unwind . get ( false ) . unwrap_or_else ( || {
424
+ let unwind_to = next_scope. cached_unwind . get ( ) . unwrap_or_else ( || {
446
425
debug_assert ! ( !may_panic, "cached block not present?" ) ;
447
426
START_BLOCK
448
427
} ) ;
@@ -453,7 +432,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
453
432
block,
454
433
unwind_to,
455
434
self . arg_count,
456
- false ,
457
435
) ) ;
458
436
459
437
scope = next_scope;
@@ -470,7 +448,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
470
448
/// None indicates there’s no cleanup to do at this point.
471
449
pub fn generator_drop_cleanup ( & mut self ) -> Option < BasicBlock > {
472
450
// Fill in the cache for unwinds
473
- self . diverge_cleanup_gen ( true ) ;
451
+ self . diverge_cleanup_gen ( ) ;
474
452
475
453
let src_info = self . scopes [ 0 ] . source_info ( self . fn_span ) ;
476
454
let resume_block = self . resume_block ( ) ;
@@ -496,7 +474,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
496
474
} ;
497
475
498
476
let unwind_to = scopes. peek ( ) . as_ref ( ) . map ( |scope| {
499
- scope. cached_unwind . get ( true ) . unwrap_or_else ( || {
477
+ scope. cached_unwind . get ( ) . unwrap_or_else ( || {
500
478
span_bug ! ( src_info. span, "cached block not present?" )
501
479
} )
502
480
} ) . unwrap_or ( resume_block) ;
@@ -507,7 +485,6 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
507
485
block,
508
486
unwind_to,
509
487
self . arg_count,
510
- true ,
511
488
) ) ;
512
489
}
513
490
@@ -760,7 +737,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
760
737
/// This path terminates in Resume. Returns the start of the path.
761
738
/// See module comment for more details.
762
739
pub fn diverge_cleanup ( & mut self ) -> BasicBlock {
763
- self . diverge_cleanup_gen ( false )
740
+ self . diverge_cleanup_gen ( )
764
741
}
765
742
766
743
fn resume_block ( & mut self ) -> BasicBlock {
@@ -779,7 +756,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
779
756
}
780
757
}
781
758
782
- fn diverge_cleanup_gen ( & mut self , generator_drop : bool ) -> BasicBlock {
759
+ fn diverge_cleanup_gen ( & mut self ) -> BasicBlock {
783
760
// Build up the drops in **reverse** order. The end result will
784
761
// look like:
785
762
//
@@ -793,15 +770,15 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
793
770
794
771
// Find the last cached block
795
772
let ( mut target, first_uncached) = if let Some ( cached_index) = self . scopes . iter ( )
796
- . rposition ( |scope| scope. cached_unwind . get ( generator_drop ) . is_some ( ) ) {
797
- ( self . scopes [ cached_index] . cached_unwind . get ( generator_drop ) . unwrap ( ) , cached_index + 1 )
773
+ . rposition ( |scope| scope. cached_unwind . get ( ) . is_some ( ) ) {
774
+ ( self . scopes [ cached_index] . cached_unwind . get ( ) . unwrap ( ) , cached_index + 1 )
798
775
} else {
799
776
( self . resume_block ( ) , 0 )
800
777
} ;
801
778
802
779
for scope in self . scopes [ first_uncached..] . iter_mut ( ) {
803
780
target = build_diverge_scope ( & mut self . cfg , scope. region_scope_span ,
804
- scope, target, generator_drop , self . is_generator ) ;
781
+ scope, target, self . is_generator ) ;
805
782
}
806
783
807
784
target
@@ -881,7 +858,6 @@ fn build_scope_drops<'tcx>(
881
858
mut block : BasicBlock ,
882
859
last_unwind_to : BasicBlock ,
883
860
arg_count : usize ,
884
- generator_drop : bool ,
885
861
) -> BlockAnd < ( ) > {
886
862
debug ! ( "build_scope_drops({:?} -> {:?}" , block, scope) ;
887
863
@@ -902,7 +878,7 @@ fn build_scope_drops<'tcx>(
902
878
903
879
let mut unwind_blocks = scope. drops . iter ( ) . rev ( ) . filter_map ( |drop_data| {
904
880
if let DropKind :: Value { cached_block } = drop_data. kind {
905
- Some ( cached_block. get ( generator_drop ) . unwrap_or_else ( || {
881
+ Some ( cached_block. get ( ) . unwrap_or_else ( || {
906
882
span_bug ! ( drop_data. span, "cached block not present?" )
907
883
} ) )
908
884
} else {
@@ -946,13 +922,12 @@ fn build_scope_drops<'tcx>(
946
922
block. unit ( )
947
923
}
948
924
949
- fn build_diverge_scope < ' tcx > ( cfg : & mut CFG < ' tcx > ,
950
- span : Span ,
951
- scope : & mut Scope < ' tcx > ,
952
- mut target : BasicBlock ,
953
- generator_drop : bool ,
954
- is_generator : bool )
955
- -> BasicBlock
925
+ fn build_diverge_scope ( cfg : & mut CFG < ' tcx > ,
926
+ span : Span ,
927
+ scope : & mut Scope < ' tcx > ,
928
+ mut target : BasicBlock ,
929
+ is_generator : bool )
930
+ -> BasicBlock
956
931
{
957
932
// Build up the drops in **reverse** order. The end result will
958
933
// look like:
@@ -1004,7 +979,7 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1004
979
}
1005
980
DropKind :: Storage => { }
1006
981
DropKind :: Value { ref mut cached_block } => {
1007
- let cached_block = cached_block. ref_mut ( generator_drop ) ;
982
+ let cached_block = cached_block. ref_mut ( ) ;
1008
983
target = if let Some ( cached_block) = * cached_block {
1009
984
storage_deads. clear ( ) ;
1010
985
target_built_by_us = false ;
@@ -1027,7 +1002,7 @@ fn build_diverge_scope<'tcx>(cfg: &mut CFG<'tcx>,
1027
1002
} ;
1028
1003
}
1029
1004
push_storage_deads ( cfg, & mut target, & mut storage_deads, target_built_by_us, source_scope) ;
1030
- * scope. cached_unwind . ref_mut ( generator_drop ) = Some ( target) ;
1005
+ * scope. cached_unwind . ref_mut ( ) = Some ( target) ;
1031
1006
1032
1007
assert ! ( storage_deads. is_empty( ) ) ;
1033
1008
debug ! ( "build_diverge_scope({:?}, {:?}) = {:?}" , scope, span, target) ;
0 commit comments