Skip to content

Commit 0c01f6e

Browse files
committed
trans: Move type_of_fn_from_ty callers to type_of.
1 parent e4e1242 commit 0c01f6e

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

src/librustc_trans/trans/callee.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
466466
let ref_ty = monomorphize::apply_param_substs(tcx,
467467
param_substs,
468468
&ref_ty);
469-
let llptrty = type_of::type_of_fn_from_ty(ccx, ref_ty).ptr_to();
469+
let llptrty = type_of::type_of(ccx, ref_ty);
470470
if llptrty != common::val_ty(val) {
471471
let val = consts::ptrcast(val, llptrty);
472472
return Datum::new(val, ref_ty, Rvalue::new(ByValue));
@@ -513,8 +513,7 @@ pub fn trans_fn_ref_with_substs<'a, 'tcx>(
513513
// This can occur on either a crate-local or crate-external
514514
// reference. It also occurs when testing libcore and in some
515515
// other weird situations. Annoying.
516-
let llty = type_of::type_of_fn_from_ty(ccx, fn_type);
517-
let llptrty = llty.ptr_to();
516+
let llptrty = type_of::type_of(ccx, fn_type);
518517
if common::val_ty(val) != llptrty {
519518
debug!("trans_fn_ref_with_substs(): casting pointer!");
520519
val = consts::ptrcast(val, llptrty);

src/librustc_trans/trans/meth.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,11 @@ fn trans_trait_callee_from_llval<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
341341

342342
// Replace the self type (&Self or Box<Self>) with an opaque pointer.
343343
let mptr = Load(bcx, GEPi(bcx, llvtable, &[vtable_index + VTABLE_OFFSET]));
344-
let llcallee_ty = type_of_fn_from_ty(ccx, opaque_fn_ty);
345344

346345
Callee {
347346
bcx: bcx,
348347
data: TraitItem(MethodData {
349-
llfn: PointerCast(bcx, mptr, llcallee_ty.ptr_to()),
348+
llfn: PointerCast(bcx, mptr, type_of(ccx, opaque_fn_ty)),
350349
llself: PointerCast(bcx, llself, Type::i8p(ccx)),
351350
}),
352351
ty: opaque_fn_ty

src/librustc_trans/trans/type_of.rs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,6 @@ pub fn type_of_rust_fn<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
150150
Type::func(&atys[..], &lloutputtype)
151151
}
152152

153-
// Given a function type and a count of ty params, construct an llvm type
154-
pub fn type_of_fn_from_ty<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, fty: Ty<'tcx>) -> Type {
155-
match fty.sty {
156-
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
157-
// FIXME(#19925) once fn item types are
158-
// zero-sized, we'll need to do something here
159-
if f.abi == Abi::Rust || f.abi == Abi::RustCall {
160-
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
161-
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
162-
type_of_rust_fn(cx, None, &sig, f.abi)
163-
} else {
164-
foreign::lltype_for_foreign_fn(cx, fty)
165-
}
166-
}
167-
_ => {
168-
cx.sess().bug("type_of_fn_from_ty given non-closure, non-bare-fn")
169-
}
170-
}
171-
}
172-
173153
// A "sizing type" is an LLVM type, the size and alignment of which are
174154
// guaranteed to be equivalent to what you would get out of `type_of()`. It's
175155
// useful because:
@@ -415,8 +395,16 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
415395
ty::TySlice(ty) => in_memory_type_of(cx, ty),
416396
ty::TyStr | ty::TyTrait(..) => Type::i8(cx),
417397

418-
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
419-
type_of_fn_from_ty(cx, t).ptr_to()
398+
ty::TyFnDef(_, _, ref f) | ty::TyFnPtr(ref f) => {
399+
// FIXME(#19925) once fn item types are
400+
// zero-sized, we'll need to do something here
401+
if f.abi == Abi::Rust || f.abi == Abi::RustCall {
402+
let sig = cx.tcx().erase_late_bound_regions(&f.sig);
403+
let sig = infer::normalize_associated_type(cx.tcx(), &sig);
404+
type_of_rust_fn(cx, None, &sig, f.abi).ptr_to()
405+
} else {
406+
foreign::lltype_for_foreign_fn(cx, t).ptr_to()
407+
}
420408
}
421409
ty::TyTuple(ref tys) if tys.is_empty() => Type::nil(cx),
422410
ty::TyTuple(..) => {

0 commit comments

Comments
 (0)