Skip to content

Commit 0be736b

Browse files
committed
Move state transform after optimizations.
1 parent 50b076f commit 0be736b

17 files changed

+227
-298
lines changed

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
616616
// Otherwise it should run fairly late, but before optimizations begin.
617617
&add_retag::AddRetag,
618618
&elaborate_box_derefs::ElaborateBoxDerefs,
619-
&coroutine::StateTransform,
620619
&Lint(known_panics_lint::KnownPanicsLint),
621620
];
622621
pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial)));
@@ -722,6 +721,7 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
722721
&simplify::SimplifyLocals::Final,
723722
&multiple_return_terminators::MultipleReturnTerminators,
724723
&large_enums::EnumSizeOpt { discrepancy: 128 },
724+
&coroutine::StateTransform,
725725
// Some cleanup necessary at least for LLVM and potentially other codegen backends.
726726
&add_call_guards::CriticalCallEdges,
727727
// Cleanup for human readability, off by default.

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
149149
tcx,
150150
&mut body,
151151
&[
152-
&mentioned_items::MentionedItems,
153152
&abort_unwinding_calls::AbortUnwindingCalls,
154153
&add_call_guards::CriticalCallEdges,
155154
],

compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ fn build_adrop_for_coroutine_shim<'tcx>(
216216
body.source.instance = instance;
217217
body.phase = MirPhase::Runtime(RuntimePhase::Initial);
218218
body.var_debug_info.clear();
219+
body.mentioned_items = None;
219220
let pin_adt_ref = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, span));
220221
let args = tcx.mk_args(&[proxy_ref.into()]);
221222
let pin_proxy_ref = Ty::new_adt(tcx, pin_adt_ref, args);

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,72 +28,68 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2828

2929
bb0: {
3030
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
31-
switchInt(move _20) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14];
31+
switchInt(move _20) -> [0: bb8, 3: bb11, 4: bb12, otherwise: bb13];
3232
}
3333

3434
bb1: {
3535
nop;
3636
nop;
37-
goto -> bb2;
38-
}
39-
40-
bb2: {
4137
_0 = Poll::<()>::Ready(const ());
4238
return;
4339
}
4440

45-
bb3: {
41+
bb2: {
4642
_0 = Poll::<()>::Pending;
4743
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 4;
4844
return;
4945
}
5046

51-
bb4: {
47+
bb3: {
5248
StorageLive(_16);
5349
_15 = &mut (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).1: impl std::future::Future<Output = ()>);
54-
_16 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _15) -> [return: bb7, unwind unreachable];
50+
_16 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _15) -> [return: bb6, unwind unreachable];
5551
}
5652

57-
bb5: {
53+
bb4: {
5854
unreachable;
5955
}
6056

61-
bb6: {
57+
bb5: {
6258
StorageDead(_16);
6359
_17 = discriminant(_9);
64-
switchInt(move _17) -> [0: bb1, 1: bb3, otherwise: bb5];
60+
switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4];
6561
}
6662

67-
bb7: {
68-
_9 = <impl Future<Output = ()> as Future>::poll(move _16, move _14) -> [return: bb6, unwind unreachable];
63+
bb6: {
64+
_9 = <impl Future<Output = ()> as Future>::poll(move _16, move _14) -> [return: bb5, unwind unreachable];
6965
}
7066

71-
bb8: {
67+
bb7: {
7268
_0 = Poll::<()>::Ready(const ());
7369
return;
7470
}
7571

72+
bb8: {
73+
goto -> bb10;
74+
}
75+
7676
bb9: {
77-
goto -> bb11;
77+
goto -> bb7;
7878
}
7979

8080
bb10: {
81-
goto -> bb8;
81+
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb9, unwind unreachable];
8282
}
8383

8484
bb11: {
85-
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb10, unwind unreachable];
85+
goto -> bb3;
8686
}
8787

8888
bb12: {
89-
goto -> bb4;
89+
goto -> bb3;
9090
}
9191

9292
bb13: {
93-
goto -> bb4;
94-
}
95-
96-
bb14: {
9793
_0 = Poll::<()>::Ready(const ());
9894
return;
9995
}

tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,95 +28,81 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2828

2929
bb0: {
3030
_20 = discriminant((*(_1.0: &mut {async fn body of a<T>()})));
31-
switchInt(move _20) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19];
31+
switchInt(move _20) -> [0: bb8, 2: bb15, 3: bb13, 4: bb14, otherwise: bb16];
3232
}
3333

3434
bb1: {
3535
nop;
3636
nop;
37-
goto -> bb2;
38-
}
39-
40-
bb2: {
4137
_0 = Poll::<()>::Ready(const ());
4238
return;
4339
}
4440

45-
bb3 (cleanup): {
46-
nop;
47-
nop;
48-
goto -> bb5;
49-
}
50-
51-
bb4 (cleanup): {
52-
goto -> bb15;
53-
}
54-
55-
bb5 (cleanup): {
56-
goto -> bb4;
57-
}
58-
59-
bb6: {
41+
bb2: {
6042
_0 = Poll::<()>::Pending;
6143
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 4;
6244
return;
6345
}
6446

65-
bb7: {
47+
bb3: {
6648
StorageLive(_16);
6749
_15 = &mut (((*(_1.0: &mut {async fn body of a<T>()})) as variant#4).1: impl std::future::Future<Output = ()>);
68-
_16 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _15) -> [return: bb10, unwind: bb15];
50+
_16 = Pin::<&mut impl Future<Output = ()>>::new_unchecked(move _15) -> [return: bb6, unwind: bb12];
6951
}
7052

71-
bb8: {
53+
bb4: {
7254
unreachable;
7355
}
7456

75-
bb9: {
57+
bb5: {
7658
StorageDead(_16);
7759
_17 = discriminant(_9);
78-
switchInt(move _17) -> [0: bb1, 1: bb6, otherwise: bb8];
60+
switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4];
7961
}
8062

81-
bb10: {
82-
_9 = <impl Future<Output = ()> as Future>::poll(move _16, move _14) -> [return: bb9, unwind: bb3];
63+
bb6: {
64+
_9 = <impl Future<Output = ()> as Future>::poll(move _16, move _14) -> [return: bb5, unwind: bb12];
8365
}
8466

85-
bb11: {
67+
bb7: {
8668
_0 = Poll::<()>::Ready(const ());
8769
return;
8870
}
8971

90-
bb12: {
91-
goto -> bb14;
72+
bb8: {
73+
goto -> bb11;
9274
}
9375

94-
bb13: {
95-
goto -> bb11;
76+
bb9 (cleanup): {
77+
goto -> bb12;
9678
}
9779

98-
bb14: {
99-
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb13, unwind: bb4];
80+
bb10: {
81+
goto -> bb7;
10082
}
10183

102-
bb15 (cleanup): {
84+
bb11: {
85+
drop(((*(_1.0: &mut {async fn body of a<T>()})).0: T)) -> [return: bb10, unwind: bb9];
86+
}
87+
88+
bb12 (cleanup): {
10389
discriminant((*(_1.0: &mut {async fn body of a<T>()}))) = 2;
10490
resume;
10591
}
10692

107-
bb16: {
108-
goto -> bb7;
93+
bb13: {
94+
goto -> bb3;
10995
}
11096

111-
bb17: {
112-
goto -> bb7;
97+
bb14: {
98+
goto -> bb3;
11399
}
114100

115-
bb18: {
116-
assert(const false, "`async fn` resumed after panicking") -> [success: bb18, unwind continue];
101+
bb15: {
102+
assert(const false, "`async fn` resumed after panicking") -> [success: bb15, unwind continue];
117103
}
118104

119-
bb19: {
105+
bb16: {
120106
_0 = Poll::<()>::Ready(const ());
121107
return;
122108
}

0 commit comments

Comments
 (0)