Skip to content

Commit 1df6f83

Browse files
MaikKleinarielb1
authored andcommitted
Remove duplicated functions from trans::common.rs
1 parent 7996f63 commit 1df6f83

File tree

11 files changed

+22
-62
lines changed

11 files changed

+22
-62
lines changed

src/librustc_trans/abi.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use llvm::{self, ValueRef, AttributePlace};
1212
use base;
1313
use builder::Builder;
14-
use common::{instance_ty, ty_fn_sig, C_usize};
14+
use common::{ty_fn_sig, C_usize};
1515
use context::CrateContext;
1616
use cabi_x86;
1717
use cabi_x86_64;
@@ -649,7 +649,7 @@ pub struct FnType<'tcx> {
649649
impl<'a, 'tcx> FnType<'tcx> {
650650
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
651651
-> Self {
652-
let fn_ty = instance_ty(ccx.tcx(), &instance);
652+
let fn_ty = instance.ty(ccx.tcx());
653653
let sig = ty_fn_sig(ccx, fn_ty);
654654
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
655655
FnType::new(ccx, sig, &[])

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
468468
// release builds.
469469
info!("trans_instance({})", instance);
470470

471-
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
471+
let fn_ty = instance.ty(ccx.tcx());
472472
let sig = common::ty_fn_sig(ccx, fn_ty);
473473
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
474474

src/librustc_trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
4848
assert!(!instance.substs.has_escaping_regions());
4949
assert!(!instance.substs.has_param_types());
5050

51-
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
51+
let fn_ty = instance.ty(ccx.tcx());
5252
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
5353
return llfn;
5454
}
@@ -96,7 +96,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
9696
assert_eq!(common::val_ty(llfn), llptrty);
9797
debug!("get_fn: not casting pointer!");
9898

99-
if common::is_inline_instance(tcx, &instance) {
99+
if instance.def.is_inline(tcx) {
100100
attributes::inline(llfn, attributes::InlineAttr::Hint);
101101
}
102102
let attrs = instance.def.attrs(ccx.tcx());

src/librustc_trans/common.rs

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use llvm;
1616
use llvm::{ValueRef, ContextRef, TypeKind};
1717
use llvm::{True, False, Bool, OperandBundleDef};
1818
use rustc::hir::def_id::DefId;
19-
use rustc::hir::map::DefPathData;
2019
use rustc::middle::lang_items::LangItem;
2120
use abi;
2221
use base;
@@ -29,7 +28,7 @@ use value::Value;
2928
use rustc::traits;
3029
use rustc::ty::{self, Ty, TyCtxt};
3130
use rustc::ty::layout::{HasDataLayout, LayoutOf};
32-
use rustc::ty::subst::{Kind, Substs};
31+
use rustc::ty::subst::Kind;
3332
use rustc::hir;
3433

3534
use libc::{c_uint, c_char};
@@ -430,38 +429,3 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
430429
}
431430
}
432431

433-
pub fn is_inline_instance<'a, 'tcx>(
434-
tcx: TyCtxt<'a, 'tcx, 'tcx>,
435-
instance: &ty::Instance<'tcx>
436-
) -> bool {
437-
let def_id = match instance.def {
438-
ty::InstanceDef::Item(def_id) => def_id,
439-
ty::InstanceDef::DropGlue(_, Some(_)) => return false,
440-
_ => return true
441-
};
442-
match tcx.def_key(def_id).disambiguated_data.data {
443-
DefPathData::StructCtor |
444-
DefPathData::EnumVariant(..) |
445-
DefPathData::ClosureExpr => true,
446-
_ => false
447-
}
448-
}
449-
450-
/// Given a DefId and some Substs, produces the monomorphic item type.
451-
pub fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
452-
def_id: DefId,
453-
substs: &'tcx Substs<'tcx>)
454-
-> Ty<'tcx>
455-
{
456-
let ty = tcx.type_of(def_id);
457-
tcx.trans_apply_param_substs(substs, &ty)
458-
}
459-
460-
/// Return the substituted type of an instance.
461-
pub fn instance_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
462-
instance: &ty::Instance<'tcx>)
463-
-> Ty<'tcx>
464-
{
465-
let ty = instance.def.def_ty(tcx);
466-
tcx.trans_apply_param_substs(instance.substs, &ty)
467-
}

src/librustc_trans/consts.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::middle::const_val::ConstEvalErr;
1717
use debuginfo;
1818
use base;
1919
use trans_item::{MonoItem, MonoItemExt};
20-
use common::{self, CrateContext, val_ty};
20+
use common::{CrateContext, val_ty};
2121
use declare;
2222
use monomorphize::Instance;
2323
use type_::Type;
@@ -110,7 +110,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
110110
return g;
111111
}
112112

113-
let ty = common::instance_ty(ccx.tcx(), &instance);
113+
let ty = instance.ty(ccx.tcx());
114114
let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
115115

116116
let llty = ccx.layout_of(ty).llvm_type(ccx);
@@ -266,7 +266,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
266266
};
267267

268268
let instance = Instance::mono(ccx.tcx(), def_id);
269-
let ty = common::instance_ty(ccx.tcx(), &instance);
269+
let ty = instance.ty(ccx.tcx());
270270
let llty = ccx.layout_of(ty).llvm_type(ccx);
271271
let g = if val_llty == llty {
272272
g

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ use llvm::debuginfo::{DIType, DIFile, DIScope, DIDescriptor,
2727
use rustc::hir::def::CtorKind;
2828
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
2929
use rustc::ty::fold::TypeVisitor;
30-
use rustc::ty::subst::Substs;
3130
use rustc::ty::util::TypeIdHasher;
3231
use rustc::ich::Fingerprint;
33-
use common::{self, CrateContext};
32+
use rustc::ty::Instance;
33+
use common::CrateContext;
3434
use rustc::ty::{self, AdtKind, Ty};
3535
use rustc::ty::layout::{self, Align, LayoutOf, Size, TyLayout};
3636
use rustc::session::{Session, config};
@@ -1656,7 +1656,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
16561656
};
16571657

16581658
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
1659-
let variable_type = common::def_ty(cx.tcx(), node_def_id, Substs::empty());
1659+
let variable_type = Instance::mono(cx.tcx(), node_def_id).ty(cx.tcx());
16601660
let type_metadata = type_metadata(cx, variable_type, span);
16611661
let var_name = tcx.item_name(node_def_id).to_string();
16621662
let linkage_name = mangled_name_of_item(cx, node_def_id, "");

src/librustc_trans/debuginfo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc::hir::def_id::{DefId, CrateNum};
2727
use rustc::ty::subst::Substs;
2828

2929
use abi::Abi;
30-
use common::{self, CrateContext};
30+
use common::CrateContext;
3131
use builder::Builder;
3232
use monomorphize::Instance;
3333
use rustc::ty::{self, Ty};
@@ -428,7 +428,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
428428
// If the method does *not* belong to a trait, proceed
429429
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
430430
let impl_self_ty =
431-
common::def_ty(cx.tcx(), impl_def_id, instance.substs);
431+
Instance::new(impl_def_id, instance.substs).ty(cx.tcx());
432432

433433
// Only "class" methods are generally understood by LLVM,
434434
// so avoid methods on other types (e.g. `<*mut T>::null`).

src/librustc_trans/mir/block.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
273273
args = &args[..1 + place.has_extra() as usize];
274274
let (drop_fn, fn_ty) = match ty.sty {
275275
ty::TyDynamic(..) => {
276-
let fn_ty = common::instance_ty(bcx.ccx.tcx(), &drop_fn);
276+
let fn_ty = drop_fn.ty(bcx.ccx.tcx());
277277
let sig = common::ty_fn_sig(bcx.ccx, fn_ty);
278278
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(&sig);
279279
let fn_ty = FnType::new_vtable(bcx.ccx, sig, &[]);
@@ -535,8 +535,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
535535
}).collect();
536536

537537

538-
let callee_ty = common::instance_ty(
539-
bcx.ccx.tcx(), instance.as_ref().unwrap());
538+
let callee_ty = instance.as_ref().unwrap().ty(bcx.ccx.tcx());
540539
trans_intrinsic_call(&bcx, callee_ty, &fn_ty, &args, dest,
541540
terminator.source_info.span);
542541

src/librustc_trans/partitioning.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@
103103
//! inlining, even when they are not marked #[inline].
104104
105105
use rustc_mir::monomorphize::collector::InliningMap;
106-
use common;
107106
use rustc::dep_graph::WorkProductId;
108107
use rustc::hir::def_id::DefId;
109108
use rustc::hir::map::DefPathData;
@@ -115,6 +114,7 @@ use std::collections::hash_map::Entry;
115114
use syntax::ast::NodeId;
116115
use syntax::symbol::{Symbol, InternedString};
117116
use trans_item::{MonoItem, BaseMonoItemExt, MonoItemExt, InstantiationMode};
117+
use rustc::ty::Instance;
118118

119119
pub use rustc::mir::mono::CodegenUnit;
120120

@@ -575,7 +575,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
575575
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
576576
// This is a method within an inherent impl, find out what the
577577
// self-type is:
578-
let impl_self_ty = common::def_ty(tcx, impl_def_id, instance.substs);
578+
let impl_self_ty = Instance::new(impl_def_id, instance.substs).ty(tcx);
579579
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
580580
return Some(def_id);
581581
}

src/librustc_trans/trans_item.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use attributes;
1919
use base;
2020
use consts;
2121
use context::CrateContext;
22-
use common;
2322
use declare;
2423
use llvm;
2524
use monomorphize::Instance;
@@ -173,7 +172,7 @@ fn predefine_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
173172
symbol_name: &str) {
174173
let def_id = ccx.tcx().hir.local_def_id(node_id);
175174
let instance = Instance::mono(ccx.tcx(), def_id);
176-
let ty = common::instance_ty(ccx.tcx(), &instance);
175+
let ty = instance.ty(ccx.tcx());
177176
let llty = ccx.layout_of(ty).llvm_type(ccx);
178177

179178
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>,
198197
assert!(!instance.substs.needs_infer() &&
199198
!instance.substs.has_param_types());
200199

201-
let mono_ty = common::instance_ty(ccx.tcx(), &instance);
200+
let mono_ty = instance.ty(ccx.tcx());
202201
let attrs = instance.def.attrs(ccx.tcx());
203202
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
204203
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
@@ -224,7 +223,7 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
224223
}
225224

226225
debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
227-
if common::is_inline_instance(ccx.tcx(), &instance) {
226+
if instance.def.is_inline(ccx.tcx()) {
228227
attributes::inline(lldecl, attributes::InlineAttr::Hint);
229228
}
230229
attributes::from_fn_attrs(ccx, &attrs, lldecl);

src/librustc_trans_utils/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ use rustc::hir::def_id::LOCAL_CRATE;
4444
use rustc::hir::map as hir_map;
4545
use rustc::util::nodemap::NodeSet;
4646

47-
use syntax::attr;
48-
4947
pub mod link;
5048
pub mod trans_crate;
5149

@@ -104,7 +102,7 @@ pub fn find_exported_symbols<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> NodeSet {
104102
(generics.parent_types == 0 && generics.types.is_empty()) &&
105103
// Functions marked with #[inline] are only ever translated
106104
// with "internal" linkage and are never exported.
107-
!common::requests_inline(tcx, &Instance::mono(tcx, def_id))
105+
!Instance::mono(tcx, def_id).def.requires_local(tcx)
108106
}
109107

110108
_ => false

0 commit comments

Comments
 (0)