inliner: Use substs_for_mir_body
Changes from 68965 extended the kind of instances that are being inlined. For some of those, the `instance_mir` returns a MIR body that is already expressed in terms of the types found in substitution array, and doesn't need further substitution. Use `substs_for_mir_body` to take that into account.
This commit is contained in:
parent
9d78d1d027
commit
8a8ee1a3ed
9 changed files with 142 additions and 42 deletions
|
@ -6,7 +6,6 @@ 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;
|
||||
|
@ -128,17 +127,15 @@ impl Inliner<'tcx> {
|
|||
self.tcx.instance_mir(callsite.callee.def)
|
||||
};
|
||||
|
||||
let callee_body: &Body<'tcx> = &*callee_body;
|
||||
|
||||
let callee_body = if self.consider_optimizing(callsite, callee_body) {
|
||||
self.tcx.subst_and_normalize_erasing_regions(
|
||||
&callsite.callee.substs,
|
||||
self.param_env,
|
||||
callee_body,
|
||||
)
|
||||
} else {
|
||||
if !self.consider_optimizing(callsite, &callee_body) {
|
||||
continue;
|
||||
};
|
||||
}
|
||||
|
||||
let callee_body = callsite.callee.subst_mir_and_normalize_erasing_regions(
|
||||
self.tcx,
|
||||
self.param_env,
|
||||
callee_body,
|
||||
);
|
||||
|
||||
// Copy only unevaluated constants from the callee_body into the caller_body.
|
||||
// Although we are only pushing `ConstKind::Unevaluated` consts to
|
||||
|
@ -317,7 +314,7 @@ impl Inliner<'tcx> {
|
|||
work_list.push(target);
|
||||
// If the place doesn't actually need dropping, treat it like
|
||||
// a regular goto.
|
||||
let ty = place.ty(callee_body, tcx).subst(tcx, callsite.callee.substs).ty;
|
||||
let ty = callsite.callee.subst_mir(self.tcx, &place.ty(callee_body, tcx).ty);
|
||||
if ty.needs_drop(tcx, self.param_env) {
|
||||
cost += CALL_PENALTY;
|
||||
if let Some(unwind) = unwind {
|
||||
|
@ -379,8 +376,7 @@ impl Inliner<'tcx> {
|
|||
let ptr_size = tcx.data_layout.pointer_size.bytes();
|
||||
|
||||
for v in callee_body.vars_and_temps_iter() {
|
||||
let v = &callee_body.local_decls[v];
|
||||
let ty = v.ty.subst(tcx, callsite.callee.substs);
|
||||
let ty = callsite.callee.subst_mir(self.tcx, &callee_body.local_decls[v].ty);
|
||||
// Cost of the var is the size in machine-words, if we know
|
||||
// it.
|
||||
if let Some(size) = type_size_of(tcx, self.param_env, ty) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue