@@ -1058,17 +1058,12 @@ fn build_async_destructor_ctor_shim<'tcx>(
1058
1058
def_id : DefId ,
1059
1059
self_ty : Ty < ' tcx > ,
1060
1060
) -> Body < ' tcx > {
1061
- // FIXME: implement cleanup branches
1062
-
1063
- let span = tcx. def_span ( def_id) ;
1064
- let Some ( sig) = tcx. fn_sig ( def_id) . instantiate ( tcx, & [ self_ty. into ( ) ] ) . no_bound_vars ( ) else {
1065
- span_bug ! ( span, "async_drop_in_place_raw with bound vars for `{self_ty}`" ) ;
1066
- } ;
1061
+ let mut builder = AsyncDestructorCtorShimBuilder :: new ( tcx, def_id, self_ty) ;
1067
1062
1063
+ let source_info = builder. source_info ;
1064
+ let span = builder. span ;
1068
1065
let param_env = tcx. param_env_reveal_all_normalized ( def_id) ;
1069
- let source_info = SourceInfo :: outermost ( span) ;
1070
1066
1071
- let mut locals = local_decls_for_sig ( & sig, span) ;
1072
1067
let return_local = Local :: new ( 0 ) ;
1073
1068
let self_ptr = Local :: new ( 1 ) ;
1074
1069
@@ -1174,39 +1169,18 @@ fn build_async_destructor_ctor_shim<'tcx>(
1174
1169
} ;
1175
1170
1176
1171
let return_bb;
1177
- let mut blocks;
1172
+ let mut blocks = & mut builder . bbs ;
1178
1173
match strategy {
1179
1174
GlueStrategy :: Empty => {
1180
- let ready_unit_fn = tcx. require_lang_item ( LangItem :: FutureReadyUnitCtor , Some ( span) ) ;
1181
-
1182
- blocks = IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 2 ) ;
1183
- let ready_unit_bb = BasicBlock :: new ( 0 ) ;
1184
- return_bb = BasicBlock :: new ( 1 ) ;
1185
-
1186
- blocks[ ready_unit_bb] . terminator = Some ( Terminator {
1187
- source_info,
1188
- kind : TerminatorKind :: Call {
1189
- func : Operand :: function_handle (
1190
- tcx,
1191
- ready_unit_fn,
1192
- [ /* HOST */ tcx. consts . false_ . into ( ) ] ,
1193
- span,
1194
- ) ,
1195
- args : Vec :: new ( ) ,
1196
- destination : return_local. into ( ) ,
1197
- target : Some ( return_bb) ,
1198
- unwind : UnwindAction :: Continue ,
1199
- call_source : CallSource :: Misc ,
1200
- fn_span : span,
1201
- } ,
1202
- } ) ;
1175
+ builder. ready_unit ( ) ;
1176
+ return builder. return_ ( ) ;
1203
1177
}
1204
1178
1205
1179
GlueStrategy :: AsyncDropProjection => {
1206
1180
let surface_async_drop_in_place_fn =
1207
1181
tcx. require_lang_item ( LangItem :: SurfaceAsyncDropInPlace , Some ( span) ) ;
1208
1182
1209
- blocks = IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 2 ) ;
1183
+ * blocks = IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 2 ) ;
1210
1184
let surface_async_drop_in_place_bb = BasicBlock :: new ( 0 ) ;
1211
1185
return_bb = BasicBlock :: new ( 1 ) ;
1212
1186
@@ -1216,7 +1190,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1216
1190
func : Operand :: function_handle (
1217
1191
tcx,
1218
1192
surface_async_drop_in_place_fn,
1219
- [ self_ty. into ( ) ] ,
1193
+ iter :: once ( self_ty. into ( ) ) ,
1220
1194
span,
1221
1195
) ,
1222
1196
args : vec ! [ respan( span, Operand :: Move ( self_ptr. into( ) ) ) ] ,
@@ -1233,13 +1207,14 @@ fn build_async_destructor_ctor_shim<'tcx>(
1233
1207
let slice_async_destructor_fn =
1234
1208
tcx. require_lang_item ( LangItem :: SliceAsyncDestructorCtor , Some ( span) ) ;
1235
1209
1236
- blocks = IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 2 ) ;
1210
+ * blocks = IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 2 ) ;
1237
1211
let slice_async_destructor_bb = BasicBlock :: new ( 0 ) ;
1238
1212
return_bb = BasicBlock :: new ( 1 ) ;
1239
1213
1240
1214
let slice_ptr = if is_array {
1241
1215
let slice_ptr_ty = Ty :: new_mut_ptr ( tcx, Ty :: new_slice ( tcx, elem_ty) ) ;
1242
- let slice_ptr = locals. push ( LocalDecl :: with_source_info ( slice_ptr_ty, source_info) ) ;
1216
+ let slice_ptr =
1217
+ builder. locals . push ( LocalDecl :: with_source_info ( slice_ptr_ty, source_info) ) ;
1243
1218
1244
1219
blocks[ slice_async_destructor_bb] . statements = vec ! [
1245
1220
Statement { source_info, kind: StatementKind :: StorageLive ( slice_ptr) } ,
@@ -1266,7 +1241,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1266
1241
func : Operand :: function_handle (
1267
1242
tcx,
1268
1243
slice_async_destructor_fn,
1269
- [ elem_ty. into ( ) , /* HOST */ tcx . consts . false_ . into ( ) ] ,
1244
+ iter :: once ( elem_ty. into ( ) ) ,
1270
1245
span,
1271
1246
) ,
1272
1247
args : vec ! [ respan( span, Operand :: Move ( slice_ptr. into( ) ) ) ] ,
@@ -1299,18 +1274,18 @@ fn build_async_destructor_ctor_shim<'tcx>(
1299
1274
tcx. type_of ( tcx. require_lang_item ( LangItem :: FutureChain , Some ( span) ) ) ;
1300
1275
let future_chain_fn = tcx. require_lang_item ( LangItem :: FutureChainCtor , Some ( span) ) ;
1301
1276
1302
- locals. raw . reserve (
1277
+ builder . locals . raw . reserve (
1303
1278
1 + LOCALS_PER_ELEM * elem_count + if has_surface_async_drop { 2 } else { 0 } ,
1304
1279
) ;
1305
1280
1306
1281
// this local is right before element locals
1307
1282
let ready_unit_local =
1308
- locals. push ( LocalDecl :: with_source_info ( ready_unit_ty, source_info) ) ;
1283
+ builder . locals . push ( LocalDecl :: with_source_info ( ready_unit_ty, source_info) ) ;
1309
1284
1310
- let locals_base = locals. len ( ) ;
1285
+ let locals_base = builder . locals . len ( ) ;
1311
1286
let mut last_chain_ty = ready_unit_ty;
1312
1287
// Creating temproraries to store intermediate futuresh
1313
- locals. extend (
1288
+ builder . locals . extend (
1314
1289
elem_tys
1315
1290
. iter ( )
1316
1291
. rev ( )
@@ -1327,7 +1302,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1327
1302
. map ( |ty| LocalDecl :: with_source_info ( ty, source_info) ) ,
1328
1303
) ;
1329
1304
1330
- blocks =
1305
+ * blocks =
1331
1306
IndexVec :: from_elem_n ( BasicBlockData :: new ( None ) , 4 + BBS_PER_ELEM * elem_count) ;
1332
1307
let ready_unit_bb = BasicBlock :: new ( 0 ) ;
1333
1308
let bbs_base = 1 ;
@@ -1380,12 +1355,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1380
1355
blocks[ ready_unit_bb] . terminator = Some ( Terminator {
1381
1356
source_info,
1382
1357
kind : TerminatorKind :: Call {
1383
- func : Operand :: function_handle (
1384
- tcx,
1385
- ready_unit_fn,
1386
- [ /* HOST */ tcx. consts . false_ . into ( ) ] ,
1387
- span,
1388
- ) ,
1358
+ func : Operand :: function_handle ( tcx, ready_unit_fn, iter:: empty ( ) , span) ,
1389
1359
args : Vec :: new ( ) ,
1390
1360
destination : ready_unit_local. into ( ) ,
1391
1361
target : Some ( chain_nodes ( ) . next ( ) . unwrap ( ) . deferred_dtor_bb ) ,
@@ -1426,7 +1396,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1426
1396
func : Operand :: function_handle (
1427
1397
tcx,
1428
1398
deferred_async_drop_fn,
1429
- [ node. elem_ty . into ( ) , /* HOST */ tcx . consts . false_ . into ( ) ] ,
1399
+ iter :: once ( node. elem_ty . into ( ) ) ,
1430
1400
span,
1431
1401
) ,
1432
1402
args : vec ! [ respan( span, Operand :: Move ( node. elem_ptr_local. into( ) ) ) ] ,
@@ -1452,9 +1422,8 @@ fn build_async_destructor_ctor_shim<'tcx>(
1452
1422
tcx,
1453
1423
future_chain_fn,
1454
1424
[
1455
- locals[ node. deferred_dtor_local ] . ty . into ( ) ,
1456
- locals[ node. previous_chain_local ] . ty . into ( ) ,
1457
- /* HOST */ tcx. consts . false_ . into ( ) ,
1425
+ builder. locals [ node. deferred_dtor_local ] . ty . into ( ) ,
1426
+ builder. locals [ node. previous_chain_local ] . ty . into ( ) ,
1458
1427
] ,
1459
1428
span,
1460
1429
) ,
@@ -1501,11 +1470,11 @@ fn build_async_destructor_ctor_shim<'tcx>(
1501
1470
) ;
1502
1471
1503
1472
let async_dropper_local =
1504
- locals. push ( LocalDecl :: with_source_info ( async_dropper_ty, source_info) ) ;
1473
+ builder . locals . push ( LocalDecl :: with_source_info ( async_dropper_ty, source_info) ) ;
1505
1474
let surface_chain_ty = future_chain_ty
1506
1475
. instantiate ( tcx, & [ async_dropper_ty. into ( ) , last_chain_ty. into ( ) ] ) ;
1507
1476
let surface_chain_local =
1508
- locals. push ( LocalDecl :: with_source_info ( surface_chain_ty, source_info) ) ;
1477
+ builder . locals . push ( LocalDecl :: with_source_info ( surface_chain_ty, source_info) ) ;
1509
1478
1510
1479
blocks[ maybe_async_dropper_bb] . statements = vec ! [ Statement {
1511
1480
source_info,
@@ -1517,7 +1486,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1517
1486
func : Operand :: function_handle (
1518
1487
tcx,
1519
1488
surface_async_drop_fn,
1520
- [ self_ty. into ( ) ] ,
1489
+ iter :: once ( self_ty. into ( ) ) ,
1521
1490
span,
1522
1491
) ,
1523
1492
args : vec ! [ respan( span, Operand :: Move ( self_ptr. into( ) ) ) ] ,
@@ -1539,11 +1508,7 @@ fn build_async_destructor_ctor_shim<'tcx>(
1539
1508
func : Operand :: function_handle (
1540
1509
tcx,
1541
1510
future_chain_fn,
1542
- [
1543
- async_dropper_ty. into ( ) ,
1544
- last_chain_ty. into ( ) ,
1545
- /* HOST */ tcx. consts . false_ . into ( ) ,
1546
- ] ,
1511
+ [ async_dropper_ty. into ( ) , last_chain_ty. into ( ) ] ,
1547
1512
span,
1548
1513
) ,
1549
1514
args : vec ! [
@@ -1601,10 +1566,11 @@ fn build_async_destructor_ctor_shim<'tcx>(
1601
1566
}
1602
1567
}
1603
1568
1604
- blocks[ return_bb] . terminator = Some ( Terminator { source_info, kind : TerminatorKind :: Return } ) ;
1569
+ builder. bbs [ return_bb] . terminator =
1570
+ Some ( Terminator { source_info, kind : TerminatorKind :: Return } ) ;
1605
1571
1606
1572
let source = MirSource :: from_instance ( ty:: InstanceDef :: AsyncDropGlueCtorShim ( def_id, self_ty) ) ;
1607
- new_body ( source, blocks , locals, sig . inputs ( ) . len ( ) , span)
1573
+ new_body ( source, builder . bbs , builder . locals , ASYNC_DESTRUCTOR_CTOR_ARG_COUNT , span)
1608
1574
}
1609
1575
1610
1576
const ASYNC_DESTRUCTOR_CTOR_ARG_COUNT : usize = 1 ;
0 commit comments