diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-10-10 22:04:13 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-11-19 02:43:56 +0200 |
| commit | 801a1a0fc10706ac908e29d66a598ff121a923cd (patch) | |
| tree | 2881b861d552a202bdef91ec95a0a7187ba9f879 | |
| parent | fa67abd12707c34a2def10247c22c336f82cd2c2 (diff) | |
| download | rust-801a1a0fc10706ac908e29d66a598ff121a923cd.tar.gz rust-801a1a0fc10706ac908e29d66a598ff121a923cd.zip | |
rustc_trans: remove type_is_fat_ptr and its uses.
| -rw-r--r-- | src/librustc_trans/common.rs | 13 | ||||
| -rw-r--r-- | src/librustc_trans/mir/constant.rs | 17 | ||||
| -rw-r--r-- | src/librustc_trans/mir/rvalue.rs | 44 |
3 files changed, 27 insertions, 47 deletions
diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 8a2c1ed2dc2..7bd8a0c81ee 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -41,19 +41,6 @@ use syntax_pos::{Span, DUMMY_SP}; 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 { ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All)) } diff --git a/src/librustc_trans/mir/constant.rs b/src/librustc_trans/mir/constant.rs index 54907cb747c..0423a684399 100644 --- a/src/librustc_trans/mir/constant.rs +++ b/src/librustc_trans/mir/constant.rs @@ -674,10 +674,6 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> { operand.llval } 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) .expect("consts: unsizing got non-pointer type").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. - 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); - if common::type_is_fat_ptr(self.ccx, cast_ty) { - let thin_ptr = self.ccx.layout_of(cast_ty) - .field(self.ccx, abi::FAT_PTR_ADDR); + if cast.is_llvm_scalar_pair() { 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) } else { // cast to thin-ptr // Cast of fat-ptr to thin-ptr is an extraction of data-ptr and // pointer-cast of that pointer to desired pointer type. - let llcast_ty = self.ccx.layout_of(cast_ty) - .immediate_llvm_type(self.ccx); + let llcast_ty = cast.immediate_llvm_type(self.ccx); consts::ptrcast(data_ptr, llcast_ty) } } else { diff --git a/src/librustc_trans/mir/rvalue.rs b/src/librustc_trans/mir/rvalue.rs index bf44434cafe..4781425f491 100644 --- a/src/librustc_trans/mir/rvalue.rs +++ b/src/librustc_trans/mir/rvalue.rs @@ -18,7 +18,6 @@ use rustc_apfloat::{ieee, Float, Status, Round}; use rustc_const_math::MAX_F32_PLUS_HALF_ULP; use std::{u128, i128}; -use abi; use base; use builder::Builder; use callee; @@ -54,10 +53,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { bcx } - mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => { - let cast_ty = self.monomorphize(&cast_ty); - - if common::type_is_fat_ptr(bcx.ccx, cast_ty) { + mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, _) => { + // The destination necessarily contains a fat pointer, so if + // it's a scalar pair, it's a fat pointer or newtype thereof. + if dest.layout.is_llvm_scalar_pair() { // into-coerce of a thin pointer to a fat pointer - just // use the operand path. let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue); @@ -223,6 +222,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> { operand.val } mir::CastKind::Unsize => { + assert!(cast.is_llvm_scalar_pair()); match operand.val { OperandValue::Pair(lldata, llextra) => { // 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 common::type_is_fat_ptr(bcx.ccx, cast.ty) { - let thin_ptr = cast.field(bcx.ccx, abi::FAT_PTR_ADDR); + if cast.is_llvm_scalar_pair() { 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) } else { // cast to thin-ptr // 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) => { let lhs = self.trans_operand(&bcx, lhs); let rhs = self.trans_operand(&bcx, rhs); - let llresult = if common::type_is_fat_ptr(bcx.ccx, lhs.layout.ty) { - match (lhs.val, rhs.val) { - (OperandValue::Pair(lhs_addr, lhs_extra), - OperandValue::Pair(rhs_addr, rhs_extra)) => { - self.trans_fat_ptr_binop(&bcx, op, - lhs_addr, lhs_extra, - rhs_addr, rhs_extra, - lhs.layout.ty) - } - _ => bug!() + let llresult = match (lhs.val, rhs.val) { + (OperandValue::Pair(lhs_addr, lhs_extra), + OperandValue::Pair(rhs_addr, rhs_extra)) => { + self.trans_fat_ptr_binop(&bcx, op, + lhs_addr, lhs_extra, + rhs_addr, rhs_extra, + lhs.layout.ty) } - } else { - self.trans_scalar_binop(&bcx, op, - lhs.immediate(), rhs.immediate(), - lhs.layout.ty) + (OperandValue::Immediate(lhs_val), + OperandValue::Immediate(rhs_val)) => { + self.trans_scalar_binop(&bcx, op, lhs_val, rhs_val, lhs.layout.ty) + } + + _ => bug!() }; let operand = OperandRef { val: OperandValue::Immediate(llresult), |
