From: Ralf Jung Date: Tue, 11 Jul 2017 23:02:06 +0000 (-0700) Subject: Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=62b2e5446d1a47f00729f2066f05254081f29914;p=rust.git Refactor: {Lvalue,Rvalue,Operand}::ty only need the locals' types, not the full &Mir --- diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 96ccc3ba500..8ac4e1208b0 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -66,6 +66,9 @@ fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { ) } +/// Types for locals +type LocalDecls<'tcx> = IndexVec>; + /// 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>, + pub local_decls: LocalDecls<'tcx>, /// Number of arguments this function takes. /// diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index 71acb36ecf7..b99c0180ecc 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -121,31 +121,31 @@ fn super_visit_with>(&self, visitor: &mut V) -> bool { } 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 @@ pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<' 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 @@ pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<' } 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 @@ pub fn ty<'a, 'gcx>(&self, mir: &Mir<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<' } 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, } } diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index daafbecc5df..a247cd77450 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -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; } diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index d7ed0938e88..e92ece7505f 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -286,7 +286,7 @@ fn move_path_for_projection(&mut self, -> Result { 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 @@ fn gather_operand(&mut self, loc: Location, operand: &Operand<'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 diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 5f80c7bee14..db951a7fef8 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -250,7 +250,7 @@ fn should_inline(&self, 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 @@ fn dest_needs_borrow(lval: &Lvalue) -> bool { 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 @@ fn dest_needs_borrow(lval: &Lvalue) -> bool { 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 @@ fn cast_box_free_arg(&self, arg: Lvalue<'tcx>, ptr_ty: Ty<'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 @@ fn make_call_args(&self, args: Vec>, // 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); diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 88a368077d4..65d20d3be87 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -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); } } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index e1c4602b045..8cb6c0b055e 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -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, diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index 68b687a2e61..3180133b05a 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -507,7 +507,7 @@ fn visit_lvalue(&mut self, 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 @@ fn visit_lvalue(&mut self, "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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { 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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { } 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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { } 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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { } 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 @@ fn visit_terminator_kind(&mut self, 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 @@ struct and enum constructors", } 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); diff --git a/src/librustc_mir/transform/type_check.rs b/src/librustc_mir/transform/type_check.rs index 7e6fccf3019..1175f955b4e 100644 --- a/src/librustc_mir/transform/type_check.rs +++ b/src/librustc_mir/transform/type_check.rs @@ -84,7 +84,7 @@ fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) { 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 @@ fn sanitize_projection(&mut self, } 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 @@ fn check_stmt(&mut self, mir: &Mir<'tcx>, stmt: &Statement<'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 @@ fn check_terminator(&mut self, 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 @@ fn check_terminator(&mut self, // 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 @@ fn check_terminator(&mut self, } } 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 @@ fn check_call_dest(&mut self, 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 @@ fn check_call_inputs(&mut self, 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 @@ fn check_box_free_inputs(&mut self, 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(), diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index da7e218439c..efeffbbe7d1 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -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> { diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index a76abcf7b49..4eb7efc593d 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -474,7 +474,7 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { 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 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { } } 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 @@ fn visit_terminator_kind(&mut self, 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); diff --git a/src/librustc_trans/mir/analyze.rs b/src/librustc_trans/mir/analyze.rs index 45afcf51b52..5c9f6f3b297 100644 --- a/src/librustc_trans/mir/analyze.rs +++ b/src/librustc_trans/mir/analyze.rs @@ -137,7 +137,7 @@ fn visit_lvalue(&mut self, // 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 @@ fn visit_lvalue(&mut self, } 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. diff --git a/src/librustc_trans/mir/block.rs b/src/librustc_trans/mir/block.rs index 48b166c61de..8cc1e787928 100644 --- a/src/librustc_trans/mir/block.rs +++ b/src/librustc_trans/mir/block.rs @@ -263,7 +263,7 @@ fn trans_terminator(&mut self, } 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 @@ fn trans_terminator(&mut self, 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::>(); diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index fcb4b25e6fe..d2479f1d883 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -275,7 +275,7 @@ fn trans(&mut self) -> Result, ConstEvalErr<'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 @@ fn trans(&mut self) -> Result, ConstEvalErr<'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), diff --git a/src/librustc_trans/mir/lvalue.rs b/src/librustc_trans/mir/lvalue.rs index 88e46b5c99a..40cbb4e6537 100644 --- a/src/librustc_trans/mir/lvalue.rs +++ b/src/librustc_trans/mir/lvalue.rs @@ -408,7 +408,7 @@ fn prepare_index(&mut self, bcx: &Builder<'a, 'tcx>, llindex: ValueRef) -> Value 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)) } } diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index 4bd5091a4f3..695dd278bc8 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -422,7 +422,7 @@ pub fn trans_rvalue_operand(&mut self, 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 @@ pub fn trans_rvalue_operand(&mut self, 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 @@ pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool { 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) }