Remove duplicated functions from trans::common.rs
This commit is contained in:
parent
7996f63ce4
commit
1df6f8321b
11 changed files with 22 additions and 62 deletions
|
|
@ -11,7 +11,7 @@
|
|||
use llvm::{self, ValueRef, AttributePlace};
|
||||
use base;
|
||||
use builder::Builder;
|
||||
use common::{instance_ty, ty_fn_sig, C_usize};
|
||||
use common::{ty_fn_sig, C_usize};
|
||||
use context::CrateContext;
|
||||
use cabi_x86;
|
||||
use cabi_x86_64;
|
||||
|
|
@ -649,7 +649,7 @@ pub struct FnType<'tcx> {
|
|||
impl<'a, 'tcx> FnType<'tcx> {
|
||||
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
|
||||
-> Self {
|
||||
let fn_ty = instance_ty(ccx.tcx(), &instance);
|
||||
let fn_ty = instance.ty(ccx.tcx());
|
||||
let sig = ty_fn_sig(ccx, fn_ty);
|
||||
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
|
||||
FnType::new(ccx, sig, &[])
|
||||
|
|
|
|||
|
|
@ -468,7 +468,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
|
|||
// release builds.
|
||||
info!("trans_instance({})", instance);
|
||||
|
||||
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let fn_ty = instance.ty(ccx.tcx());
|
||||
let sig = common::ty_fn_sig(ccx, fn_ty);
|
||||
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
assert!(!instance.substs.has_escaping_regions());
|
||||
assert!(!instance.substs.has_param_types());
|
||||
|
||||
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let fn_ty = instance.ty(ccx.tcx());
|
||||
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
|
||||
return llfn;
|
||||
}
|
||||
|
|
@ -96,7 +96,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
assert_eq!(common::val_ty(llfn), llptrty);
|
||||
debug!("get_fn: not casting pointer!");
|
||||
|
||||
if common::is_inline_instance(tcx, &instance) {
|
||||
if instance.def.is_inline(tcx) {
|
||||
attributes::inline(llfn, attributes::InlineAttr::Hint);
|
||||
}
|
||||
let attrs = instance.def.attrs(ccx.tcx());
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use llvm;
|
|||
use llvm::{ValueRef, ContextRef, TypeKind};
|
||||
use llvm::{True, False, Bool, OperandBundleDef};
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::DefPathData;
|
||||
use rustc::middle::lang_items::LangItem;
|
||||
use abi;
|
||||
use base;
|
||||
|
|
@ -29,7 +28,7 @@ use value::Value;
|
|||
use rustc::traits;
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::ty::layout::{HasDataLayout, LayoutOf};
|
||||
use rustc::ty::subst::{Kind, Substs};
|
||||
use rustc::ty::subst::Kind;
|
||||
use rustc::hir;
|
||||
|
||||
use libc::{c_uint, c_char};
|
||||
|
|
@ -430,38 +429,3 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_inline_instance<'a, 'tcx>(
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
instance: &ty::Instance<'tcx>
|
||||
) -> bool {
|
||||
let def_id = match instance.def {
|
||||
ty::InstanceDef::Item(def_id) => def_id,
|
||||
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
|
||||
_ => return true
|
||||
};
|
||||
match tcx.def_key(def_id).disambiguated_data.data {
|
||||
DefPathData::StructCtor |
|
||||
DefPathData::EnumVariant(..) |
|
||||
DefPathData::ClosureExpr => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
/// Given a DefId and some Substs, produces the monomorphic item type.
|
||||
pub fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
def_id: DefId,
|
||||
substs: &'tcx Substs<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let ty = tcx.type_of(def_id);
|
||||
tcx.trans_apply_param_substs(substs, &ty)
|
||||
}
|
||||
|
||||
/// Return the substituted type of an instance.
|
||||
pub fn instance_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
instance: &ty::Instance<'tcx>)
|
||||
-> Ty<'tcx>
|
||||
{
|
||||
let ty = instance.def.def_ty(tcx);
|
||||
tcx.trans_apply_param_substs(instance.substs, &ty)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use rustc::middle::const_val::ConstEvalErr;
|
|||
use debuginfo;
|
||||
use base;
|
||||
use trans_item::{MonoItem, MonoItemExt};
|
||||
use common::{self, CrateContext, val_ty};
|
||||
use common::{CrateContext, val_ty};
|
||||
use declare;
|
||||
use monomorphize::Instance;
|
||||
use type_::Type;
|
||||
|
|
@ -110,7 +110,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
|
|||
return g;
|
||||
}
|
||||
|
||||
let ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let ty = instance.ty(ccx.tcx());
|
||||
let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
|
||||
|
||||
let llty = ccx.layout_of(ty).llvm_type(ccx);
|
||||
|
|
@ -266,7 +266,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
};
|
||||
|
||||
let instance = Instance::mono(ccx.tcx(), def_id);
|
||||
let ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let ty = instance.ty(ccx.tcx());
|
||||
let llty = ccx.layout_of(ty).llvm_type(ccx);
|
||||
let g = if val_llty == llty {
|
||||
g
|
||||
|
|
|
|||
|
|
@ -27,10 +27,10 @@ use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
|
|||
use rustc::hir::def::CtorKind;
|
||||
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
|
||||
use rustc::ty::fold::TypeVisitor;
|
||||
use rustc::ty::subst::Substs;
|
||||
use rustc::ty::util::TypeIdHasher;
|
||||
use rustc::ich::Fingerprint;
|
||||
use common::{self, CrateContext};
|
||||
use rustc::ty::Instance;
|
||||
use common::CrateContext;
|
||||
use rustc::ty::{self, AdtKind, Ty};
|
||||
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
|
||||
use rustc::session::{Session, config};
|
||||
|
|
@ -1656,7 +1656,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
|
|||
};
|
||||
|
||||
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
|
||||
let variable_type = common::def_ty(cx.tcx(), node_def_id, Substs::empty());
|
||||
let variable_type = Instance::mono(cx.tcx(), node_def_id).ty(cx.tcx());
|
||||
let type_metadata = type_metadata(cx, variable_type, span);
|
||||
let var_name = tcx.item_name(node_def_id).to_string();
|
||||
let linkage_name = mangled_name_of_item(cx, node_def_id, "");
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ use rustc::hir::def_id::{DefId, CrateNum};
|
|||
use rustc::ty::subst::Substs;
|
||||
|
||||
use abi::Abi;
|
||||
use common::{self, CrateContext};
|
||||
use common::CrateContext;
|
||||
use builder::Builder;
|
||||
use monomorphize::Instance;
|
||||
use rustc::ty::{self, Ty};
|
||||
|
|
@ -428,7 +428,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
|
|||
// If the method does *not* belong to a trait, proceed
|
||||
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
|
||||
let impl_self_ty =
|
||||
common::def_ty(cx.tcx(), impl_def_id, instance.substs);
|
||||
Instance::new(impl_def_id, instance.substs).ty(cx.tcx());
|
||||
|
||||
// Only "class" methods are generally understood by LLVM,
|
||||
// so avoid methods on other types (e.g. `<*mut T>::null`).
|
||||
|
|
|
|||
|
|
@ -273,7 +273,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
args = &args[..1 + place.has_extra() as usize];
|
||||
let (drop_fn, fn_ty) = match ty.sty {
|
||||
ty::TyDynamic(..) => {
|
||||
let fn_ty = common::instance_ty(bcx.ccx.tcx(), &drop_fn);
|
||||
let fn_ty = drop_fn.ty(bcx.ccx.tcx());
|
||||
let sig = common::ty_fn_sig(bcx.ccx, fn_ty);
|
||||
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(&sig);
|
||||
let fn_ty = FnType::new_vtable(bcx.ccx, sig, &[]);
|
||||
|
|
@ -535,8 +535,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
|
|||
}).collect();
|
||||
|
||||
|
||||
let callee_ty = common::instance_ty(
|
||||
bcx.ccx.tcx(), instance.as_ref().unwrap());
|
||||
let callee_ty = instance.as_ref().unwrap().ty(bcx.ccx.tcx());
|
||||
trans_intrinsic_call(&bcx, callee_ty, &fn_ty, &args, dest,
|
||||
terminator.source_info.span);
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@
|
|||
//! inlining, even when they are not marked #[inline].
|
||||
|
||||
use rustc_mir::monomorphize::collector::InliningMap;
|
||||
use common;
|
||||
use rustc::dep_graph::WorkProductId;
|
||||
use rustc::hir::def_id::DefId;
|
||||
use rustc::hir::map::DefPathData;
|
||||
|
|
@ -115,6 +114,7 @@ use std::collections::hash_map::Entry;
|
|||
use syntax::ast::NodeId;
|
||||
use syntax::symbol::{Symbol, InternedString};
|
||||
use trans_item::{MonoItem, BaseMonoItemExt, MonoItemExt, InstantiationMode};
|
||||
use rustc::ty::Instance;
|
||||
|
||||
pub use rustc::mir::mono::CodegenUnit;
|
||||
|
||||
|
|
@ -575,7 +575,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
|||
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
|
||||
// This is a method within an inherent impl, find out what the
|
||||
// self-type is:
|
||||
let impl_self_ty = common::def_ty(tcx, impl_def_id, instance.substs);
|
||||
let impl_self_ty = Instance::new(impl_def_id, instance.substs).ty(tcx);
|
||||
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
|
||||
return Some(def_id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ use attributes;
|
|||
use base;
|
||||
use consts;
|
||||
use context::CrateContext;
|
||||
use common;
|
||||
use declare;
|
||||
use llvm;
|
||||
use monomorphize::Instance;
|
||||
|
|
@ -173,7 +172,7 @@ fn predefine_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
symbol_name: &str) {
|
||||
let def_id = ccx.tcx().hir.local_def_id(node_id);
|
||||
let instance = Instance::mono(ccx.tcx(), def_id);
|
||||
let ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let ty = instance.ty(ccx.tcx());
|
||||
let llty = ccx.layout_of(ty).llvm_type(ccx);
|
||||
|
||||
let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| {
|
||||
|
|
@ -198,7 +197,7 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
assert!(!instance.substs.needs_infer() &&
|
||||
!instance.substs.has_param_types());
|
||||
|
||||
let mono_ty = common::instance_ty(ccx.tcx(), &instance);
|
||||
let mono_ty = instance.ty(ccx.tcx());
|
||||
let attrs = instance.def.attrs(ccx.tcx());
|
||||
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
|
||||
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
|
||||
|
|
@ -224,7 +223,7 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||
}
|
||||
|
||||
debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
|
||||
if common::is_inline_instance(ccx.tcx(), &instance) {
|
||||
if instance.def.is_inline(ccx.tcx()) {
|
||||
attributes::inline(lldecl, attributes::InlineAttr::Hint);
|
||||
}
|
||||
attributes::from_fn_attrs(ccx, &attrs, lldecl);
|
||||
|
|
|
|||
|
|
@ -44,8 +44,6 @@ use rustc::hir::def_id::LOCAL_CRATE;
|
|||
use rustc::hir::map as hir_map;
|
||||
use rustc::util::nodemap::NodeSet;
|
||||
|
||||
use syntax::attr;
|
||||
|
||||
pub mod link;
|
||||
pub mod trans_crate;
|
||||
|
||||
|
|
@ -104,7 +102,7 @@ pub fn find_exported_symbols<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> NodeSet {
|
|||
(generics.parent_types == 0 && generics.types.is_empty()) &&
|
||||
// Functions marked with #[inline] are only ever translated
|
||||
// with "internal" linkage and are never exported.
|
||||
!common::requests_inline(tcx, &Instance::mono(tcx, def_id))
|
||||
!Instance::mono(tcx, def_id).def.requires_local(tcx)
|
||||
}
|
||||
|
||||
_ => false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue