Skip to content

Commit 42359ce

Browse files
committed
Move state transform after optimizations.
1 parent f18eb33 commit 42359ce

19 files changed

+244
-354
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ const SELF_ARG: Local = Local::from_u32(1);
177177
const CTX_ARG: Local = Local::from_u32(2);
178178

179179
/// A `yield` point in the coroutine.
180+
#[derive(Debug)]
180181
struct SuspensionPoint<'tcx> {
181182
/// State discriminant used when suspending or resuming at this point.
182183
state: usize,

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
621621
// Otherwise it should run fairly late, but before optimizations begin.
622622
&add_retag::AddRetag,
623623
&elaborate_box_derefs::ElaborateBoxDerefs,
624-
&coroutine::StateTransform,
625624
&Lint(known_panics_lint::KnownPanicsLint),
626625
];
627626
pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial)));
@@ -727,6 +726,7 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'
727726
&simplify::SimplifyLocals::Final,
728727
&multiple_return_terminators::MultipleReturnTerminators,
729728
&large_enums::EnumSizeOpt { discrepancy: 128 },
729+
&coroutine::StateTransform,
730730
// Some cleanup necessary at least for LLVM and potentially other codegen backends.
731731
&add_call_guards::CriticalCallEdges,
732732
// 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
@@ -27,72 +27,68 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2727

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

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

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

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

56-
bb5: {
52+
bb4: {
5753
unreachable;
5854
}
5955

60-
bb6: {
56+
bb5: {
6157
StorageDead(_16);
6258
_17 = discriminant(_9);
63-
switchInt(move _17) -> [0: bb1, 1: bb3, otherwise: bb5];
59+
switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4];
6460
}
6561

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

70-
bb8: {
66+
bb7: {
7167
_0 = Poll::<()>::Ready(const ());
7268
return;
7369
}
7470

71+
bb8: {
72+
goto -> bb10;
73+
}
74+
7575
bb9: {
76-
goto -> bb11;
76+
goto -> bb7;
7777
}
7878

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

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

8787
bb12: {
88-
goto -> bb4;
88+
goto -> bb3;
8989
}
9090

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

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
@@ -27,95 +27,81 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a<T>()}>, _2: &mut Context<'_>)
2727

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

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

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

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

70-
bb8: {
52+
bb4: {
7153
unreachable;
7254
}
7355

74-
bb9: {
56+
bb5: {
7557
StorageDead(_16);
7658
_17 = discriminant(_9);
77-
switchInt(move _17) -> [0: bb1, 1: bb6, otherwise: bb8];
59+
switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4];
7860
}
7961

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

84-
bb11: {
66+
bb7: {
8567
_0 = Poll::<()>::Ready(const ());
8668
return;
8769
}
8870

89-
bb12: {
90-
goto -> bb14;
71+
bb8: {
72+
goto -> bb11;
9173
}
9274

93-
bb13: {
94-
goto -> bb11;
75+
bb9 (cleanup): {
76+
goto -> bb12;
9577
}
9678

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

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

106-
bb16: {
107-
goto -> bb7;
92+
bb13: {
93+
goto -> bb3;
10894
}
10995

110-
bb17: {
111-
goto -> bb7;
96+
bb14: {
97+
goto -> bb3;
11298
}
11399

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

118-
bb19: {
104+
bb16: {
119105
_0 = Poll::<()>::Ready(const ());
120106
return;
121107
}

0 commit comments

Comments
 (0)