Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_mir_transform/src/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,16 @@ impl<'tcx> Inliner<'tcx> {
Ok(new_blocks) => {
debug!("inlined {}", callsite.callee);
self.changed = true;

self.history.push(callsite.callee.def_id());
self.process_blocks(caller_body, new_blocks);
self.history.pop();

inlined_count += 1;
if inlined_count == inline_limit {
debug!("inline count reached");
return;
}
self.history.push(callsite.callee.def_id());
self.process_blocks(caller_body, new_blocks);
self.history.pop();
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion tests/mir-opt/inline/cycle.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
+ let mut _3: &fn() {g}; // in scope 1 at $DIR/cycle.rs:6:5: 6:6
+ let _4: (); // in scope 1 at $DIR/cycle.rs:6:5: 6:8
+ scope 2 (inlined <fn() {g} as Fn<()>>::call - shim(fn() {g})) { // at $DIR/cycle.rs:6:5: 6:8
+ scope 3 (inlined g) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ scope 4 (inlined f::<fn() {main}>) { // at $DIR/cycle.rs:12:5: 12:12
+ debug g => main; // in scope 4 at $DIR/cycle.rs:5:6: 5:7
+ let _6: (); // in scope 4 at $DIR/cycle.rs:6:5: 6:8
+ scope 5 (inlined <fn() {main} as Fn<()>>::call - shim(fn() {main})) { // at $DIR/cycle.rs:6:5: 6:8
+ }
+ }
+ }
+ }
+ }

Expand All @@ -30,7 +38,11 @@
+ _3 = &_2; // scope 1 at $DIR/cycle.rs:6:5: 6:6
+ StorageLive(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ _5 = const (); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ _4 = move (*_3)() -> [return: bb4, unwind: bb2]; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ StorageLive(_6); // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ _6 = main() -> [return: bb4, unwind: bb2]; // scope 5 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ // mir::Constant
+ // + span: no-location
+ // + literal: Const { ty: fn() {main}, val: Value(<ZST>) }
}

bb1: {
Expand All @@ -50,6 +62,7 @@
+ }
+
+ bb4: {
+ StorageDead(_6); // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ StorageDead(_5); // scope 1 at $DIR/cycle.rs:6:5: 6:8
+ StorageDead(_3); // scope 1 at $DIR/cycle.rs:6:7: 6:8
+ drop(_2) -> bb1; // scope 1 at $DIR/cycle.rs:7:1: 7:2
Expand Down
106 changes: 103 additions & 3 deletions tests/mir-opt/inline/exponential_runtime.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,26 @@
+ let _5: (); // in scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ let _6: (); // in scope 2 at $DIR/exponential_runtime.rs:63:9: 63:25
+ let _7: (); // in scope 2 at $DIR/exponential_runtime.rs:64:9: 64:25
+ scope 3 (inlined <() as E>::call) { // at $DIR/exponential_runtime.rs:62:9: 62:25
+ let _8: (); // in scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ let _9: (); // in scope 3 at $DIR/exponential_runtime.rs:51:9: 51:25
+ let _10: (); // in scope 3 at $DIR/exponential_runtime.rs:52:9: 52:25
+ scope 4 (inlined <() as D>::call) { // at $DIR/exponential_runtime.rs:50:9: 50:25
+ let _11: (); // in scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ let _12: (); // in scope 4 at $DIR/exponential_runtime.rs:39:9: 39:25
+ let _13: (); // in scope 4 at $DIR/exponential_runtime.rs:40:9: 40:25
+ scope 5 (inlined <() as C>::call) { // at $DIR/exponential_runtime.rs:38:9: 38:25
+ let _14: (); // in scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ let _15: (); // in scope 5 at $DIR/exponential_runtime.rs:27:9: 27:25
+ let _16: (); // in scope 5 at $DIR/exponential_runtime.rs:28:9: 28:25
+ scope 6 (inlined <() as B>::call) { // at $DIR/exponential_runtime.rs:26:9: 26:25
+ let _17: (); // in scope 6 at $DIR/exponential_runtime.rs:14:9: 14:25
+ let _18: (); // in scope 6 at $DIR/exponential_runtime.rs:15:9: 15:25
+ let _19: (); // in scope 6 at $DIR/exponential_runtime.rs:16:9: 16:25
+ }
+ }
+ }
+ }
+ }
+ }

Expand All @@ -24,12 +44,24 @@
+ StorageLive(_5); // scope 1 at $DIR/exponential_runtime.rs:74:9: 74:25
+ StorageLive(_6); // scope 1 at $DIR/exponential_runtime.rs:74:9: 74:25
+ StorageLive(_7); // scope 1 at $DIR/exponential_runtime.rs:74:9: 74:25
+ _5 = <() as E>::call() -> bb4; // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageLive(_8); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageLive(_9); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageLive(_10); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageLive(_11); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ StorageLive(_12); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ StorageLive(_13); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ StorageLive(_14); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ StorageLive(_15); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ StorageLive(_16); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ StorageLive(_17); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ StorageLive(_18); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ StorageLive(_19); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ _17 = <() as A>::call() -> bb12; // scope 6 at $DIR/exponential_runtime.rs:14:9: 14:25
// mir::Constant
- // + span: $DIR/exponential_runtime.rs:87:5: 87:20
- // + literal: Const { ty: fn() {<() as G>::call}, val: Value(<ZST>) }
+ // + span: $DIR/exponential_runtime.rs:62:9: 62:23
+ // + literal: Const { ty: fn() {<() as E>::call}, val: Value(<ZST>) }
+ // + span: $DIR/exponential_runtime.rs:14:9: 14:23
+ // + literal: Const { ty: fn() {<() as A>::call}, val: Value(<ZST>) }
}

bb1: {
Expand Down Expand Up @@ -59,6 +91,9 @@
+ }
+
+ bb4: {
+ StorageDead(_10); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageDead(_9); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ StorageDead(_8); // scope 2 at $DIR/exponential_runtime.rs:62:9: 62:25
+ _6 = <() as E>::call() -> bb5; // scope 2 at $DIR/exponential_runtime.rs:63:9: 63:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:63:9: 63:23
Expand All @@ -70,6 +105,71 @@
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:64:9: 64:23
+ // + literal: Const { ty: fn() {<() as E>::call}, val: Value(<ZST>) }
+ }
+
+ bb6: {
+ StorageDead(_13); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ StorageDead(_12); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ StorageDead(_11); // scope 3 at $DIR/exponential_runtime.rs:50:9: 50:25
+ _9 = <() as D>::call() -> bb7; // scope 3 at $DIR/exponential_runtime.rs:51:9: 51:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:51:9: 51:23
+ // + literal: Const { ty: fn() {<() as D>::call}, val: Value(<ZST>) }
+ }
+
+ bb7: {
+ _10 = <() as D>::call() -> bb4; // scope 3 at $DIR/exponential_runtime.rs:52:9: 52:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:52:9: 52:23
+ // + literal: Const { ty: fn() {<() as D>::call}, val: Value(<ZST>) }
+ }
+
+ bb8: {
+ StorageDead(_16); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ StorageDead(_15); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ StorageDead(_14); // scope 4 at $DIR/exponential_runtime.rs:38:9: 38:25
+ _12 = <() as C>::call() -> bb9; // scope 4 at $DIR/exponential_runtime.rs:39:9: 39:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:39:9: 39:23
+ // + literal: Const { ty: fn() {<() as C>::call}, val: Value(<ZST>) }
+ }
+
+ bb9: {
+ _13 = <() as C>::call() -> bb6; // scope 4 at $DIR/exponential_runtime.rs:40:9: 40:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:40:9: 40:23
+ // + literal: Const { ty: fn() {<() as C>::call}, val: Value(<ZST>) }
+ }
+
+ bb10: {
+ StorageDead(_19); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ StorageDead(_18); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ StorageDead(_17); // scope 5 at $DIR/exponential_runtime.rs:26:9: 26:25
+ _15 = <() as B>::call() -> bb11; // scope 5 at $DIR/exponential_runtime.rs:27:9: 27:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:27:9: 27:23
+ // + literal: Const { ty: fn() {<() as B>::call}, val: Value(<ZST>) }
+ }
+
+ bb11: {
+ _16 = <() as B>::call() -> bb8; // scope 5 at $DIR/exponential_runtime.rs:28:9: 28:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:28:9: 28:23
+ // + literal: Const { ty: fn() {<() as B>::call}, val: Value(<ZST>) }
+ }
+
+ bb12: {
+ _18 = <() as A>::call() -> bb13; // scope 6 at $DIR/exponential_runtime.rs:15:9: 15:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:15:9: 15:23
+ // + literal: Const { ty: fn() {<() as A>::call}, val: Value(<ZST>) }
+ }
+
+ bb13: {
+ _19 = <() as A>::call() -> bb10; // scope 6 at $DIR/exponential_runtime.rs:16:9: 16:25
+ // mir::Constant
+ // + span: $DIR/exponential_runtime.rs:16:9: 16:23
+ // + literal: Const { ty: fn() {<() as A>::call}, val: Value(<ZST>) }
}
}

15 changes: 14 additions & 1 deletion tests/mir-opt/inline/inline_cycle.two.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
+ debug f => _2; // in scope 1 at $DIR/inline_cycle.rs:54:22: 54:23
+ let _3: (); // in scope 1 at $DIR/inline_cycle.rs:55:5: 55:8
+ scope 2 (inlined <fn() {f} as FnOnce<()>>::call_once - shim(fn() {f})) { // at $DIR/inline_cycle.rs:55:5: 55:8
+ scope 3 (inlined f) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ scope 4 (inlined call::<fn() {f}>) { // at $DIR/inline_cycle.rs:60:5: 60:12
+ debug f => f; // in scope 4 at $DIR/inline_cycle.rs:54:22: 54:23
+ let _5: (); // in scope 4 at $DIR/inline_cycle.rs:55:5: 55:8
+ scope 5 (inlined <fn() {f} as FnOnce<()>>::call_once - shim(fn() {f})) { // at $DIR/inline_cycle.rs:55:5: 55:8
+ }
+ }
+ }
+ }
+ }

Expand All @@ -27,10 +35,15 @@
+ StorageLive(_3); // scope 0 at $DIR/inline_cycle.rs:+1:5: +1:12
+ StorageLive(_4); // scope 1 at $DIR/inline_cycle.rs:55:5: 55:8
+ _4 = const (); // scope 1 at $DIR/inline_cycle.rs:55:5: 55:8
+ _3 = move _2() -> bb1; // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ StorageLive(_5); // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ _5 = f() -> bb1; // scope 5 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ // mir::Constant
+ // + span: no-location
+ // + literal: Const { ty: fn() {f}, val: Value(<ZST>) }
}

bb1: {
+ StorageDead(_5); // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ StorageDead(_4); // scope 1 at $DIR/inline_cycle.rs:55:5: 55:8
+ StorageDead(_3); // scope 0 at $DIR/inline_cycle.rs:+1:5: +1:12
+ StorageDead(_2); // scope 0 at $DIR/inline_cycle.rs:+1:5: +1:12
Expand Down
8 changes: 5 additions & 3 deletions tests/mir-opt/inline/inline_cycle_generic.main.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
let _1: (); // in scope 0 at $DIR/inline_cycle_generic.rs:+1:5: +1:24
+ scope 1 (inlined <C as Call>::call) { // at $DIR/inline_cycle_generic.rs:10:5: 10:24
+ scope 2 (inlined <B<A> as Call>::call) { // at $DIR/inline_cycle_generic.rs:39:9: 39:31
+ scope 3 (inlined <A as Call>::call) { // at $DIR/inline_cycle_generic.rs:32:9: 32:28
+ }
+ }
+ }

bb0: {
StorageLive(_1); // scope 0 at $DIR/inline_cycle_generic.rs:+1:5: +1:24
- _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline_cycle_generic.rs:+1:5: +1:24
+ _1 = <A as Call>::call() -> bb1; // scope 2 at $DIR/inline_cycle_generic.rs:32:9: 32:28
+ _1 = <B<C> as Call>::call() -> bb1; // scope 3 at $DIR/inline_cycle_generic.rs:24:9: 24:31
// mir::Constant
- // + span: $DIR/inline_cycle_generic.rs:10:5: 10:22
- // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(<ZST>) }
+ // + span: $DIR/inline_cycle_generic.rs:32:9: 32:26
+ // + literal: Const { ty: fn() {<A as Call>::call}, val: Value(<ZST>) }
+ // + span: $DIR/inline_cycle_generic.rs:24:9: 24:29
+ // + literal: Const { ty: fn() {<B<C> as Call>::call}, val: Value(<ZST>) }
}

bb1: {
Expand Down
39 changes: 4 additions & 35 deletions tests/mir-opt/inline/inline_diverging.h.Inline.diff
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
+ }
+ }
+ scope 4 (inlined <fn() -> ! {sleep} as Fn<()>>::call - shim(fn() -> ! {sleep})) { // at $DIR/inline_diverging.rs:27:13: 27:16
+ scope 5 (inlined sleep) { // at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ }
+ }
+ }

Expand All @@ -40,44 +42,11 @@
+ _3 = &_2; // scope 1 at $DIR/inline_diverging.rs:27:13: 27:14
+ StorageLive(_8); // scope 1 at $DIR/inline_diverging.rs:27:13: 27:16
+ _8 = const (); // scope 1 at $DIR/inline_diverging.rs:27:13: 27:16
+ _4 = move (*_3)() -> [return: bb6, unwind: bb4]; // scope 4 at $SRC_DIR/core/src/ops/function.rs:LL:COL
+ goto -> bb1; // scope 5 at $DIR/inline_diverging.rs:39:5: 39:12
+ }
+
+ bb1: {
+ StorageDead(_5); // scope 2 at $DIR/inline_diverging.rs:28:15: 28:16
+ StorageLive(_7); // scope 3 at $DIR/inline_diverging.rs:29:6: 29:7
+ _7 = move _4; // scope 3 at $DIR/inline_diverging.rs:29:6: 29:7
+ _1 = (move _7, move _6); // scope 3 at $DIR/inline_diverging.rs:29:5: 29:11
+ StorageDead(_7); // scope 3 at $DIR/inline_diverging.rs:29:10: 29:11
+ StorageDead(_4); // scope 1 at $DIR/inline_diverging.rs:30:1: 30:2
+ drop(_2) -> bb2; // scope 1 at $DIR/inline_diverging.rs:30:1: 30:2
+ }
+
+ bb2: {
+ unreachable; // scope 0 at $DIR/inline_diverging.rs:30:2: 30:2
+ }
+
+ bb3 (cleanup): {
+ drop(_4) -> [return: bb4, unwind terminate]; // scope 1 at $DIR/inline_diverging.rs:30:1: 30:2
+ }
+
+ bb4 (cleanup): {
+ drop(_2) -> [return: bb5, unwind terminate]; // scope 1 at $DIR/inline_diverging.rs:30:1: 30:2
+ }
+
+ bb5 (cleanup): {
+ resume; // scope 1 at $DIR/inline_diverging.rs:26:1: 30:2
+ }
+
+ bb6: {
+ StorageDead(_8); // scope 1 at $DIR/inline_diverging.rs:27:13: 27:16
+ StorageDead(_3); // scope 1 at $DIR/inline_diverging.rs:27:15: 27:16
+ StorageLive(_5); // scope 2 at $DIR/inline_diverging.rs:28:13: 28:14
+ _5 = &_2; // scope 2 at $DIR/inline_diverging.rs:28:13: 28:14
+ _6 = <fn() -> ! {sleep} as Fn<()>>::call(move _5, const ()) -> [return: bb1, unwind: bb3]; // scope 2 at $DIR/inline_diverging.rs:28:13: 28:16
+ // mir::Constant
+ // + span: $DIR/inline_diverging.rs:28:13: 28:14
+ // + literal: Const { ty: for<'a> extern "rust-call" fn(&'a fn() -> ! {sleep}, ()) -> <fn() -> ! {sleep} as FnOnce<()>>::Output {<fn() -> ! {sleep} as Fn<()>>::call}, val: Value(<ZST>) }
+ goto -> bb1; // scope 5 at $DIR/inline_diverging.rs:39:5: 39:12
}
}

Loading