]> git.lizzy.rs Git - rust.git/commitdiff
trans: Move type_of_fn_from_ty callers to type_of.
authorEduard Burtescu <edy.burt@gmail.com>
Wed, 17 Feb 2016 09:10:46 +0000 (11:10 +0200)
committerEduard Burtescu <edy.burt@gmail.com>
Wed, 9 Mar 2016 14:45:28 +0000 (16:45 +0200)
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/meth.rs
src/librustc_trans/trans/type_of.rs

index af51cc9141788319e981677359c83e23f2530f47..cf9dde9ef60ea13909f8c6c678efde1cbe7740d5 100644 (file)
@@ -466,7 +466,7 @@ fn is_named_tuple_constructor(tcx: &TyCtxt, def_id: DefId) -> bool {
             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 @@ fn is_named_tuple_constructor(tcx: &TyCtxt, def_id: DefId) -> bool {
     // 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);
index f0ed06f876ecfe034060d846613e09ab59fbc562..4b18ff05b188e69094fce5bfcb4e77f266acf248 100644 (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
index 708aa9bdc9a8428321ddba6a18a57d7a78b10c77..8b4ed9b87980d49a5bd89ec4d1d94162458bb274 100644 (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(..) => {