Skip to content

Commit 801a1a0

Browse files
committed
rustc_trans: remove type_is_fat_ptr and its uses.
1 parent fa67abd commit 801a1a0

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
@@ -674,10 +674,6 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
674674
operand.llval
675675
}
676676
mir::CastKind::Unsize => {
677-
// unsize targets other than to a fat pointer currently
678-
// can't be in constants.
679-
assert!(common::type_is_fat_ptr(self.ccx, cast_ty));
680-
681677
let pointee_ty = operand.ty.builtin_deref(true, ty::NoPreference)
682678
.expect("consts: unsizing got non-pointer type").ty;
683679
let (base, old_info) = if !self.ccx.shared().type_is_sized(pointee_ty) {
@@ -760,19 +756,18 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
760756
}
761757
}
762758
mir::CastKind::Misc => { // Casts from a fat-ptr.
763-
if common::type_is_fat_ptr(self.ccx, operand.ty) {
759+
let l = self.ccx.layout_of(operand.ty);
760+
let cast = self.ccx.layout_of(cast_ty);
761+
if l.is_llvm_scalar_pair() {
764762
let (data_ptr, meta) = operand.get_fat_ptr(self.ccx);
765-
if common::type_is_fat_ptr(self.ccx, cast_ty) {
766-
let thin_ptr = self.ccx.layout_of(cast_ty)
767-
.field(self.ccx, abi::FAT_PTR_ADDR);
763+
if cast.is_llvm_scalar_pair() {
768764
let data_cast = consts::ptrcast(data_ptr,
769-
thin_ptr.llvm_type(self.ccx));
765+
cast.scalar_pair_element_llvm_type(self.ccx, 0));
770766
C_fat_ptr(self.ccx, data_cast, meta)
771767
} else { // cast to thin-ptr
772768
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
773769
// pointer-cast of that pointer to desired pointer type.
774-
let llcast_ty = self.ccx.layout_of(cast_ty)
775-
.immediate_llvm_type(self.ccx);
770+
let llcast_ty = cast.immediate_llvm_type(self.ccx);
776771
consts::ptrcast(data_ptr, llcast_ty)
777772
}
778773
} else {

src/librustc_trans/mir/rvalue.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_apfloat::{ieee, Float, Status, Round};
1818
use rustc_const_math::MAX_F32_PLUS_HALF_ULP;
1919
use std::{u128, i128};
2020

21-
use abi;
2221
use base;
2322
use builder::Builder;
2423
use callee;
@@ -54,10 +53,10 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
5453
bcx
5554
}
5655

57-
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, cast_ty) => {
58-
let cast_ty = self.monomorphize(&cast_ty);
59-
60-
if common::type_is_fat_ptr(bcx.ccx, cast_ty) {
56+
mir::Rvalue::Cast(mir::CastKind::Unsize, ref source, _) => {
57+
// The destination necessarily contains a fat pointer, so if
58+
// it's a scalar pair, it's a fat pointer or newtype thereof.
59+
if dest.layout.is_llvm_scalar_pair() {
6160
// into-coerce of a thin pointer to a fat pointer - just
6261
// use the operand path.
6362
let (bcx, temp) = self.trans_rvalue_operand(bcx, rvalue);
@@ -223,6 +222,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
223222
operand.val
224223
}
225224
mir::CastKind::Unsize => {
225+
assert!(cast.is_llvm_scalar_pair());
226226
match operand.val {
227227
OperandValue::Pair(lldata, llextra) => {
228228
// unsize from a fat pointer - this is a
@@ -248,12 +248,11 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
248248
}
249249
}
250250
}
251-
mir::CastKind::Misc if common::type_is_fat_ptr(bcx.ccx, operand.layout.ty) => {
251+
mir::CastKind::Misc if operand.layout.is_llvm_scalar_pair() => {
252252
if let OperandValue::Pair(data_ptr, meta) = operand.val {
253-
if common::type_is_fat_ptr(bcx.ccx, cast.ty) {
254-
let thin_ptr = cast.field(bcx.ccx, abi::FAT_PTR_ADDR);
253+
if cast.is_llvm_scalar_pair() {
255254
let data_cast = bcx.pointercast(data_ptr,
256-
thin_ptr.llvm_type(bcx.ccx));
255+
cast.scalar_pair_element_llvm_type(bcx.ccx, 0));
257256
OperandValue::Pair(data_cast, meta)
258257
} else { // cast to thin-ptr
259258
// Cast of fat-ptr to thin-ptr is an extraction of data-ptr and
@@ -368,22 +367,21 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
368367
mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => {
369368
let lhs = self.trans_operand(&bcx, lhs);
370369
let rhs = self.trans_operand(&bcx, rhs);
371-
let llresult = if common::type_is_fat_ptr(bcx.ccx, lhs.layout.ty) {
372-
match (lhs.val, rhs.val) {
373-
(OperandValue::Pair(lhs_addr, lhs_extra),
374-
OperandValue::Pair(rhs_addr, rhs_extra)) => {
375-
self.trans_fat_ptr_binop(&bcx, op,
376-
lhs_addr, lhs_extra,
377-
rhs_addr, rhs_extra,
378-
lhs.layout.ty)
379-
}
380-
_ => bug!()
370+
let llresult = match (lhs.val, rhs.val) {
371+
(OperandValue::Pair(lhs_addr, lhs_extra),
372+
OperandValue::Pair(rhs_addr, rhs_extra)) => {
373+
self.trans_fat_ptr_binop(&bcx, op,
374+
lhs_addr, lhs_extra,
375+
rhs_addr, rhs_extra,
376+
lhs.layout.ty)
381377
}
382378

383-
} else {
384-
self.trans_scalar_binop(&bcx, op,
385-
lhs.immediate(), rhs.immediate(),
386-
lhs.layout.ty)
379+
(OperandValue::Immediate(lhs_val),
380+
OperandValue::Immediate(rhs_val)) => {
381+
self.trans_scalar_binop(&bcx, op, lhs_val, rhs_val, lhs.layout.ty)
382+
}
383+
384+
_ => bug!()
387385
};
388386
let operand = OperandRef {
389387
val: OperandValue::Immediate(llresult),

0 commit comments

Comments
 (0)