From 8efafa18e5ebc70d5219f8d9d016f2694dcb2196 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 20 Sep 2018 20:44:07 -0500 Subject: [PATCH 1/2] Extend MIR inlining to all operand variants --- src/librustc_mir/transform/inline.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 8689fde3ee640..04f61235ca195 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -94,8 +94,8 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> { // Only consider direct calls to functions let terminator = bb_data.terminator(); if let TerminatorKind::Call { - func: Operand::Constant(ref f), .. } = terminator.kind { - if let ty::FnDef(callee_def_id, substs) = f.ty.sty { + func: ref op, .. } = terminator.kind { + if let ty::FnDef(callee_def_id, substs) = op.ty(caller_mir, self.tcx).sty { if let Some(instance) = Instance::resolve(self.tcx, param_env, callee_def_id, From 1e3c86e1c40e703f632087751d073b58bd96a6df Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Sat, 22 Sep 2018 16:48:33 -0500 Subject: [PATCH 2/2] Add test to check if inlining works for any operand --- src/test/mir-opt/inline-any-operand.rs | 39 ++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/mir-opt/inline-any-operand.rs diff --git a/src/test/mir-opt/inline-any-operand.rs b/src/test/mir-opt/inline-any-operand.rs new file mode 100644 index 0000000000000..da95842ea4dee --- /dev/null +++ b/src/test/mir-opt/inline-any-operand.rs @@ -0,0 +1,39 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-flags: -Z span_free_formats + +// Tests that MIR inliner works for any operand + +fn main() { + println!("{}", bar()); +} + +#[inline(always)] +fn foo(x: i32, y: i32) -> bool { + x == y +} + +fn bar() -> bool { + let f = foo; + f(1, -1) +} + +// END RUST SOURCE +// START rustc.bar.Inline.after.mir +// ... +// bb0: { +// ... +// _0 = Eq(move _3, move _4); +// ... +// return; +// } +// ... +// END rustc.bar.Inline.after.mir