Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir

This commit is contained in:
Ralf Jung 2017-07-11 16:02:06 -07:00
parent 9475ae477a
commit 62b2e5446d
16 changed files with 72 additions and 69 deletions

View File

@ -66,6 +66,9 @@ macro_rules! newtype_index {
)
}
/// Types for locals
type LocalDecls<'tcx> = IndexVec<Local, LocalDecl<'tcx>>;
/// Lowered representation of a single function.
#[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
pub struct Mir<'tcx> {
@ -90,7 +93,7 @@ pub struct Mir<'tcx> {
/// The first local is the return value pointer, followed by `arg_count`
/// locals for the function arguments, followed by any user-declared
/// variables and temporaries.
pub local_decls: IndexVec<Local, LocalDecl<'tcx>>,
pub local_decls: LocalDecls<'tcx>,
/// Number of arguments this function takes.
///

View File

@ -121,31 +121,31 @@ impl<'tcx> TypeFoldable<'tcx> for LvalueTy<'tcx> {
}
impl<'tcx> Lvalue<'tcx> {
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> {
pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> LvalueTy<'tcx> {
match *self {
Lvalue::Local(index) =>
LvalueTy::Ty { ty: mir.local_decls[index].ty },
LvalueTy::Ty { ty: local_decls[index].ty },
Lvalue::Static(ref data) =>
LvalueTy::Ty { ty: data.ty },
Lvalue::Projection(ref proj) =>
proj.base.ty(mir, tcx).projection_ty(tcx, &proj.elem),
proj.base.ty(local_decls, tcx).projection_ty(tcx, &proj.elem),
}
}
}
impl<'tcx> Rvalue<'tcx> {
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>
pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx>
{
match *self {
Rvalue::Use(ref operand) => operand.ty(mir, tcx),
Rvalue::Use(ref operand) => operand.ty(local_decls, tcx),
Rvalue::Repeat(ref operand, ref count) => {
let op_ty = operand.ty(mir, tcx);
let op_ty = operand.ty(local_decls, tcx);
let count = count.as_u64(tcx.sess.target.uint_type);
assert_eq!(count as usize as u64, count);
tcx.mk_array(op_ty, count as usize)
}
Rvalue::Ref(reg, bk, ref lv) => {
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
let lv_ty = lv.ty(local_decls, tcx).to_ty(tcx);
tcx.mk_ref(reg,
ty::TypeAndMut {
ty: lv_ty,
@ -156,22 +156,22 @@ impl<'tcx> Rvalue<'tcx> {
Rvalue::Len(..) => tcx.types.usize,
Rvalue::Cast(.., ty) => ty,
Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(mir, tcx);
let rhs_ty = rhs.ty(mir, tcx);
let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx);
op.ty(tcx, lhs_ty, rhs_ty)
}
Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => {
let lhs_ty = lhs.ty(mir, tcx);
let rhs_ty = rhs.ty(mir, tcx);
let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx);
let ty = op.ty(tcx, lhs_ty, rhs_ty);
tcx.intern_tup(&[ty, tcx.types.bool], false)
}
Rvalue::UnaryOp(UnOp::Not, ref operand) |
Rvalue::UnaryOp(UnOp::Neg, ref operand) => {
operand.ty(mir, tcx)
operand.ty(local_decls, tcx)
}
Rvalue::Discriminant(ref lval) => {
let ty = lval.ty(mir, tcx).to_ty(tcx);
let ty = lval.ty(local_decls, tcx).to_ty(tcx);
if let ty::TyAdt(adt_def, _) = ty.sty {
adt_def.repr.discr_type().to_ty(tcx)
} else {
@ -189,7 +189,7 @@ impl<'tcx> Rvalue<'tcx> {
}
AggregateKind::Tuple => {
tcx.mk_tup(
ops.iter().map(|op| op.ty(mir, tcx)),
ops.iter().map(|op| op.ty(local_decls, tcx)),
false
)
}
@ -206,9 +206,9 @@ impl<'tcx> Rvalue<'tcx> {
}
impl<'tcx> Operand<'tcx> {
pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
pub fn ty<'a, 'gcx>(&self, local_decls: &LocalDecls<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
match self {
&Operand::Consume(ref l) => l.ty(mir, tcx).to_ty(tcx),
&Operand::Consume(ref l) => l.ty(local_decls, tcx).to_ty(tcx),
&Operand::Constant(ref c) => c.ty,
}
}

View File

@ -129,7 +129,7 @@ pub fn move_path_children_matching<'tcx, F>(move_data: &MoveData<'tcx>,
fn lvalue_contents_drop_state_cannot_differ<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
lv: &mir::Lvalue<'tcx>) -> bool {
let ty = lv.ty(mir, tcx).to_ty(tcx);
let ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx);
match ty.sty {
ty::TyArray(..) | ty::TySlice(..) | ty::TyRef(..) | ty::TyRawPtr(..) => {
debug!("lvalue_contents_drop_state_cannot_differ lv: {:?} ty: {:?} refd => true",
@ -216,7 +216,7 @@ pub(crate) fn on_all_drop_children_bits<'a, 'tcx, F>(
{
on_all_children_bits(tcx, mir, &ctxt.move_data, path, |child| {
let lvalue = &ctxt.move_data.move_paths[path].lvalue;
let ty = lvalue.ty(mir, tcx).to_ty(tcx);
let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx);
debug!("on_all_drop_children_bits({:?}, {:?} : {:?})", path, lvalue, ty);
if ty.needs_drop(tcx, ctxt.param_env) {
@ -263,7 +263,7 @@ pub(crate) fn drop_flag_effects_for_location<'a, 'tcx, F>(
// don't move out of non-Copy things
let lvalue = &move_data.move_paths[path].lvalue;
let ty = lvalue.ty(mir, tcx).to_ty(tcx);
let ty = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx);
if !ty.moves_by_default(tcx, param_env, DUMMY_SP) {
continue;
}

View File

@ -286,7 +286,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
-> Result<MovePathIndex, MovePathError>
{
let base = try!(self.move_path_for(&proj.base));
let lv_ty = proj.base.ty(self.mir, self.tcx).to_ty(self.tcx);
let lv_ty = proj.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
match lv_ty.sty {
// error: can't move out of borrowed content
ty::TyRef(..) | ty::TyRawPtr(..) => return Err(MovePathError::IllegalMove),
@ -504,7 +504,7 @@ impl<'a, 'tcx> MoveDataBuilder<'a, 'tcx> {
fn gather_move(&mut self, loc: Location, lval: &Lvalue<'tcx>) {
debug!("gather_move({:?}, {:?})", loc, lval);
let lv_ty = lval.ty(self.mir, self.tcx).to_ty(self.tcx);
let lv_ty = lval.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
if !lv_ty.moves_by_default(self.tcx, self.param_env, DUMMY_SP) {
debug!("gather_move({:?}, {:?}) - {:?} is Copy. skipping", loc, lval, lv_ty);
return

View File

@ -250,7 +250,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
work_list.push(target);
// If the location doesn't actually need dropping, treat it like
// a regular goto.
let ty = location.ty(&callee_mir, tcx).subst(tcx, callsite.substs);
let ty = location.ty(&callee_mir.local_decls, tcx).subst(tcx, callsite.substs);
let ty = ty.to_ty(tcx);
if ty.needs_drop(tcx, param_env) {
cost += CALL_PENALTY;
@ -390,7 +390,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
BorrowKind::Mut,
destination.0);
let ty = dest.ty(caller_mir, self.tcx);
let ty = dest.ty(&caller_mir.local_decls, self.tcx);
let temp = LocalDecl::new_temp(ty, callsite.location.span);
@ -422,7 +422,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
bug!("Constant arg to \"box_free\"");
};
let ptr_ty = args[0].ty(caller_mir, self.tcx);
let ptr_ty = args[0].ty(&caller_mir.local_decls, self.tcx);
vec![self.cast_box_free_arg(arg, ptr_ty, &callsite, caller_mir)]
} else {
// Copy the arguments if needed.
@ -475,7 +475,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
BorrowKind::Mut,
arg.deref());
let ty = arg.ty(caller_mir, self.tcx);
let ty = arg.ty(&caller_mir.local_decls, self.tcx);
let ref_tmp = LocalDecl::new_temp(ty, callsite.location.span);
let ref_tmp = caller_mir.local_decls.push(ref_tmp);
let ref_tmp = Lvalue::Local(ref_tmp);
@ -529,7 +529,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
// Otherwise, create a temporary for the arg
let arg = Rvalue::Use(a);
let ty = arg.ty(caller_mir, tcx);
let ty = arg.ty(&caller_mir.local_decls, tcx);
let arg_tmp = LocalDecl::new_temp(ty, callsite.location.span);
let arg_tmp = caller_mir.local_decls.push(arg_tmp);

View File

@ -87,7 +87,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for OptimizationFinder<'b, 'a, 'tcx> {
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
if let Rvalue::Ref(_, _, Lvalue::Projection(ref projection)) = *rvalue {
if let ProjectionElem::Deref = projection.elem {
if projection.base.ty(self.mir, self.tcx).to_ty(self.tcx).is_region_ptr() {
if projection.base.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx).is_region_ptr() {
self.optimizations.and_stars.insert(location);
}
}

View File

@ -362,13 +362,13 @@ pub fn promote_candidates<'a, 'tcx>(mir: &mut Mir<'tcx>,
continue;
}
}
(statement.source_info.span, dest.ty(mir, tcx).to_ty(tcx))
(statement.source_info.span, dest.ty(&mir.local_decls, tcx).to_ty(tcx))
}
Candidate::ShuffleIndices(bb) => {
let terminator = mir[bb].terminator();
let ty = match terminator.kind {
TerminatorKind::Call { ref args, .. } => {
args[2].ty(mir, tcx)
args[2].ty(&mir.local_decls, tcx)
}
_ => {
span_bug!(terminator.source_info.span,

View File

@ -507,7 +507,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
this.add(Qualif::STATIC);
}
let base_ty = proj.base.ty(this.mir, this.tcx).to_ty(this.tcx);
let base_ty = proj.base.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx);
if let ty::TyRawPtr(_) = base_ty.sty {
this.add(Qualif::NOT_CONST);
if this.mode != Mode::Fn {
@ -530,7 +530,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
"cannot refer to the interior of another \
static, use a constant instead");
}
let ty = lvalue.ty(this.mir, this.tcx).to_ty(this.tcx);
let ty = lvalue.ty(&this.mir.local_decls, this.tcx).to_ty(this.tcx);
this.qualif.restrict(ty, this.tcx, this.param_env);
}
@ -606,7 +606,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
self.add(Qualif::STATIC_REF);
}
let ty = lvalue.ty(self.mir, self.tcx).to_ty(self.tcx);
let ty = lvalue.ty(&self.mir.local_decls, self.tcx).to_ty(self.tcx);
if kind == BorrowKind::Mut {
// In theory, any zero-sized value could be borrowed
// mutably without consequences. However, only &mut []
@ -671,7 +671,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
}
Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => {
let operand_ty = operand.ty(self.mir, self.tcx);
let operand_ty = operand.ty(&self.mir.local_decls, self.tcx);
let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast");
let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast");
match (cast_in, cast_out) {
@ -689,7 +689,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
}
Rvalue::BinaryOp(op, ref lhs, _) => {
if let ty::TyRawPtr(_) = lhs.ty(self.mir, self.tcx).sty {
if let ty::TyRawPtr(_) = lhs.ty(&self.mir.local_decls, self.tcx).sty {
assert!(op == BinOp::Eq || op == BinOp::Ne ||
op == BinOp::Le || op == BinOp::Lt ||
op == BinOp::Ge || op == BinOp::Gt ||
@ -727,7 +727,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
}
if Some(def.did) == self.tcx.lang_items.unsafe_cell_type() {
let ty = rvalue.ty(self.mir, self.tcx);
let ty = rvalue.ty(&self.mir.local_decls, self.tcx);
self.add_type(ty);
assert!(self.qualif.intersects(Qualif::MUTABLE_INTERIOR));
// Even if the value inside may not need dropping,
@ -748,7 +748,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
if let TerminatorKind::Call { ref func, ref args, ref destination, .. } = *kind {
self.visit_operand(func, location);
let fn_ty = func.ty(self.mir, self.tcx);
let fn_ty = func.ty(&self.mir.local_decls, self.tcx);
let (is_shuffle, is_const_fn) = match fn_ty.sty {
ty::TyFnDef(def_id, _) => {
(self.tcx.fn_sig(def_id).abi() == Abi::PlatformIntrinsic &&
@ -828,7 +828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
} else {
// Be conservative about the returned value of a const fn.
let tcx = self.tcx;
let ty = dest.ty(self.mir, tcx).to_ty(tcx);
let ty = dest.ty(&self.mir.local_decls, tcx).to_ty(tcx);
self.qualif = Qualif::empty();
self.add_type(ty);

View File

@ -84,7 +84,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
self.super_rvalue(rvalue, location);
let rval_ty = rvalue.ty(self.mir, self.tcx());
let rval_ty = rvalue.ty(&self.mir.local_decls, self.tcx());
self.sanitize_type(rvalue, rval_ty);
}
@ -178,7 +178,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
ProjectionElem::Index(ref i) => {
self.visit_operand(i, location);
let index_ty = i.ty(self.mir, tcx);
let index_ty = i.ty(&self.mir.local_decls, tcx);
if index_ty != tcx.types.usize {
LvalueTy::Ty {
ty: span_mirbug_and_err!(self, i, "index by non-usize {:?}", i)
@ -378,15 +378,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
let tcx = self.tcx();
match stmt.kind {
StatementKind::Assign(ref lv, ref rv) => {
let lv_ty = lv.ty(mir, tcx).to_ty(tcx);
let rv_ty = rv.ty(mir, tcx);
let lv_ty = lv.ty(&mir.local_decls, tcx).to_ty(tcx);
let rv_ty = rv.ty(&mir.local_decls, tcx);
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
span_mirbug!(self, stmt, "bad assignment ({:?} = {:?}): {:?}",
lv_ty, rv_ty, terr);
}
}
StatementKind::SetDiscriminant{ ref lvalue, variant_index } => {
let lvalue_type = lvalue.ty(mir, tcx).to_ty(tcx);
let lvalue_type = lvalue.ty(&mir.local_decls, tcx).to_ty(tcx);
let adt = match lvalue_type.sty {
TypeVariants::TyAdt(adt, _) if adt.is_enum() => adt,
_ => {
@ -438,15 +438,15 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
ref value,
..
} => {
let lv_ty = location.ty(mir, tcx).to_ty(tcx);
let rv_ty = value.ty(mir, tcx);
let lv_ty = location.ty(&mir.local_decls, tcx).to_ty(tcx);
let rv_ty = value.ty(&mir.local_decls, tcx);
if let Err(terr) = self.sub_types(rv_ty, lv_ty) {
span_mirbug!(self, term, "bad DropAndReplace ({:?} = {:?}): {:?}",
lv_ty, rv_ty, terr);
}
}
TerminatorKind::SwitchInt { ref discr, switch_ty, .. } => {
let discr_ty = discr.ty(mir, tcx);
let discr_ty = discr.ty(&mir.local_decls, tcx);
if let Err(terr) = self.sub_types(discr_ty, switch_ty) {
span_mirbug!(self, term, "bad SwitchInt ({:?} on {:?}): {:?}",
switch_ty, discr_ty, terr);
@ -459,7 +459,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
// FIXME: check the values
}
TerminatorKind::Call { ref func, ref args, ref destination, .. } => {
let func_ty = func.ty(mir, tcx);
let func_ty = func.ty(&mir.local_decls, tcx);
debug!("check_terminator: call, func_ty={:?}", func_ty);
let sig = match func_ty.sty {
ty::TyFnDef(..) | ty::TyFnPtr(_) => func_ty.fn_sig(tcx),
@ -479,16 +479,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
}
}
TerminatorKind::Assert { ref cond, ref msg, .. } => {
let cond_ty = cond.ty(mir, tcx);
let cond_ty = cond.ty(&mir.local_decls, tcx);
if cond_ty != tcx.types.bool {
span_mirbug!(self, term, "bad Assert ({:?}, not bool", cond_ty);
}
if let AssertMessage::BoundsCheck { ref len, ref index } = *msg {
if len.ty(mir, tcx) != tcx.types.usize {
if len.ty(&mir.local_decls, tcx) != tcx.types.usize {
span_mirbug!(self, len, "bounds-check length non-usize {:?}", len)
}
if index.ty(mir, tcx) != tcx.types.usize {
if index.ty(&mir.local_decls, tcx) != tcx.types.usize {
span_mirbug!(self, index, "bounds-check index non-usize {:?}", index)
}
}
@ -504,7 +504,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
let tcx = self.tcx();
match *destination {
Some((ref dest, _)) => {
let dest_ty = dest.ty(mir, tcx).to_ty(tcx);
let dest_ty = dest.ty(&mir.local_decls, tcx).to_ty(tcx);
if let Err(terr) = self.sub_types(sig.output(), dest_ty) {
span_mirbug!(self, term,
"call dest mismatch ({:?} <- {:?}): {:?}",
@ -532,7 +532,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
span_mirbug!(self, term, "call to {:?} with wrong # of args", sig);
}
for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() {
let op_arg_ty = op_arg.ty(mir, self.tcx());
let op_arg_ty = op_arg.ty(&mir.local_decls, self.tcx());
if let Err(terr) = self.sub_types(op_arg_ty, fn_arg) {
span_mirbug!(self, term, "bad arg #{:?} ({:?} <- {:?}): {:?}",
n, fn_arg, op_arg_ty, terr);
@ -581,7 +581,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
return;
}
let ty = args[0].ty(mir, self.tcx());
let ty = args[0].ty(&mir.local_decls, self.tcx());
let arg_ty = match ty.sty {
ty::TyRawPtr(mt) => mt.ty,
ty::TyAdt(def, _) if def.is_box() => ty.boxed_ty(),

View File

@ -130,7 +130,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D>
where D: DropElaborator<'b, 'tcx>
{
fn lvalue_ty(&self, lvalue: &Lvalue<'tcx>) -> Ty<'tcx> {
lvalue.ty(self.elaborator.mir(), self.tcx()).to_ty(self.tcx())
lvalue.ty(&self.elaborator.mir().local_decls, self.tcx()).to_ty(self.tcx())
}
fn tcx(&self) -> ty::TyCtxt<'b, 'tcx, 'tcx> {

View File

@ -474,7 +474,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => {
let target_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs,
&target_ty);
let source_ty = operand.ty(self.mir, self.scx.tcx());
let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx());
let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs,
&source_ty);
let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.scx,
@ -491,13 +491,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
}
}
mir::Rvalue::Cast(mir::CastKind::ReifyFnPointer, ref operand, _) => {
let fn_ty = operand.ty(self.mir, self.scx.tcx());
let fn_ty = operand.ty(&self.mir.local_decls, self.scx.tcx());
let fn_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs,
&fn_ty);
visit_fn_use(self.scx, fn_ty, false, &mut self.output);
}
mir::Rvalue::Cast(mir::CastKind::ClosureFnPointer, ref operand, _) => {
let source_ty = operand.ty(self.mir, self.scx.tcx());
let source_ty = operand.ty(&self.mir.local_decls, self.scx.tcx());
let source_ty = self.scx.tcx().trans_apply_param_substs(self.param_substs,
&source_ty);
match source_ty.sty {
@ -555,13 +555,13 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let tcx = self.scx.tcx();
match *kind {
mir::TerminatorKind::Call { ref func, .. } => {
let callee_ty = func.ty(self.mir, tcx);
let callee_ty = func.ty(&self.mir.local_decls, tcx);
let callee_ty = tcx.trans_apply_param_substs(self.param_substs, &callee_ty);
visit_fn_use(self.scx, callee_ty, true, &mut self.output);
}
mir::TerminatorKind::Drop { ref location, .. } |
mir::TerminatorKind::DropAndReplace { ref location, .. } => {
let ty = location.ty(self.mir, self.scx.tcx())
let ty = location.ty(&self.mir.local_decls, self.scx.tcx())
.to_ty(self.scx.tcx());
let ty = tcx.trans_apply_param_substs(self.param_substs, &ty);
visit_drop_use(self.scx, ty, true, self.output);

View File

@ -137,7 +137,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
// Allow uses of projections of immediate pair fields.
if let mir::Lvalue::Projection(ref proj) = *lvalue {
if let mir::Lvalue::Local(_) = proj.base {
let ty = proj.base.ty(self.cx.mir, self.cx.ccx.tcx());
let ty = proj.base.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx());
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx()));
if common::type_is_imm_pair(self.cx.ccx, ty) {
@ -168,7 +168,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
}
LvalueContext::Drop => {
let ty = lvalue.ty(self.cx.mir, self.cx.ccx.tcx());
let ty = lvalue.ty(&self.cx.mir.local_decls, self.cx.ccx.tcx());
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx()));
// Only need the lvalue if we're actually dropping it.

View File

@ -263,7 +263,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
}
mir::TerminatorKind::Drop { ref location, target, unwind } => {
let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
let ty = location.ty(&self.mir.local_decls, bcx.tcx()).to_ty(bcx.tcx());
let ty = self.monomorphize(&ty);
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.shared(), ty);
@ -438,7 +438,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
let extra_args = &args[sig.inputs().len()..];
let extra_args = extra_args.iter().map(|op_arg| {
let op_ty = op_arg.ty(&self.mir, bcx.tcx());
let op_ty = op_arg.ty(&self.mir.local_decls, bcx.tcx());
self.monomorphize(&op_ty)
}).collect::<Vec<_>>();

View File

@ -275,7 +275,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
let span = statement.source_info.span;
match statement.kind {
mir::StatementKind::Assign(ref dest, ref rvalue) => {
let ty = dest.ty(self.mir, tcx);
let ty = dest.ty(&self.mir.local_decls, tcx);
let ty = self.monomorphize(&ty).to_ty(tcx);
match self.const_rvalue(rvalue, ty, span) {
Ok(value) => self.store(dest, value, span),
@ -331,7 +331,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
}
mir::TerminatorKind::Call { ref func, ref args, ref destination, .. } => {
let fn_ty = func.ty(self.mir, tcx);
let fn_ty = func.ty(&self.mir.local_decls, tcx);
let fn_ty = self.monomorphize(&fn_ty);
let (def_id, substs) = match fn_ty.sty {
ty::TyFnDef(def_id, substs) => (def_id, substs),

View File

@ -408,7 +408,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
pub fn monomorphized_lvalue_ty(&self, lvalue: &mir::Lvalue<'tcx>) -> Ty<'tcx> {
let tcx = self.ccx.tcx();
let lvalue_ty = lvalue.ty(&self.mir, tcx);
let lvalue_ty = lvalue.ty(&self.mir.local_decls, tcx);
self.monomorphize(&lvalue_ty.to_ty(tcx))
}
}

View File

@ -422,7 +422,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
mir::Rvalue::Discriminant(ref lvalue) => {
let discr_lvalue = self.trans_lvalue(&bcx, lvalue);
let enum_ty = discr_lvalue.ty.to_ty(bcx.tcx());
let discr_ty = rvalue.ty(&*self.mir, bcx.tcx());
let discr_ty = rvalue.ty(&self.mir.local_decls, bcx.tcx());
let discr_type = type_of::immediate_type_of(bcx.ccx, discr_ty);
let discr = adt::trans_get_discr(&bcx, enum_ty, discr_lvalue.llval,
discr_lvalue.alignment, Some(discr_type), true);
@ -476,7 +476,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
mir::Rvalue::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(self.mir, self.ccx.tcx());
let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx());
(bcx, OperandRef::new_zst(self.ccx, self.monomorphize(&ty)))
}
}
@ -676,7 +676,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
true,
mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(self.mir, self.ccx.tcx());
let ty = rvalue.ty(&self.mir.local_decls, self.ccx.tcx());
let ty = self.monomorphize(&ty);
common::type_is_zero_size(self.ccx, ty)
}