Skip to content

Commit 0d36257

Browse files
committed
Inline more when we do inline
To offset the less inlining in simple forwarding functions.
1 parent 00c4b72 commit 0d36257

10 files changed

+302
-163
lines changed

compiler/rustc_mir_transform/src/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ impl<'tcx> Inliner<'tcx> {
154154
self.changed = true;
155155

156156
self.history.push(callsite.callee.def_id());
157-
self.process_blocks(caller_body, new_blocks);
157+
self.process_blocks(caller_body, new_blocks.clone());
158158
self.history.pop();
159159

160-
inlined_count += 1;
160+
inlined_count += usize::from(new_blocks.count() > 2);
161161
if inlined_count == inline_limit {
162162
debug!("inline count reached");
163163
return;

tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff

+99-30
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,50 @@
5555
+ let _26: ();
5656
+ scope 9 {
5757
+ }
58+
+ scope 12 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) {
59+
+ }
60+
+ scope 13 (inlined <std::future::Ready<()> as Future>::poll) {
61+
+ let mut _42: ();
62+
+ let mut _43: std::option::Option<()>;
63+
+ let mut _44: &mut std::option::Option<()>;
64+
+ let mut _45: &mut std::future::Ready<()>;
65+
+ let mut _46: &mut std::pin::Pin<&mut std::future::Ready<()>>;
66+
+ scope 14 (inlined <Pin<&mut std::future::Ready<()>> as DerefMut>::deref_mut) {
67+
+ let mut _47: std::pin::Pin<&mut std::future::Ready<()>>;
68+
+ scope 15 (inlined Pin::<&mut std::future::Ready<()>>::as_mut) {
69+
+ let mut _48: &mut &mut std::future::Ready<()>;
70+
+ scope 16 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) {
71+
+ }
72+
+ scope 18 (inlined <&mut std::future::Ready<()> as DerefMut>::deref_mut) {
73+
+ }
74+
+ }
75+
+ scope 17 (inlined Pin::<&mut std::future::Ready<()>>::get_mut) {
76+
+ }
77+
+ }
78+
+ scope 19 (inlined Option::<()>::take) {
79+
+ let mut _49: std::option::Option<()>;
80+
+ scope 20 (inlined std::mem::replace::<Option<()>>) {
81+
+ scope 21 {
82+
+ scope 23 (inlined std::ptr::write::<Option<()>>) {
83+
+ }
84+
+ }
85+
+ scope 22 (inlined std::ptr::read::<Option<()>>) {
86+
+ }
87+
+ }
88+
+ }
89+
+ scope 24 (inlined #[track_caller] Option::<()>::expect) {
90+
+ let mut _50: isize;
91+
+ let mut _51: !;
92+
+ scope 25 {
93+
+ }
94+
+ }
95+
+ }
5896
+ }
5997
+ scope 10 (inlined ready::<()>) {
6098
+ let mut _41: std::option::Option<()>;
6199
+ }
100+
+ scope 11 (inlined <std::future::Ready<()> as IntoFuture>::into_future) {
101+
+ }
62102
+ }
63103
+ }
64104
}
@@ -113,7 +153,7 @@
113153
+ StorageLive(_40);
114154
+ _33 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
115155
+ _32 = discriminant((*_33));
116-
+ switchInt(move _32) -> [0: bb3, 1: bb13, 3: bb12, otherwise: bb8];
156+
+ switchInt(move _32) -> [0: bb3, 1: bb10, 3: bb9, otherwise: bb5];
117157
}
118158

119159
- bb3: {
@@ -164,19 +204,16 @@
164204
+ _13 = std::future::Ready::<()>(move _41);
165205
+ StorageDead(_41);
166206
+ StorageDead(_14);
167-
+ _12 = <std::future::Ready<()> as IntoFuture>::into_future(move _13) -> [return: bb4, unwind unreachable];
168-
+ }
169-
+
170-
bb4: {
171-
- StorageDead(_2);
172-
- return;
207+
+ _12 = move _13;
173208
+ StorageDead(_13);
174209
+ _36 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
175210
+ (((*_36) as variant#3).1: std::future::Ready<()>) = move _12;
176-
+ goto -> bb5;
211+
+ goto -> bb4;
177212
+ }
178213
+
179-
+ bb5: {
214+
bb4: {
215+
- StorageDead(_2);
216+
- return;
180217
+ StorageLive(_17);
181218
+ StorageLive(_18);
182219
+ StorageLive(_19);
@@ -185,10 +222,7 @@
185222
+ _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
186223
+ _21 = &mut (((*_37) as variant#3).1: std::future::Ready<()>);
187224
+ _20 = &mut (*_21);
188-
+ _19 = Pin::<&mut std::future::Ready<()>>::new_unchecked(move _20) -> [return: bb6, unwind unreachable];
189-
+ }
190-
+
191-
+ bb6: {
225+
+ _19 = Pin::<&mut std::future::Ready<()>> { __pointer: _20 };
192226
+ StorageDead(_20);
193227
+ StorageLive(_22);
194228
+ StorageLive(_23);
@@ -197,21 +231,36 @@
197231
+ _23 = move _24;
198232
+ _22 = &mut (*_23);
199233
+ StorageDead(_24);
200-
+ _18 = <std::future::Ready<()> as Future>::poll(move _19, move _22) -> [return: bb7, unwind unreachable];
201-
+ }
202-
+
203-
+ bb7: {
204-
+ StorageDead(_22);
205-
+ StorageDead(_19);
206-
+ _25 = discriminant(_18);
207-
+ switchInt(move _25) -> [0: bb10, 1: bb9, otherwise: bb8];
234+
+ StorageLive(_45);
235+
+ StorageLive(_46);
236+
+ StorageLive(_49);
237+
+ StorageLive(_51);
238+
+ StorageLive(_42);
239+
+ StorageLive(_43);
240+
+ StorageLive(_44);
241+
+ _46 = &mut _19;
242+
+ StorageLive(_47);
243+
+ StorageLive(_48);
244+
+ _48 = &mut (_19.0: &mut std::future::Ready<()>);
245+
+ _45 = (_19.0: &mut std::future::Ready<()>);
246+
+ StorageDead(_48);
247+
+ _47 = Pin::<&mut std::future::Ready<()>> { __pointer: _45 };
248+
+ StorageDead(_47);
249+
+ _44 = &mut ((*_45).0: std::option::Option<()>);
250+
+ _49 = Option::<()>::None;
251+
+ _43 = ((*_45).0: std::option::Option<()>);
252+
+ ((*_45).0: std::option::Option<()>) = _49;
253+
+ StorageDead(_44);
254+
+ StorageLive(_50);
255+
+ _50 = discriminant(_43);
256+
+ switchInt(move _50) -> [0: bb11, 1: bb12, otherwise: bb5];
208257
+ }
209258
+
210-
+ bb8: {
259+
+ bb5: {
211260
+ unreachable;
212261
+ }
213262
+
214-
+ bb9: {
263+
+ bb6: {
215264
+ _17 = const ();
216265
+ StorageDead(_23);
217266
+ StorageDead(_21);
@@ -229,7 +278,7 @@
229278
+ goto -> bb2;
230279
+ }
231280
+
232-
+ bb10: {
281+
+ bb7: {
233282
+ StorageLive(_26);
234283
+ _26 = ((_18 as Ready).0: ());
235284
+ _30 = _26;
@@ -240,17 +289,17 @@
240289
+ StorageDead(_17);
241290
+ StorageDead(_12);
242291
+ _39 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
243-
+ drop((((*_39) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb11, unwind unreachable];
292+
+ drop((((*_39) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb8, unwind unreachable];
244293
+ }
245294
+
246-
+ bb11: {
295+
+ bb8: {
247296
+ _7 = Poll::<()>::Ready(move _30);
248297
+ _40 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()});
249298
+ discriminant((*_40)) = 1;
250299
+ goto -> bb2;
251300
+ }
252301
+
253-
+ bb12: {
302+
+ bb9: {
254303
+ StorageLive(_12);
255304
+ StorageLive(_28);
256305
+ StorageLive(_29);
@@ -259,11 +308,31 @@
259308
+ _31 = move _28;
260309
+ StorageDead(_28);
261310
+ _16 = const ();
262-
+ goto -> bb5;
311+
+ goto -> bb4;
263312
+ }
264313
+
265-
+ bb13: {
266-
+ assert(const false, "`async fn` resumed after completion") -> [success: bb13, unwind unreachable];
314+
+ bb10: {
315+
+ assert(const false, "`async fn` resumed after completion") -> [success: bb10, unwind unreachable];
316+
+ }
317+
+
318+
+ bb11: {
319+
+ _51 = option::expect_failed(const "`Ready` polled after completion") -> unwind unreachable;
320+
+ }
321+
+
322+
+ bb12: {
323+
+ _42 = move ((_43 as Some).0: ());
324+
+ StorageDead(_50);
325+
+ StorageDead(_43);
326+
+ _18 = Poll::<()>::Ready(move _42);
327+
+ StorageDead(_42);
328+
+ StorageDead(_51);
329+
+ StorageDead(_49);
330+
+ StorageDead(_46);
331+
+ StorageDead(_45);
332+
+ StorageDead(_22);
333+
+ StorageDead(_19);
334+
+ _25 = discriminant(_18);
335+
+ switchInt(move _25) -> [0: bb7, 1: bb6, otherwise: bb5];
267336
}
268337
}
269338

0 commit comments

Comments
 (0)