+//! 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
/// 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, .. })) => {
/// 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>,
) {
};
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(),
// 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) {
.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
(
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;
}