rustc_trans: remove type_is_fat_ptr and its uses.
This commit is contained in:
parent
fa67abd127
commit
801a1a0fc1
3 changed files with 27 additions and 47 deletions
|
@ -41,19 +41,6 @@ use syntax_pos::{Span, DUMMY_SP};
|
||||||
|
|
||||||
pub use context::{CrateContext, SharedCrateContext};
|
pub use context::{CrateContext, SharedCrateContext};
|
||||||
|
|
||||||
pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
|
|
||||||
match ty.sty {
|
|
||||||
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
|
|
||||||
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) => {
|
|
||||||
!ccx.shared().type_is_sized(ty)
|
|
||||||
}
|
|
||||||
ty::TyAdt(def, _) if def.is_box() => {
|
|
||||||
!ccx.shared().type_is_sized(ty.boxed_ty())
|
|
||||||
}
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
|
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
|
||||||
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
|
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
|
||||||
}
|
}
|
||||||
|
|
|
@ -674,10 +674,6 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
||||||
operand.llval
|
operand.llval
|
||||||
}
|
}
|
||||||
mir::CastKind::Unsize => {
|
mir::CastKind::Unsize => {
|
||||||
// unsize targets other than to a fat pointer currently
|
|
||||||
// can't be in constants.
|
|
||||||
assert!(common::type_is_fat_ptr(self.ccx, cast_ty));
|
|
||||||
|
|
||||||
let pointee_ty = operand.ty.builtin_deref(true, ty::NoPreference)
|
let pointee_ty = operand.ty.builtin_deref(true, ty::NoPreference)
|
||||||
.expect("consts: unsizing got non-pointer type").ty;
|
.expect("consts: unsizing got non-pointer type").ty;
|
||||||
let (base, old_info) = if !self.ccx.shared().type_is_sized(pointee_ty) {
|
let (base, old_info) = if !self.ccx.shared().type_is_sized(pointee_ty) {
|
||||||
|
@ -760,19 +756,18 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mir::CastKind::Misc => { // Casts from a fat-ptr.
|
mir::CastKind::Misc => { // Casts from a fat-ptr.
|
||||||
if common::type_is_fat_ptr(self.ccx, operand.ty) {
|
let l = self.ccx.layout_of(operand.ty);
|
||||||
|
let cast = self.ccx.layout_of(cast_ty);
|
||||||
|
if l.is_llvm_scalar_pair() {
|
||||||
let (data_ptr, meta) = operand.get_fat_ptr(self.ccx);
|
let (data_ptr, meta) = operand.get_fat_ptr(self.ccx);
|
||||||
if common::type_is_fat_ptr(self.ccx, cast_ty) {
|
if cast.is_llvm_scalar_pair() {
|
||||||
let thin_ptr = self.ccx.layout_of(cast_ty)
|
|
||||||
.field(self.ccx, abi::FAT_PTR_ADDR);
|
|
||||||
let data_cast = consts::ptrcast(data_ptr,
|
let data_cast = consts::ptrcast(data_ptr,
|
||||||
thin_ptr.llvm_type(self.ccx));
|
cast.scalar_pair_element_llvm_type(self.ccx, 0));
|
||||||
C_fat_ptr(self.ccx, data_cast, meta)
|
C_fat_ptr(self.ccx, data_cast, meta)
|
||||||
} else { // cast to thin-ptr
|
} else { // cast to thin-ptr
|
||||||
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
|
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
|
||||||
// pointer-cast of that pointer to desired pointer type.
|
// pointer-cast of that pointer to desired pointer type.
|
||||||
let llcast_ty = self.ccx.layout_of(cast_ty)
|
let llcast_ty = cast.immediate_llvm_type(self.ccx);
|
||||||
.immediate_llvm_type(self.ccx);
|
|
||||||
consts::ptrcast(data_ptr, llcast_ty)
|
consts::ptrcast(data_ptr, llcast_ty)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -18,7 +18,6 @@ use rustc_apfloat::{ieee, Float, Status, Round};
|
||||||
use rustc_const_math::MAX_F32_PLUS_HALF_ULP;
|
use rustc_const_math::MAX_F32_PLUS_HALF_ULP;
|
||||||
use std::{u128, i128};
|
use std::{u128, i128};
|
||||||
|
|
||||||
use abi;
|
|
||||||
use base;
|
use base;
|
||||||
use builder::Builder;
|
use builder::Builder;
|
||||||
use callee;
|
use callee;
|
||||||
|
@ -54,10 +53,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
bcx
|
bcx
|
||||||
}
|
}
|
||||||
|
|
||||||
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
|
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, _) => {
|
||||||
let cast_ty = self.monomorphize(&cast_ty);
|
// The destination necessarily contains a fat pointer, so if
|
||||||
|
// it's a scalar pair, it's a fat pointer or newtype thereof.
|
||||||
if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
|
if dest.layout.is_llvm_scalar_pair() {
|
||||||
// into-coerce of a thin pointer to a fat pointer - just
|
// into-coerce of a thin pointer to a fat pointer - just
|
||||||
// use the operand path.
|
// use the operand path.
|
||||||
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
|
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
|
||||||
|
@ -223,6 +222,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
operand.val
|
operand.val
|
||||||
}
|
}
|
||||||
mir::CastKind::Unsize => {
|
mir::CastKind::Unsize => {
|
||||||
|
assert!(cast.is_llvm_scalar_pair());
|
||||||
match operand.val {
|
match operand.val {
|
||||||
OperandValue::Pair(lldata, llextra) => {
|
OperandValue::Pair(lldata, llextra) => {
|
||||||
// unsize from a fat pointer - this is a
|
// unsize from a fat pointer - this is a
|
||||||
|
@ -248,12 +248,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mir::CastKind::Misc if common::type_is_fat_ptr(bcx.ccx, operand.layout.ty) => {
|
mir::CastKind::Misc if operand.layout.is_llvm_scalar_pair() => {
|
||||||
if let OperandValue::Pair(data_ptr, meta) = operand.val {
|
if let OperandValue::Pair(data_ptr, meta) = operand.val {
|
||||||
if common::type_is_fat_ptr(bcx.ccx, cast.ty) {
|
if cast.is_llvm_scalar_pair() {
|
||||||
let thin_ptr = cast.field(bcx.ccx, abi::FAT_PTR_ADDR);
|
|
||||||
let data_cast = bcx.pointercast(data_ptr,
|
let data_cast = bcx.pointercast(data_ptr,
|
||||||
thin_ptr.llvm_type(bcx.ccx));
|
cast.scalar_pair_element_llvm_type(bcx.ccx, 0));
|
||||||
OperandValue::Pair(data_cast, meta)
|
OperandValue::Pair(data_cast, meta)
|
||||||
} else { // cast to thin-ptr
|
} else { // cast to thin-ptr
|
||||||
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
|
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
|
||||||
|
@ -368,22 +367,21 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
||||||
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
|
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
|
||||||
let lhs = self.trans_operand(&bcx, lhs);
|
let lhs = self.trans_operand(&bcx, lhs);
|
||||||
let rhs = self.trans_operand(&bcx, rhs);
|
let rhs = self.trans_operand(&bcx, rhs);
|
||||||
let llresult = if common::type_is_fat_ptr(bcx.ccx, lhs.layout.ty) {
|
let llresult = match (lhs.val, rhs.val) {
|
||||||
match (lhs.val, rhs.val) {
|
(OperandValue::Pair(lhs_addr, lhs_extra),
|
||||||
(OperandValue::Pair(lhs_addr, lhs_extra),
|
OperandValue::Pair(rhs_addr, rhs_extra)) => {
|
||||||
OperandValue::Pair(rhs_addr, rhs_extra)) => {
|
self.trans_fat_ptr_binop(&bcx, op,
|
||||||
self.trans_fat_ptr_binop(&bcx, op,
|
lhs_addr, lhs_extra,
|
||||||
lhs_addr, lhs_extra,
|
rhs_addr, rhs_extra,
|
||||||
rhs_addr, rhs_extra,
|
lhs.layout.ty)
|
||||||
lhs.layout.ty)
|
|
||||||
}
|
|
||||||
_ => bug!()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
(OperandValue::Immediate(lhs_val),
|
||||||
self.trans_scalar_binop(&bcx, op,
|
OperandValue::Immediate(rhs_val)) => {
|
||||||
lhs.immediate(), rhs.immediate(),
|
self.trans_scalar_binop(&bcx, op, lhs_val, rhs_val, lhs.layout.ty)
|
||||||
lhs.layout.ty)
|
}
|
||||||
|
|
||||||
|
_ => bug!()
|
||||||
};
|
};
|
||||||
let operand = OperandRef {
|
let operand = OperandRef {
|
||||||
val: OperandValue::Immediate(llresult),
|
val: OperandValue::Immediate(llresult),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue