]> git.lizzy.rs Git - rust.git/commitdiff
Check history earlier.
authorCamille GILLOT <gillot.camille@gmail.com>
Mon, 13 Dec 2021 12:46:30 +0000 (13:46 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Thu, 30 Jun 2022 19:45:29 +0000 (21:45 +0200)
compiler/rustc_mir_transform/src/inline.rs
src/test/mir-opt/inline/inline_cycle.one.Inline.diff
src/test/mir-opt/inline/inline_cycle.two.Inline.diff
src/test/mir-opt/inline/inline_cycle_generic.main.Inline.diff

index 49403ba03a45ddfd8a2e57779b3751112d9784d8..15a0e0a41ea79a9d01323d5efdbf3f88fe49e7ea 100644 (file)
@@ -263,6 +263,10 @@ fn resolve_callsite(
                     return None;
                 }
 
+                if self.history.contains(&callee) {
+                    return None;
+                }
+
                 let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, substs);
 
                 return Some(CallSite {
@@ -407,22 +411,9 @@ fn check_mir_body(
                 }
 
                 TerminatorKind::Call { func: Operand::Constant(ref f), cleanup, .. } => {
-                    if let ty::FnDef(def_id, substs) =
+                    if let ty::FnDef(def_id, _) =
                         *callsite.callee.subst_mir(self.tcx, &f.literal.ty()).kind()
                     {
-                        if let Ok(substs) =
-                            self.tcx.try_normalize_erasing_regions(self.param_env, substs)
-                        {
-                            if let Ok(Some(instance)) =
-                                Instance::resolve(self.tcx, self.param_env, def_id, substs)
-                            {
-                                if callsite.callee.def_id() == instance.def_id() {
-                                    return Err("self-recursion");
-                                } else if self.history.contains(&instance) {
-                                    return Err("already inlined");
-                                }
-                            }
-                        }
                         // Don't give intrinsics the extra penalty for calls
                         if tcx.is_intrinsic(def_id) {
                             cost += INSTR_COST;
index b732e7cdb9bf8f05cf26755873a3df7cf724aa3f..3b32cb809113e70a5a0f52ba447c7e61452aa7ae 100644 (file)
@@ -5,17 +5,20 @@
       let mut _0: ();                      // return place in scope 0 at $DIR/inline-cycle.rs:13:10: 13:10
       let _1: ();                          // in scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
 +     scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle.rs:14:5: 14:24
++         scope 2 (inlined <A<C> as Call>::call) { // at $DIR/inline-cycle.rs:43:9: 43:23
++             scope 3 (inlined <B<C> as Call>::call) { // at $DIR/inline-cycle.rs:28:9: 28:31
++             }
++         }
 +     }
   
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
 -         _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle.rs:14:5: 14:24
-+         _1 = <A<C> as Call>::call() -> bb1; // scope 1 at $DIR/inline-cycle.rs:43:9: 43:23
++         _1 = <C as Call>::call() -> bb1; // scope 3 at $DIR/inline-cycle.rs:36:9: 36:28
                                            // mir::Constant
 -                                          // + span: $DIR/inline-cycle.rs:14:5: 14:22
--                                          // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
-+                                          // + span: $DIR/inline-cycle.rs:43:9: 43:21
-+                                          // + literal: Const { ty: fn() {<A<C> as Call>::call}, val: Value(Scalar(<ZST>)) }
++                                          // + span: $DIR/inline-cycle.rs:36:9: 36:26
+                                           // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
       }
   
       bb1: {
index eac5bf8edec4bb0c9471bf9f1d9e78fbf15ed452..c7f8a64afcd8d93c76429659651a94e67976e119 100644 (file)
@@ -11,6 +11,9 @@
 +         let _3: ();                      // in scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
 +         let mut _4: fn() {f};            // in scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
 +         scope 2 (inlined <fn() {f} as FnOnce<()>>::call_once - shim(fn() {f})) { // at $DIR/inline-cycle.rs:54:5: 54:8
++             scope 3 (inlined f) {        // at $SRC_DIR/core/src/ops/function.rs:LL:COL
++                 let _6: ();              // in scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
++             }
 +         }
 +     }
   
 +         _2 = f;                          // scope 0 at $DIR/inline-cycle.rs:49:5: 49:12
                                            // mir::Constant
 -                                          // + span: $DIR/inline-cycle.rs:49:5: 49:9
--                                          // + literal: Const { ty: fn(fn() {f}) {call::<fn() {f}>}, val: Value(Scalar(<ZST>)) }
--                                          // mir::Constant
-                                           // + span: $DIR/inline-cycle.rs:49:10: 49:11
-                                           // + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
++                                          // + span: $DIR/inline-cycle.rs:49:10: 49:11
++                                          // + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
 +         StorageLive(_3);                 // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
 +         StorageLive(_4);                 // scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
 +         _4 = move _2;                    // scope 1 at $DIR/inline-cycle.rs:54:5: 54:6
 +         StorageLive(_5);                 // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
 +         _5 = const ();                   // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
-+         _3 = move _4() -> bb1;           // scope 2 at $SRC_DIR/core/src/ops/function.rs:LL:COL
++         StorageLive(_6);                 // scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
++         _6 = call::<fn() {f}>(f) -> bb1; // scope 3 at $DIR/inline-cycle.rs:59:5: 59:12
++                                          // mir::Constant
++                                          // + span: $DIR/inline-cycle.rs:59:5: 59:9
+                                           // + literal: Const { ty: fn(fn() {f}) {call::<fn() {f}>}, val: Value(Scalar(<ZST>)) }
+                                           // mir::Constant
+-                                          // + span: $DIR/inline-cycle.rs:49:10: 49:11
++                                          // + span: $DIR/inline-cycle.rs:59:10: 59:11
+                                           // + literal: Const { ty: fn() {f}, val: Value(Scalar(<ZST>)) }
       }
   
       bb1: {
++         StorageDead(_6);                 // scope 3 at $DIR/inline-cycle.rs:59:12: 59:13
 +         StorageDead(_5);                 // scope 1 at $DIR/inline-cycle.rs:54:5: 54:8
 +         StorageDead(_4);                 // scope 1 at $DIR/inline-cycle.rs:54:7: 54:8
 +         StorageDead(_3);                 // scope 1 at $DIR/inline-cycle.rs:54:8: 54:9
index 267f53a8dfe7b4f7b57b6fb1ff6872595b20303a..2a19b21510a1023835e8db86de6a62bbbb047993 100644 (file)
@@ -4,12 +4,22 @@
   fn main() -> () {
       let mut _0: ();                      // return place in scope 0 at $DIR/inline-cycle-generic.rs:8:11: 8:11
       let _1: ();                          // in scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
++     scope 1 (inlined <C as Call>::call) { // at $DIR/inline-cycle-generic.rs:9:5: 9:24
++         scope 2 (inlined <B<A> as Call>::call) { // at $DIR/inline-cycle-generic.rs:38:9: 38:31
++             scope 3 (inlined <A as Call>::call) { // at $DIR/inline-cycle-generic.rs:31:9: 31:28
++                 scope 4 (inlined <B<C> as Call>::call) { // at $DIR/inline-cycle-generic.rs:23:9: 23:31
++                 }
++             }
++         }
++     }
   
       bb0: {
           StorageLive(_1);                 // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
-          _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
+-         _1 = <C as Call>::call() -> bb1; // scope 0 at $DIR/inline-cycle-generic.rs:9:5: 9:24
++         _1 = <C as Call>::call() -> bb1; // scope 4 at $DIR/inline-cycle-generic.rs:31:9: 31:28
                                            // mir::Constant
-                                           // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
+-                                          // + span: $DIR/inline-cycle-generic.rs:9:5: 9:22
++                                          // + span: $DIR/inline-cycle-generic.rs:31:9: 31:26
                                            // + literal: Const { ty: fn() {<C as Call>::call}, val: Value(Scalar(<ZST>)) }
       }
   
           StorageDead(_1);                 // scope 0 at $DIR/inline-cycle-generic.rs:9:24: 9:25
           _0 = const ();                   // scope 0 at $DIR/inline-cycle-generic.rs:8:11: 10:2
           return;                          // scope 0 at $DIR/inline-cycle-generic.rs:10:2: 10:2
++     }
++ 
++     bb2 (cleanup): {
++         resume;                          // scope 0 at $DIR/inline-cycle-generic.rs:8:1: 10:2
       }
   }