Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3dd0a7d
Do not call `unwrap` with `signatures` option enabled
JohnTitor Oct 25, 2020
443b45f
rustc_target: Change os from "unknown" to "none" for bare metal targets
petrochenkov Nov 11, 2020
1def24c
rustc_target: Normalize vendor from "" to "unknown" for all targets
petrochenkov Nov 11, 2020
e0a8f22
rustc_target: Make sure that in-tree targets follow conventions for o…
petrochenkov Nov 11, 2020
f5e67b5
Add a test for r# identifiers
poliorcetics Nov 12, 2020
9c70696
Ignore tidy linelength
poliorcetics Nov 12, 2020
bd0eb07
Added some unit tests as requested
richkadel Nov 3, 2020
ecfeac5
Use intradoc-links for the whole test, add a @has check
poliorcetics Nov 12, 2020
562d50e
Include llvm-as in llvm-tools-preview component
zec Nov 12, 2020
e4a43fc
Merge changes from rust-lang/rust
zec Nov 12, 2020
eb9f2bb
Overcome Sync issues with non-parallel compiler
richkadel Nov 12, 2020
fe56d26
Fix and re-enable two coverage tests on MacOS
richkadel Nov 8, 2020
775f1e5
fix pretty print for qpath
gui1117 Nov 12, 2020
04d41e1
rustc_target: Mark UEFI targets as `is_like_windows`/`is_like_msvc`
petrochenkov Nov 11, 2020
0b4af16
Never inline when `no_sanitize` attributes differ
tmiasko Nov 11, 2020
ae43326
Never inline cold functions
tmiasko Nov 11, 2020
9bb3d6b
Remove check for impossible condition
tmiasko Nov 11, 2020
2879ab7
rustc_parse: Remove optimization for 0-length streams in `collect_tok…
petrochenkov Nov 4, 2020
66cadec
Fix generator inlining by checking for rust-call abi and spread arg
tmiasko Nov 11, 2020
79d853e
Never inline C variadic functions
tmiasko Nov 11, 2020
2a010dd
./x.py test --bless
tmiasko Nov 11, 2020
d486bfc
Normalize function type during validation
tmiasko Nov 12, 2020
99be78d
Always use param_env_reveal_all_normalized in validator
tmiasko Nov 12, 2020
c131063
Added a unit test for BcbCounters
richkadel Nov 13, 2020
309d863
Fix wrong XPath
poliorcetics Nov 13, 2020
b4b0ef3
Addressed feedback
richkadel Nov 13, 2020
bf6902c
Add BTreeMap::retain and BTreeSet::retain
mbrubeck Nov 13, 2020
6667bba
Rollup merge of #78352 - JohnTitor:issue-75229, r=Dylan-DPC
Dylan-DPC Nov 13, 2020
4e93b53
Rollup merge of #78736 - petrochenkov:lazyenum, r=Aaron1011
Dylan-DPC Nov 13, 2020
19dcd35
Rollup merge of #78888 - richkadel:llvm-coverage-tests, r=tmandry
Dylan-DPC Nov 13, 2020
0728b86
Rollup merge of #78951 - petrochenkov:unknown, r=ehuss
Dylan-DPC Nov 13, 2020
13de6cf
Rollup merge of #78959 - petrochenkov:likeuefi, r=nagisa
Dylan-DPC Nov 13, 2020
578cc17
Rollup merge of #78962 - poliorcetics:rustdoc-raw-ident-test, r=jyn514
Dylan-DPC Nov 13, 2020
8734357
Rollup merge of #78963 - richkadel:llvm-coverage-counters-2.0.4, r=tm…
Dylan-DPC Nov 13, 2020
2362b5a
Rollup merge of #78966 - tmiasko:inline-never, r=oli-obk
Dylan-DPC Nov 13, 2020
ba71160
Rollup merge of #78968 - zec:add-llvm-as, r=Mark-Simulacrum
Dylan-DPC Nov 13, 2020
7ae8480
Rollup merge of #78969 - tmiasko:normalize, r=davidtwco
Dylan-DPC Nov 13, 2020
0180045
Rollup merge of #78980 - thiolliere:gui-fix-qpath, r=estebank
Dylan-DPC Nov 13, 2020
bb160af
Rollup merge of #79026 - mbrubeck:btree_retain, r=m-ou-se
Dylan-DPC Nov 13, 2020
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
Prev Previous commit
Next Next commit
Fix generator inlining by checking for rust-call abi and spread arg
  • Loading branch information
tmiasko committed Nov 12, 2020
commit 66cadec1763ac645337c1ac58f06ea48b9b72a26
26 changes: 14 additions & 12 deletions compiler/rustc_mir/src/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use rustc_index::vec::Idx;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::mir::visit::*;
use rustc_middle::mir::*;
use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
use rustc_span::{hygiene::ExpnKind, ExpnData, Span};
use rustc_target::spec::abi::Abi;
Expand All @@ -28,6 +29,7 @@ pub struct Inline;
#[derive(Copy, Clone, Debug)]
struct CallSite<'tcx> {
callee: Instance<'tcx>,
fn_sig: ty::PolyFnSig<'tcx>,
block: BasicBlock,
target: Option<BasicBlock>,
source_info: SourceInfo,
Expand Down Expand Up @@ -173,22 +175,23 @@ impl Inliner<'tcx> {

// Only consider direct calls to functions
let terminator = bb_data.terminator();
if let TerminatorKind::Call { func: ref op, ref destination, .. } = 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.
let normalized_substs = self.tcx.normalize_erasing_regions(self.param_env, substs);
if let TerminatorKind::Call { ref func, ref destination, .. } = terminator.kind {
let func_ty = func.ty(caller_body, self.tcx);
if let ty::FnDef(def_id, substs) = *func_ty.kind() {
// To resolve an instance its substs have to be fully normalized.
let substs = self.tcx.normalize_erasing_regions(self.param_env, substs);
let callee =
Instance::resolve(self.tcx, self.param_env, callee_def_id, normalized_substs)
.ok()
.flatten()?;
Instance::resolve(self.tcx, self.param_env, def_id, substs).ok().flatten()?;

if let InstanceDef::Virtual(..) | InstanceDef::Intrinsic(_) = callee.def {
return None;
}

let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, substs);

return Some(CallSite {
callee,
fn_sig,
block: bb,
target: destination.map(|(_, target)| target),
source_info: terminator.source_info,
Expand Down Expand Up @@ -437,7 +440,7 @@ impl Inliner<'tcx> {
};

// Copy the arguments if needed.
let args: Vec<_> = self.make_call_args(args, &callsite, caller_body);
let args: Vec<_> = self.make_call_args(args, &callsite, caller_body, &callee_body);

let mut integrator = Integrator {
args: &args,
Expand Down Expand Up @@ -518,6 +521,7 @@ impl Inliner<'tcx> {
args: Vec<Operand<'tcx>>,
callsite: &CallSite<'tcx>,
caller_body: &mut Body<'tcx>,
callee_body: &Body<'tcx>,
) -> Vec<Local> {
let tcx = self.tcx;

Expand All @@ -544,9 +548,7 @@ impl Inliner<'tcx> {
// tmp2 = tuple_tmp.2
//
// and the vector is `[closure_ref, tmp0, tmp1, tmp2]`.
// FIXME(eddyb) make this check for `"rust-call"` ABI combined with
// `callee_body.spread_arg == None`, instead of special-casing closures.
if tcx.is_closure(callsite.callee.def_id()) {
if callsite.fn_sig.abi() == Abi::RustCall && callee_body.spread_arg.is_none() {
let mut args = args.into_iter();
let self_ = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_body);
let tuple = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_body);
Expand Down
16 changes: 16 additions & 0 deletions src/test/mir-opt/inline/inline-generator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(generators, generator_trait)]

use std::ops::Generator;
use std::pin::Pin;

// EMIT_MIR inline_generator.main.Inline.diff
fn main() {
let _r = Pin::new(&mut g()).resume(false);
}

#[inline(always)]
pub fn g() -> impl Generator<bool> {
#[inline(always)]
|a| { yield if a { 7 } else { 13 } }
}