use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::infer;
-use rustc::middle::region::ROOT_CODE_EXTENT;
use rustc::middle::const_val::ConstVal;
use rustc::mir::*;
use rustc::mir::transform::MirSource;
use rustc::ty::{self, Ty};
-use rustc::ty::subst::{Kind, Subst};
+use rustc::ty::subst::{Kind, Subst, Substs};
use rustc::ty::maps::Providers;
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
use syntax::ast;
use syntax_pos::Span;
-use std::cell::RefCell;
use std::fmt;
use std::iter;
-use std::mem;
use transform::{add_call_guards, no_landing_pads, simplify};
use util::elaborate_drops::{self, DropElaborator, DropStyle, DropFlagMode};
fn make_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
instance: ty::InstanceDef<'tcx>)
- -> &'tcx RefCell<Mir<'tcx>>
+ -> &'tcx Mir<'tcx>
{
debug!("make_shim({:?})", instance);
- let did = instance.def_id();
- let span = tcx.def_span(did);
- let param_env =
- tcx.construct_parameter_environment(span, did, ROOT_CODE_EXTENT);
let mut result = match instance {
ty::InstanceDef::Item(..) =>
build_call_shim(
tcx,
- ¶m_env,
def_id,
adjustment,
CallKind::Indirect,
// trans::mir knows to turn to an actual virtual call.
build_call_shim(
tcx,
- ¶m_env,
def_id,
Adjustment::Identity,
CallKind::Direct(def_id),
build_call_shim(
tcx,
- ¶m_env,
call_once,
Adjustment::RefMut,
CallKind::Direct(call_mut),
)
}
ty::InstanceDef::DropGlue(def_id, ty) => {
- build_drop_shim(tcx, ¶m_env, def_id, ty)
+ build_drop_shim(tcx, def_id, ty)
}
ty::InstanceDef::Intrinsic(_) => {
bug!("creating shims from intrinsics ({:?}) is unsupported", instance)
add_call_guards::add_call_guards(&mut result);
debug!("make_shim({:?}) = {:?}", instance, result);
- let result = tcx.alloc_mir(result);
- // Perma-borrow MIR from shims to prevent mutation.
- mem::forget(result.borrow());
- result
+ tcx.alloc_mir(result)
}
#[derive(Copy, Clone, Debug, PartialEq)]
}
fn build_drop_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
- param_env: &ty::ParameterEnvironment<'tcx>,
def_id: DefId,
ty: Option<Ty<'tcx>>)
-> Mir<'tcx>
let substs = if let Some(ty) = ty {
tcx.mk_substs(iter::once(Kind::from(ty)))
} else {
- param_env.free_substs
+ Substs::identity_for_item(tcx, def_id)
};
- let fn_ty = tcx.item_type(def_id).subst(tcx, substs);
+ let fn_ty = tcx.type_of(def_id).subst(tcx, substs);
let sig = tcx.erase_late_bound_regions(&fn_ty.fn_sig());
let span = tcx.def_span(def_id);
if let Some(..) = ty {
let patch = {
+ let param_env = tcx.param_env(def_id);
let mut elaborator = DropShimElaborator {
mir: &mir,
patch: MirPatch::new(&mir),
- tcx, param_env
+ tcx,
+ param_env
};
let dropee = Lvalue::Local(Local::new(1+0)).deref();
let resume_block = elaborator.patch.resume_block();
elaborate_drops::elaborate_drop(
&mut elaborator,
source_info,
- false,
&dropee,
(),
return_block,
- Some(resume_block),
+ elaborate_drops::Unwind::To(resume_block),
START_BLOCK
);
elaborator.patch
mir: &'a Mir<'tcx>,
patch: MirPatch<'tcx>,
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
- param_env: &'a ty::ParameterEnvironment<'tcx>,
+ param_env: ty::ParamEnv<'tcx>,
}
impl<'a, 'tcx> fmt::Debug for DropShimElaborator<'a, 'tcx> {
fn patch(&mut self) -> &mut MirPatch<'tcx> { &mut self.patch }
fn mir(&self) -> &'a Mir<'tcx> { self.mir }
fn tcx(&self) -> ty::TyCtxt<'a, 'tcx, 'tcx> { self.tcx }
- fn param_env(&self) -> &'a ty::ParameterEnvironment<'tcx> { self.param_env }
+ fn param_env(&self) -> ty::ParamEnv<'tcx> { self.param_env }
fn drop_style(&self, _path: Self::Path, mode: DropFlagMode) -> DropStyle {
if let DropFlagMode::Shallow = mode {
/// If `untuple_args` is a vec of types, the second argument of the
/// function will be untupled as these types.
fn build_call_shim<'a, 'tcx>(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
- param_env: &ty::ParameterEnvironment<'tcx>,
def_id: DefId,
rcvr_adjustment: Adjustment,
call_kind: CallKind,
call_kind={:?}, untuple_args={:?})",
def_id, rcvr_adjustment, call_kind, untuple_args);
- let fn_ty = tcx.item_type(def_id).subst(tcx, param_env.free_substs);
+ let fn_ty = tcx.type_of(def_id);
let sig = tcx.erase_late_bound_regions(&fn_ty.fn_sig());
let span = tcx.def_span(def_id);
CallKind::Direct(def_id) => (
Operand::Constant(box Constant {
span: span,
- ty: tcx.item_type(def_id).subst(tcx, param_env.free_substs),
+ ty: tcx.type_of(def_id),
literal: Literal::Value {
- value: ConstVal::Function(def_id, param_env.free_substs),
+ value: ConstVal::Function(def_id,
+ Substs::identity_for_item(tcx, def_id)),
},
}),
vec![rcvr]
{
let tcx = infcx.tcx;
let def_id = tcx.hir.local_def_id(ctor_id);
- let sig = match tcx.item_type(def_id).sty {
+ let sig = match tcx.type_of(def_id).sty {
ty::TyFnDef(_, _, fty) => tcx.no_late_bound_regions(&fty)
.expect("LBR in ADT constructor signature"),
_ => bug!("unexpected type for ctor {:?}", def_id)