trans: Move type_of_fn_from_ty callers to type_of.

This commit is contained in:
Eduard Burtescu 2016-02-17 11:10:46 +02:00
parent e4e1242769
commit 0c01f6e149
3 changed files with 13 additions and 27 deletions

View file

@ -466,7 +466,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
let ref_ty = monomorphize::apply_param_substs(tcx,
param_substs,
&ref_ty);
let llptrty = type_of::type_of_fn_from_ty(ccx, ref_ty).ptr_to();
let llptrty = type_of::type_of(ccx, ref_ty);
if llptrty != common::val_ty(val) {
let val = consts::ptrcast(val, llptrty);
return Datum::new(val, ref_ty, Rvalue::new(ByValue));
@ -513,8 +513,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
// This can occur on either a crate-local or crate-external
// reference. It also occurs when testing libcore and in some
// other weird situations. Annoying.
let llty = type_of::type_of_fn_from_ty(ccx, fn_type);
let llptrty = llty.ptr_to();
let llptrty = type_of::type_of(ccx, fn_type);
if common::val_ty(val) != llptrty {
debug!("trans_fn_ref_with_substs(): casting pointer!");
val = consts::ptrcast(val, llptrty);

View file

@ -341,12 +341,11 @@ fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
// Replace the self type (&Self or Box<Self>) with an opaque pointer.
let mptr = Load(bcx, GEPi(bcx, llvtable, &[vtable_index + VTABLE_OFFSET]));
let llcallee_ty = type_of_fn_from_ty(ccx, opaque_fn_ty);
Callee {
bcx: bcx,
data: TraitItem(MethodData {
llfn: PointerCast(bcx, mptr, llcallee_ty.ptr_to()),
llfn: PointerCast(bcx, mptr, type_of(ccx, opaque_fn_ty)),
llself: PointerCast(bcx, llself, Type::i8p(ccx)),
}),
ty: opaque_fn_ty

View file

@ -150,26 +150,6 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
Type::func(&atys[..], &lloutputtype)
}
// Given a function type and a count of ty params, construct an llvm type
pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type {
match fty.sty {
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
// FIXME(#19925) once fn item types are
// zero-sized, we'll need to do something here
if f.abi == Abi::Rust || f.abi == Abi::RustCall {
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
type_of_rust_fn(cx, None, &sig, f.abi)
} else {
foreign::lltype_for_foreign_fn(cx, fty)
}
}
_ => {
cx.sess().bug("type_of_fn_from_ty given non-closure, non-bare-fn")
}
}
}
// A "sizing type" is an LLVM type, the size and alignment of which are
// guaranteed to be equivalent to what you would get out of `type_of()`. It's
// useful because:
@ -415,8 +395,16 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
ty::TySlice(ty) => in_memory_type_of(cx, ty),
ty::TyStr | ty::TyTrait(..) => Type::i8(cx),
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
type_of_fn_from_ty(cx, t).ptr_to()
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
// FIXME(#19925) once fn item types are
// zero-sized, we'll need to do something here
if f.abi == Abi::Rust || f.abi == Abi::RustCall {
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
type_of_rust_fn(cx, None, &sig, f.abi).ptr_to()
} else {
foreign::lltype_for_foreign_fn(cx, t).ptr_to()
}
}
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
ty::TyTuple(..) => {