about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-11-06 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-11-09 11:41:10 +0100
commitb7f16c56d10abbd664407b4eef41b5e69d18666d (patch)
tree914056cb45f848982f491e78a3918558b91e3525
parentfe8f02690804d5ee696bd3bca9515f5f71857e3b (diff)
downloadrust-b7f16c56d10abbd664407b4eef41b5e69d18666d.tar.gz
rust-b7f16c56d10abbd664407b4eef41b5e69d18666d.zip
inliner: Make `inline_call` infallible
The inliner does not support inlining of divering calls. Reject them
early on and turn `inline_call` into an infallible operation.
-rw-r--r--compiler/rustc_mir/src/transform/inline.rs23
1 files changed, 6 insertions, 17 deletions
diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs
index a41304236b2..503b40b506a 100644
--- a/compiler/rustc_mir/src/transform/inline.rs
+++ b/compiler/rustc_mir/src/transform/inline.rs
@@ -138,12 +138,7 @@ impl Inliner<'tcx> {
             );
 
             let start = caller_body.basic_blocks().len();
-            debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
-            if !self.inline_call(callsite, caller_body, callee_body) {
-                debug!("attempting to inline callsite {:?} - failure", callsite);
-                continue;
-            }
-            debug!("attempting to inline callsite {:?} - success", callsite);
+            self.inline_call(callsite, caller_body, callee_body);
 
             // Add callsites from inlined function
             for (bb, bb_data) in caller_body.basic_blocks().iter_enumerated().skip(start) {
@@ -179,7 +174,8 @@ impl Inliner<'tcx> {
 
         // Only consider direct calls to functions
         let terminator = bb_data.terminator();
-        if let TerminatorKind::Call { func: ref op, .. } = terminator.kind {
+        // FIXME: Handle inlining of diverging calls
+        if let TerminatorKind::Call { func: ref op, destination: Some(_), .. } = terminator.kind {
             if let ty::FnDef(callee_def_id, substs) = *op.ty(caller_body, self.tcx).kind() {
                 // To resolve an instance its substs have to be fully normalized, so
                 // we do this here.
@@ -397,12 +393,11 @@ impl Inliner<'tcx> {
         callsite: CallSite<'tcx>,
         caller_body: &mut Body<'tcx>,
         mut callee_body: Body<'tcx>,
-    ) -> bool {
+    ) {
         let terminator = caller_body[callsite.bb].terminator.take().unwrap();
         match terminator.kind {
-            // FIXME: Handle inlining of diverging calls
             TerminatorKind::Call { args, destination: Some(destination), cleanup, .. } => {
-                debug!("inlined {:?} into {:?}", callsite.callee, caller_body.source);
+                debug!("inlined {} into {:?}", callsite.callee, caller_body.source.instance);
 
                 // If the call is something like `a[*i] = f(i)`, where
                 // `i : &mut usize`, then just duplicating the `a[*i]`
@@ -519,14 +514,8 @@ impl Inliner<'tcx> {
                         matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
                     }),
                 );
-
-                true
-            }
-            kind => {
-                caller_body[callsite.bb].terminator =
-                    Some(Terminator { source_info: terminator.source_info, kind });
-                false
             }
+            kind => bug!("unexpected terminator kind {:?}", kind),
         }
     }