about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/abi/mod.rs6
-rw-r--r--src/abi/pass_mode.rs2
-rw-r--r--src/base.rs4
-rw-r--r--src/constant.rs15
-rw-r--r--src/discriminant.rs6
-rw-r--r--src/intrinsics/mod.rs6
-rw-r--r--src/num.rs5
-rw-r--r--src/unsize.rs33
-rw-r--r--src/value_and_place.rs17
-rw-r--r--src/vtable.rs17
10 files changed, 54 insertions, 57 deletions
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index c983daabdc1..00e7ae48b79 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -276,7 +276,7 @@ fn local_place<'tcx>(
     let place = if is_ssa {
         CPlace::new_var(fx, local, layout)
     } else {
-        CPlace::new_stack_slot(fx, layout.ty)
+        CPlace::new_stack_slot(fx, layout)
     };
 
     #[cfg(debug_assertions)]
@@ -667,13 +667,13 @@ pub fn codegen_drop<'tcx>(
             _ => {
                 let arg_place = CPlace::new_stack_slot(
                     fx,
-                    fx.tcx.mk_ref(
+                    fx.layout_of(fx.tcx.mk_ref(
                         &ty::RegionKind::ReErased,
                         TypeAndMut {
                             ty,
                             mutbl: crate::rustc_hir::Mutability::Mut,
                         },
-                    ),
+                    )),
                 );
                 drop_place.write_place_ref(fx, arg_place);
                 let arg_value = arg_place.to_cvalue(fx);
diff --git a/src/abi/pass_mode.rs b/src/abi/pass_mode.rs
index 58f6eaf25ce..231eb64de41 100644
--- a/src/abi/pass_mode.rs
+++ b/src/abi/pass_mode.rs
@@ -131,7 +131,7 @@ pub(super) fn cvalue_for_param<'tcx>(
     arg_ty: Ty<'tcx>,
 ) -> Option<CValue<'tcx>> {
     let layout = fx.layout_of(arg_ty);
-    let pass_mode = get_pass_mode(fx.tcx, fx.layout_of(arg_ty));
+    let pass_mode = get_pass_mode(fx.tcx, layout);
 
     if let PassMode::NoPass = pass_mode {
         return None;
diff --git a/src/base.rs b/src/base.rs
index 0c0f43d076e..5eb0170a19d 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -363,7 +363,7 @@ fn trans_stmt<'tcx>(
                         }
                         UnOp::Neg => match layout.ty.kind {
                             ty::Int(_) => {
-                                let zero = CValue::const_val(fx, layout.ty, 0);
+                                let zero = CValue::const_val(fx, layout, 0);
                                 crate::num::trans_int_binop(fx, BinOp::Sub, zero, operand)
                             }
                             ty::Float(_) => {
@@ -528,7 +528,7 @@ fn trans_stmt<'tcx>(
                         .ty
                         .is_sized(fx.tcx.at(stmt.source_info.span), ParamEnv::reveal_all()));
                     let ty_size = fx.layout_of(fx.monomorphize(ty)).size.bytes();
-                    let val = CValue::const_val(fx, fx.tcx.types.usize, ty_size.into());
+                    let val = CValue::const_val(fx, fx.layout_of(fx.tcx.types.usize), ty_size.into());
                     lval.write_cvalue(fx, val);
                 }
                 Rvalue::Aggregate(kind, operands) => match **kind {
diff --git a/src/constant.rs b/src/constant.rs
index 92ccaa1b164..6d33f71072a 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -43,11 +43,11 @@ pub fn codegen_static(constants_cx: &mut ConstantCx, def_id: DefId) {
 fn codegen_static_ref<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
     def_id: DefId,
-    ty: Ty<'tcx>,
+    layout: TyLayout<'tcx>,
 ) -> CPlace<'tcx> {
     let linkage = crate::linkage::get_static_ref_linkage(fx.tcx, def_id);
     let data_id = data_id_for_static(fx.tcx, fx.module, def_id, linkage);
-    cplace_for_dataid(fx, ty, data_id)
+    cplace_for_dataid(fx, layout, data_id)
 }
 
 pub fn trans_constant<'tcx>(
@@ -62,7 +62,7 @@ pub fn trans_constant<'tcx>(
             return codegen_static_ref(
                 fx,
                 def_id,
-                fx.monomorphize(&constant.literal.ty),
+                fx.layout_of(fx.monomorphize(&constant.literal.ty)),
             ).to_cvalue(fx);
         }
         ConstKind::Unevaluated(def_id, ref substs, promoted) => {
@@ -137,13 +137,13 @@ pub fn trans_const_value<'tcx>(
                     let bits = const_.val.try_to_bits(layout.size).unwrap_or_else(|| {
                         panic!("{:?}\n{:?}", const_, layout);
                     });
-                    CValue::const_val(fx, ty, bits)
+                    CValue::const_val(fx, layout, bits)
                 }
                 ty::Int(_) => {
                     let bits = const_.val.try_to_bits(layout.size).unwrap();
                     CValue::const_val(
                         fx,
-                        ty,
+                        layout,
                         rustc::mir::interpret::sign_extend(bits, layout.size),
                     )
                 }
@@ -228,7 +228,7 @@ fn trans_const_place<'tcx>(
     let alloc_id = fx.tcx.alloc_map.lock().create_memory_alloc(alloc);
     fx.constants_cx.todo.insert(TodoItem::Alloc(alloc_id));
     let data_id = data_id_for_alloc_id(fx.module, alloc_id, alloc.align);
-    cplace_for_dataid(fx, const_.ty, data_id)
+    cplace_for_dataid(fx, fx.layout_of(const_.ty), data_id)
 }
 
 fn data_id_for_alloc_id<B: Backend>(
@@ -304,12 +304,11 @@ fn data_id_for_static(
 
 fn cplace_for_dataid<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-    ty: Ty<'tcx>,
+    layout: TyLayout<'tcx>,
     data_id: DataId,
 ) -> CPlace<'tcx> {
     let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
     let global_ptr = fx.bcx.ins().global_value(fx.pointer_type, local_data_id);
-    let layout = fx.layout_of(fx.monomorphize(&ty));
     assert!(!layout.is_unsized(), "unsized statics aren't supported");
     CPlace::for_ptr(crate::pointer::Pointer::new(global_ptr), layout)
 }
diff --git a/src/discriminant.rs b/src/discriminant.rs
index ccc474401b6..6389bd6277c 100644
--- a/src/discriminant.rs
+++ b/src/discriminant.rs
@@ -27,7 +27,7 @@ pub fn codegen_set_discriminant<'tcx>(
                 .discriminant_for_variant(fx.tcx, variant_index)
                 .unwrap()
                 .val;
-            let discr = CValue::const_val(fx, ptr.layout().ty, to);
+            let discr = CValue::const_val(fx, ptr.layout(), to);
             ptr.write_cvalue(fx, discr);
         }
         layout::Variants::Multiple {
@@ -45,7 +45,7 @@ pub fn codegen_set_discriminant<'tcx>(
                 let niche = place.place_field(fx, mir::Field::new(discr_index));
                 let niche_value = variant_index.as_u32() - niche_variants.start().as_u32();
                 let niche_value = u128::from(niche_value).wrapping_add(niche_start);
-                let niche_llval = CValue::const_val(fx, niche.layout().ty, niche_value);
+                let niche_llval = CValue::const_val(fx, niche.layout(), niche_value);
                 niche.write_cvalue(fx, niche_llval);
             }
         }
@@ -73,7 +73,7 @@ pub fn codegen_get_discriminant<'tcx>(
                 .ty
                 .discriminant_for_variant(fx.tcx, *index)
                 .map_or(u128::from(index.as_u32()), |discr| discr.val);
-            return CValue::const_val(fx, dest_layout.ty, discr_val);
+            return CValue::const_val(fx, dest_layout, discr_val);
         }
         layout::Variants::Multiple {
             discr,
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs
index 70c9167c69e..459c68baa63 100644
--- a/src/intrinsics/mod.rs
+++ b/src/intrinsics/mod.rs
@@ -453,7 +453,7 @@ pub fn codegen_intrinsic_call<'tcx>(
             let layout = fx.layout_of(T);
             let size = if layout.is_unsized() {
                 let (_ptr, info) = ptr.load_scalar_pair(fx);
-                let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout.ty, info);
+                let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout, info);
                 size
             } else {
                 fx
@@ -467,7 +467,7 @@ pub fn codegen_intrinsic_call<'tcx>(
             let layout = fx.layout_of(T);
             let align = if layout.is_unsized() {
                 let (_ptr, info) = ptr.load_scalar_pair(fx);
-                let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout.ty, info);
+                let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout, info);
                 align
             } else {
                 fx
@@ -951,7 +951,7 @@ pub fn codegen_intrinsic_call<'tcx>(
 
             fx.bcx.ins().call_indirect(f_sig, f, &[data]);
 
-            let ret_val = CValue::const_val(fx, ret.layout().ty, 0);
+            let ret_val = CValue::const_val(fx, ret.layout(), 0);
             ret.write_cvalue(fx, ret_val);
         };
     }
diff --git a/src/num.rs b/src/num.rs
index 5dee1d8c2ab..e11143d6bd2 100644
--- a/src/num.rs
+++ b/src/num.rs
@@ -285,10 +285,11 @@ pub fn trans_checked_int_binop<'tcx>(
     };
 
     let has_overflow = fx.bcx.ins().bint(types::I8, has_overflow);
+
+    // FIXME directly write to result place instead
     let out_place = CPlace::new_stack_slot(
         fx,
-        fx.tcx
-            .mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter()),
+        fx.layout_of(fx.tcx.mk_tup([in_lhs.layout().ty, fx.tcx.types.bool].iter())),
     );
     let out_layout = out_place.layout();
     out_place.write_cvalue(fx, CValue::by_val_pair(res, has_overflow, out_layout));
diff --git a/src/unsize.rs b/src/unsize.rs
index 6d497b18866..ab2b2f201a2 100644
--- a/src/unsize.rs
+++ b/src/unsize.rs
@@ -28,7 +28,9 @@ pub fn unsized_info<'tcx>(
             // change to the vtable.
             old_info.expect("unsized_info: missing old info for trait upcast")
         }
-        (_, &ty::Dynamic(ref data, ..)) => crate::vtable::get_vtable(fx, source, data.principal()),
+        (_, &ty::Dynamic(ref data, ..)) => {
+            crate::vtable::get_vtable(fx, fx.layout_of(source), data.principal())
+        }
         _ => bug!(
             "unsized_info: invalid unsizing {:?} -> {:?}",
             source,
@@ -38,13 +40,13 @@ pub fn unsized_info<'tcx>(
 }
 
 /// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer.
-pub fn unsize_thin_ptr<'tcx>(
+fn unsize_thin_ptr<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
     src: Value,
-    src_ty: Ty<'tcx>,
-    dst_ty: Ty<'tcx>,
+    src_layout: TyLayout<'tcx>,
+    dst_layout: TyLayout<'tcx>,
 ) -> (Value, Value) {
-    match (&src_ty.kind, &dst_ty.kind) {
+    match (&src_layout.ty.kind, &dst_layout.ty.kind) {
         (&ty::Ref(_, a, _), &ty::Ref(_, b, _))
         | (&ty::Ref(_, a, _), &ty::RawPtr(ty::TypeAndMut { ty: b, .. }))
         | (&ty::RawPtr(ty::TypeAndMut { ty: a, .. }), &ty::RawPtr(ty::TypeAndMut { ty: b, .. })) => {
@@ -52,15 +54,13 @@ pub fn unsize_thin_ptr<'tcx>(
             (src, unsized_info(fx, a, b, None))
         }
         (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => {
-            let (a, b) = (src_ty.boxed_ty(), dst_ty.boxed_ty());
+            let (a, b) = (src_layout.ty.boxed_ty(), dst_layout.ty.boxed_ty());
             assert!(!fx.layout_of(a).is_unsized());
             (src, unsized_info(fx, a, b, None))
         }
         (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => {
             assert_eq!(def_a, def_b);
 
-            let src_layout = fx.layout_of(src_ty);
-            let dst_layout = fx.layout_of(dst_ty);
             let mut result = None;
             for i in 0..src_layout.fields.count() {
                 let src_f = src_layout.field(fx, i);
@@ -74,7 +74,7 @@ pub fn unsize_thin_ptr<'tcx>(
                 let dst_f = dst_layout.field(fx, i);
                 assert_ne!(src_f.ty, dst_f.ty);
                 assert_eq!(result, None);
-                result = Some(unsize_thin_ptr(fx, src, src_f.ty, dst_f.ty));
+                result = Some(unsize_thin_ptr(fx, src, src_f, dst_f));
             }
             result.unwrap()
         }
@@ -101,7 +101,7 @@ pub fn coerce_unsized_into<'tcx>(
             src.load_scalar_pair(fx)
         } else {
             let base = src.load_scalar(fx);
-            unsize_thin_ptr(fx, base, src_ty, dst_ty)
+            unsize_thin_ptr(fx, base, src.layout(), dst.layout())
         };
         dst.write_cvalue(fx, CValue::by_val_pair(base, info, dst.layout()));
     };
@@ -139,10 +139,9 @@ pub fn coerce_unsized_into<'tcx>(
 
 pub fn size_and_align_of_dst<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-    ty: Ty<'tcx>,
+    layout: TyLayout<'tcx>,
     info: Value,
 ) -> (Value, Value) {
-    let layout = fx.layout_of(ty);
     if !layout.is_unsized() {
         let size = fx
             .bcx
@@ -154,7 +153,7 @@ pub fn size_and_align_of_dst<'tcx>(
             .iconst(fx.pointer_type, layout.align.abi.bytes() as i64);
         return (size, align);
     }
-    match ty.kind {
+    match layout.ty.kind {
         ty::Dynamic(..) => {
             // load size/align from vtable
             (
@@ -177,7 +176,7 @@ pub fn size_and_align_of_dst<'tcx>(
             // First get the size of all statically known fields.
             // Don't use size_of because it also rounds up to alignment, which we
             // want to avoid, as the unsized field's alignment could be smaller.
-            assert!(!ty.is_simd());
+            assert!(!layout.ty.is_simd());
 
             let i = layout.fields.count() - 1;
             let sized_size = layout.fields.offset(i).bytes();
@@ -186,8 +185,8 @@ pub fn size_and_align_of_dst<'tcx>(
 
             // Recurse to get the size of the dynamically sized field (must be
             // the last field).
-            let field_ty = layout.field(fx, i).ty;
-            let (unsized_size, mut unsized_align) = size_and_align_of_dst(fx, field_ty, info);
+            let field_layout = layout.field(fx, i);
+            let (unsized_size, mut unsized_align) = size_and_align_of_dst(fx, field_layout, info);
 
             // FIXME (#26403, #27023): We should be adding padding
             // to `sized_size` (to accommodate the `unsized_align`
@@ -200,7 +199,7 @@ pub fn size_and_align_of_dst<'tcx>(
             let size = fx.bcx.ins().iadd_imm(unsized_size, sized_size as i64);
 
             // Packed types ignore the alignment of their fields.
-            if let ty::Adt(def, _) = ty.kind {
+            if let ty::Adt(def, _) = layout.ty.kind {
                 if def.repr.packed() {
                     unsized_align = sized_align;
                 }
diff --git a/src/value_and_place.rs b/src/value_and_place.rs
index 39eb7d24707..95913256f24 100644
--- a/src/value_and_place.rs
+++ b/src/value_and_place.rs
@@ -32,7 +32,7 @@ fn codegen_field<'tcx>(
             _ => {
                 // We have to align the offset for DST's
                 let unaligned_offset = field_offset.bytes();
-                let (_, unsized_align) = crate::unsize::size_and_align_of_dst(fx, field_layout.ty, extra);
+                let (_, unsized_align) = crate::unsize::size_and_align_of_dst(fx, field_layout, extra);
 
                 let one = fx.bcx.ins().iconst(pointer_ty(fx.tcx), 1);
                 let align_sub_1 = fx.bcx.ins().isub(unsized_align, one);
@@ -88,12 +88,13 @@ impl<'tcx> CValue<'tcx> {
         self.1
     }
 
+    // FIXME remove
     pub fn force_stack<'a>(self, fx: &mut FunctionCx<'_, 'tcx, impl Backend>) -> Pointer {
         let layout = self.1;
         match self.0 {
             CValueInner::ByRef(ptr) => ptr,
             CValueInner::ByVal(_) | CValueInner::ByValPair(_, _) => {
-                let cplace = CPlace::new_stack_slot(fx, layout.ty);
+                let cplace = CPlace::new_stack_slot(fx, layout);
                 cplace.write_cvalue(fx, self);
                 cplace.to_ptr(fx)
             }
@@ -196,13 +197,12 @@ impl<'tcx> CValue<'tcx> {
     /// If `ty` is signed, `const_val` must already be sign extended.
     pub fn const_val<'a>(
         fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-        ty: Ty<'tcx>,
+        layout: TyLayout<'tcx>,
         const_val: u128,
     ) -> CValue<'tcx> {
-        let clif_ty = fx.clif_type(ty).unwrap();
-        let layout = fx.layout_of(ty);
+        let clif_ty = fx.clif_type(layout.ty).unwrap();
 
-        let val = match ty.kind {
+        let val = match layout.ty.kind {
             ty::TyKind::Uint(UintTy::U128) | ty::TyKind::Int(IntTy::I128) => {
                 let lsb = fx.bcx.ins().iconst(types::I64, const_val as u64 as i64);
                 let msb = fx
@@ -226,7 +226,7 @@ impl<'tcx> CValue<'tcx> {
             ty::TyKind::Int(_) => fx.bcx.ins().iconst(clif_ty, const_val as i128 as i64),
             _ => panic!(
                 "CValue::const_val for non bool/integer/pointer type {:?} is not allowed",
-                ty
+                layout.ty
             ),
         };
 
@@ -270,9 +270,8 @@ impl<'tcx> CPlace<'tcx> {
 
     pub fn new_stack_slot(
         fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-        ty: Ty<'tcx>,
+        layout: TyLayout<'tcx>,
     ) -> CPlace<'tcx> {
-        let layout = fx.layout_of(ty);
         assert!(!layout.is_unsized());
         if layout.size.bytes() == 0 {
             return CPlace {
diff --git a/src/vtable.rs b/src/vtable.rs
index 913bb712da3..7eaf8ffdada 100644
--- a/src/vtable.rs
+++ b/src/vtable.rs
@@ -60,14 +60,14 @@ pub fn get_ptr_and_method_ref<'tcx>(
 
 pub fn get_vtable<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-    ty: Ty<'tcx>,
+    layout: TyLayout<'tcx>,
     trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
 ) -> Value {
-    let data_id = if let Some(data_id) = fx.vtables.get(&(ty, trait_ref)) {
+    let data_id = if let Some(data_id) = fx.vtables.get(&(layout.ty, trait_ref)) {
         *data_id
     } else {
-        let data_id = build_vtable(fx, ty, trait_ref);
-        fx.vtables.insert((ty, trait_ref), data_id);
+        let data_id = build_vtable(fx, layout, trait_ref);
+        fx.vtables.insert((layout.ty, trait_ref), data_id);
         data_id
     };
 
@@ -77,20 +77,20 @@ pub fn get_vtable<'tcx>(
 
 fn build_vtable<'tcx>(
     fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
-    ty: Ty<'tcx>,
+    layout: TyLayout<'tcx>,
     trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>,
 ) -> DataId {
     let tcx = fx.tcx;
     let usize_size = fx.layout_of(fx.tcx.types.usize).size.bytes() as usize;
 
     let drop_in_place_fn =
-        import_function(tcx, fx.module, Instance::resolve_drop_in_place(tcx, ty));
+        import_function(tcx, fx.module, Instance::resolve_drop_in_place(tcx, layout.ty));
 
     let mut components: Vec<_> = vec![Some(drop_in_place_fn), None, None];
 
     let methods_root;
     let methods = if let Some(trait_ref) = trait_ref {
-        methods_root = tcx.vtable_methods(trait_ref.with_self_ty(tcx, ty));
+        methods_root = tcx.vtable_methods(trait_ref.with_self_ty(tcx, layout.ty));
         methods_root.iter()
     } else {
         (&[]).iter()
@@ -112,7 +112,6 @@ fn build_vtable<'tcx>(
         .collect::<Vec<u8>>()
         .into_boxed_slice();
 
-    let layout = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap();
     write_usize(fx.tcx, &mut data, SIZE_INDEX, layout.size.bytes());
     write_usize(fx.tcx, &mut data, ALIGN_INDEX, layout.align.abi.bytes());
     data_ctx.define(data);
@@ -127,7 +126,7 @@ fn build_vtable<'tcx>(
     let data_id = fx
         .module
         .declare_data(
-            &format!("vtable.{:?}.for.{:?}", trait_ref, ty),
+            &format!("vtable.{:?}.for.{:?}", trait_ref, layout.ty),
             Linkage::Local,
             false,
             Some(