]> git.lizzy.rs Git - rust.git/blobdiff - src/unsize.rs
Rollup merge of #81618 - bjorn3:sync_cg_clif-2021-02-01, r=bjorn3
[rust.git] / src / unsize.rs
index 363186a8c6425254cd5ae5c71e740ae57650eb07..c77ff5d56ba626859e85d806f1c184ee3e41d712 100644 (file)
@@ -1,3 +1,7 @@
+//! Codegen of the [`PointerCast::Unsize`] operation.
+//!
+//! [`PointerCast::Unsize`]: `rustc_middle::ty::adjustment::PointerCast::Unsize`
+
 use crate::prelude::*;
 
 // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/base.rs#L159-L307
 /// in an upcast, where the new vtable for an object will be derived
 /// from the old one.
 pub(crate) fn unsized_info<'tcx>(
-    fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
+    fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     source: Ty<'tcx>,
     target: Ty<'tcx>,
     old_info: Option<Value>,
 ) -> Value {
     let (source, target) =
-        fxcodegen_cx.tcx
+        fx.tcx
             .struct_lockstep_tails_erasing_lifetimes(source, target, ParamEnv::reveal_all());
-    match (&source.kind, &target.kind) {
+    match (&source.kind(), &target.kind()) {
         (&ty::Array(_, len), &ty::Slice(_)) => fx.bcx.ins().iconst(
             fx.pointer_type,
-            len.eval_usize(fxcodegen_cx.tcx, ParamEnv::reveal_all()) as i64,
+            len.eval_usize(fx.tcx, ParamEnv::reveal_all()) as i64,
         ),
         (&ty::Dynamic(..), &ty::Dynamic(..)) => {
             // For now, upcasts are limited to changes in marker
@@ -41,12 +45,12 @@ pub(crate) fn unsized_info<'tcx>(
 
 /// Coerce `src` to `dst_ty`. `src_ty` must be a thin pointer.
 fn unsize_thin_ptr<'tcx>(
-    fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
+    fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     src: Value,
     src_layout: TyAndLayout<'tcx>,
     dst_layout: TyAndLayout<'tcx>,
 ) -> (Value, Value) {
-    match (&src_layout.ty.kind, &dst_layout.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, .. })) => {
@@ -85,7 +89,7 @@ fn unsize_thin_ptr<'tcx>(
 /// Coerce `src`, which is a reference to a value of type `src_ty`,
 /// to a value of type `dst_ty` and store the result in `dst`
 pub(crate) fn coerce_unsized_into<'tcx>(
-    fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
+    fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     src: CValue<'tcx>,
     dst: CPlace<'tcx>,
 ) {
@@ -105,7 +109,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
         };
         dst.write_cvalue(fx, CValue::by_val_pair(base, info, dst.layout()));
     };
-    match (&src_ty.kind, &dst_ty.kind) {
+    match (&src_ty.kind(), &dst_ty.kind()) {
         (&ty::Ref(..), &ty::Ref(..))
         | (&ty::Ref(..), &ty::RawPtr(..))
         | (&ty::RawPtr(..), &ty::RawPtr(..)) => coerce_ptr(),
@@ -138,7 +142,7 @@ pub(crate) fn coerce_unsized_into<'tcx>(
 // Adapted from https://github.com/rust-lang/rust/blob/2a663555ddf36f6b041445894a8c175cd1bc718c/src/librustc_codegen_ssa/glue.rs
 
 pub(crate) fn size_and_align_of_dst<'tcx>(
-    fx: &mut FunctionCx<'_, 'tcx, impl Backend>,
+    fx: &mut FunctionCx<'_, 'tcx, impl Module>,
     layout: TyAndLayout<'tcx>,
     info: Value,
 ) -> (Value, Value) {
@@ -153,7 +157,7 @@ pub(crate) fn size_and_align_of_dst<'tcx>(
             .iconst(fx.pointer_type, layout.align.abi.bytes() as i64);
         return (size, align);
     }
-    match layout.ty.kind {
+    match layout.ty.kind() {
         ty::Dynamic(..) => {
             // load size/align from vtable
             (
@@ -199,7 +203,7 @@ pub(crate) 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, _) = layout.ty.kind {
+            if let ty::Adt(def, _) = layout.ty.kind() {
                 if def.repr.packed() {
                     unsized_align = sized_align;
                 }