From 0c01f6e14912edc35296aa4b7558a0b36790561b Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Wed, 17 Feb 2016 11:10:46 +0200 Subject: [PATCH] trans: Move type_of_fn_from_ty callers to type_of. --- src/librustc_trans/trans/callee.rs | 5 ++--- src/librustc_trans/trans/meth.rs | 3 +-- src/librustc_trans/trans/type_of.rs | 32 +++++++++-------------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/src/librustc_trans/trans/callee.rs b/src/librustc_trans/trans/callee.rs index af51cc914178..cf9dde9ef60e 100644 --- a/src/librustc_trans/trans/callee.rs +++ b/src/librustc_trans/trans/callee.rs @@ -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); diff --git a/src/librustc_trans/trans/meth.rs b/src/librustc_trans/trans/meth.rs index f0ed06f876ec..4b18ff05b188 100644 --- a/src/librustc_trans/trans/meth.rs +++ b/src/librustc_trans/trans/meth.rs @@ -341,12 +341,11 @@ fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, // Replace the self type (&Self or Box) 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 diff --git a/src/librustc_trans/trans/type_of.rs b/src/librustc_trans/trans/type_of.rs index 708aa9bdc9a8..8b4ed9b87980 100644 --- a/src/librustc_trans/trans/type_of.rs +++ b/src/librustc_trans/trans/type_of.rs @@ -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(..) => {