Skip to content

Commit 3da46d5

Browse files
committed
rustc_trans: remove type_is_fat_ptr and its uses.
1 parent a80c1cc commit 3da46d5

File tree

3 files changed

+27
-47
lines changed

3 files changed

+27
-47
lines changed

src/librustc_trans/common.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,6 @@ use syntax_pos::{Span, DUMMY_SP};
4141

4242
pub use context::{CrateContext, SharedCrateContext};
4343

44-
pub fn type_is_fat_ptr<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -> bool {
45-
match ty.sty {
46-
ty::TyRef(_, ty::TypeAndMut { ty, .. }) |
47-
ty::TyRawPtr(ty::TypeAndMut { ty, .. }) => {
48-
!ccx.shared().type_is_sized(ty)
49-
}
50-
ty::TyAdt(def, _) if def.is_box() => {
51-
!ccx.shared().type_is_sized(ty.boxed_ty())
52-
}
53-
_ => false
54-
}
55-
}
56-
5744
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
5845
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
5946
}

src/librustc_trans/mir/constant.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -673,10 +673,6 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
673673
operand.llval
674674
}
675675
mir::CastKind::Unsize => {
676-
// unsize targets other than to a fat pointer currently
677-
// can't be in constants.
678-
assert!(common::type_is_fat_ptr(self.ccx, cast_ty));
679-
680676
let pointee_ty = operand.ty.builtin_deref(true, ty::NoPreference)
681677
.expect("consts: unsizing got non-pointer type").ty;
682678
let (base, old_info) = if !self.ccx.shared().type_is_sized(pointee_ty) {
@@ -761,19 +757,18 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
761757
}
762758
}
763759
mir::CastKind::Misc => { // Casts from a fat-ptr.
764-
if common::type_is_fat_ptr(self.ccx, operand.ty) {
760+
let l = self.ccx.layout_of(operand.ty);
761+
let cast = self.ccx.layout_of(cast_ty);
762+
if l.is_llvm_scalar_pair() {
765763
let (data_ptr, meta) = operand.get_fat_ptr(self.ccx);
766-
if common::type_is_fat_ptr(self.ccx, cast_ty) {
767-
let thin_ptr = self.ccx.layout_of(cast_ty)
768-
.field(self.ccx, abi::FAT_PTR_ADDR);
764+
if cast.is_llvm_scalar_pair() {
769765
let data_cast = consts::ptrcast(data_ptr,
770-
thin_ptr.llvm_type(self.ccx));
766+
cast.scalar_pair_element_llvm_type(self.ccx, 0));
771767
C_fat_ptr(self.ccx, data_cast, meta)
772768
} else { // cast to thin-ptr
773769
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
774770
// pointer-cast of that pointer to desired pointer type.
775-
let llcast_ty = self.ccx.layout_of(cast_ty)
776-
.immediate_llvm_type(self.ccx);
771+
let llcast_ty = cast.immediate_llvm_type(self.ccx);
777772
consts::ptrcast(data_ptr, llcast_ty)
778773
}
779774
} else {

src/librustc_trans/mir/rvalue.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::ty::layout::{self, LayoutOf};
1515
use rustc::mir;
1616
use rustc::middle::lang_items::ExchangeMallocFnLangItem;
1717

18-
use abi;
1918
use base;
2019
use builder::Builder;
2120
use callee;
@@ -49,10 +48,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
4948
bcx
5049
}
5150

52-
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
53-
let cast_ty = self.monomorphize(&cast_ty);
54-
55-
if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
51+
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, _) => {
52+
// The destination necessarily contains a fat pointer, so if
53+
// it's a scalar pair, it's a fat pointer or newtype thereof.
54+
if dest.layout.is_llvm_scalar_pair() {
5655
// into-coerce of a thin pointer to a fat pointer - just
5756
// use the operand path.
5857
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
@@ -218,6 +217,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
218217
operand.val
219218
}
220219
mir::CastKind::Unsize => {
220+
assert!(cast.is_llvm_scalar_pair());
221221
match operand.val {
222222
OperandValue::Pair(lldata, llextra) => {
223223
// unsize from a fat pointer - this is a
@@ -243,12 +243,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
243243
}
244244
}
245245
}
246-
mir::CastKind::Misc if common::type_is_fat_ptr(bcx.ccx, operand.layout.ty) => {
246+
mir::CastKind::Misc if operand.layout.is_llvm_scalar_pair() => {
247247
if let OperandValue::Pair(data_ptr, meta) = operand.val {
248-
if common::type_is_fat_ptr(bcx.ccx, cast.ty) {
249-
let thin_ptr = cast.field(bcx.ccx, abi::FAT_PTR_ADDR);
248+
if cast.is_llvm_scalar_pair() {
250249
let data_cast = bcx.pointercast(data_ptr,
251-
thin_ptr.llvm_type(bcx.ccx));
250+
cast.scalar_pair_element_llvm_type(bcx.ccx, 0));
252251
OperandValue::Pair(data_cast, meta)
253252
} else { // cast to thin-ptr
254253
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
@@ -365,22 +364,21 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
365364
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
366365
let lhs = self.trans_operand(&bcx, lhs);
367366
let rhs = self.trans_operand(&bcx, rhs);
368-
let llresult = if common::type_is_fat_ptr(bcx.ccx, lhs.layout.ty) {
369-
match (lhs.val, rhs.val) {
370-
(OperandValue::Pair(lhs_addr, lhs_extra),
371-
OperandValue::Pair(rhs_addr, rhs_extra)) => {
372-
self.trans_fat_ptr_binop(&bcx, op,
373-
lhs_addr, lhs_extra,
374-
rhs_addr, rhs_extra,
375-
lhs.layout.ty)
376-
}
377-
_ => bug!()
367+
let llresult = match (lhs.val, rhs.val) {
368+
(OperandValue::Pair(lhs_addr, lhs_extra),
369+
OperandValue::Pair(rhs_addr, rhs_extra)) => {
370+
self.trans_fat_ptr_binop(&bcx, op,
371+
lhs_addr, lhs_extra,
372+
rhs_addr, rhs_extra,
373+
lhs.layout.ty)
378374
}
379375

380-
} else {
381-
self.trans_scalar_binop(&bcx, op,
382-
lhs.immediate(), rhs.immediate(),
383-
lhs.layout.ty)
376+
(OperandValue::Immediate(lhs_val),
377+
OperandValue::Immediate(rhs_val)) => {
378+
self.trans_scalar_binop(&bcx, op, lhs_val, rhs_val, lhs.layout.ty)
379+
}
380+
381+
_ => bug!()
384382
};
385383
let operand = OperandRef {
386384
val: OperandValue::Immediate(llresult),

0 commit comments

Comments
 (0)