From c2f1e5d16455057f86c1e3051e77009d90b167fc Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 11 Oct 2016 23:46:22 -0400 Subject: [PATCH] Get rid of superfluous HashMap in LocalCrateContext. We only need the str slice type. --- src/librustc_trans/common.rs | 2 +- src/librustc_trans/context.rs | 16 ++++++++-------- src/librustc_trans/type_.rs | 25 ------------------------- src/librustc_trans/type_of.rs | 2 +- 4 files changed, 10 insertions(+), 35 deletions(-) diff --git a/src/librustc_trans/common.rs b/src/librustc_trans/common.rs index 464b261b08e..d238cf7bb45 100644 --- a/src/librustc_trans/common.rs +++ b/src/librustc_trans/common.rs @@ -815,7 +815,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef { let len = s.len(); let cs = consts::ptrcast(C_cstr(cx, s, false), Type::i8p(cx)); - C_named_struct(cx.tn().find_type("str_slice").unwrap(), &[cs, C_uint(cx, len)]) + C_named_struct(cx.str_slice_type(), &[cs, C_uint(cx, len)]) } pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef { diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 264d4940c17..3930bcbdd9a 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -25,7 +25,7 @@ use monomorphize::Instance; use partitioning::CodegenUnit; use trans_item::TransItem; -use type_::{Type, TypeNames}; +use type_::Type; use rustc::ty::subst::Substs; use rustc::ty::{self, Ty, TyCtxt}; use session::config::NoDebugInfo; @@ -87,7 +87,6 @@ pub struct LocalCrateContext<'tcx> { llmod: ModuleRef, llcx: ContextRef, previous_work_product: Option, - tn: TypeNames, // FIXME: This seems to be largely unused. codegen_unit: CodegenUnit<'tcx>, needs_unwind_cleanup_cache: RefCell, bool>>, fn_pointer_shims: RefCell, ValueRef>>, @@ -137,6 +136,7 @@ pub struct LocalCrateContext<'tcx> { type_hashcodes: RefCell, String>>, int_type: Type, opaque_vec_type: Type, + str_slice_type: Type, builder: BuilderRef_res, /// Holds the LLVM values for closure IDs. @@ -611,7 +611,6 @@ impl<'tcx> LocalCrateContext<'tcx> { llcx: llcx, previous_work_product: previous_work_product, codegen_unit: codegen_unit, - tn: TypeNames::new(), needs_unwind_cleanup_cache: RefCell::new(FxHashMap()), fn_pointer_shims: RefCell::new(FxHashMap()), drop_glues: RefCell::new(FxHashMap()), @@ -631,6 +630,7 @@ impl<'tcx> LocalCrateContext<'tcx> { type_hashcodes: RefCell::new(FxHashMap()), int_type: Type::from_ref(ptr::null_mut()), opaque_vec_type: Type::from_ref(ptr::null_mut()), + str_slice_type: Type::from_ref(ptr::null_mut()), builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)), closure_vals: RefCell::new(FxHashMap()), dbg_cx: dbg_cx, @@ -662,7 +662,7 @@ impl<'tcx> LocalCrateContext<'tcx> { local_ccx.int_type = int_type; local_ccx.opaque_vec_type = opaque_vec_type; - local_ccx.tn.associate_type("str_slice", &str_slice_ty); + local_ccx.str_slice_type = str_slice_ty; if shared.tcx.sess.count_llvm_insns() { base::init_insn_ctxt() @@ -778,10 +778,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) } } - pub fn tn<'a>(&'a self) -> &'a TypeNames { - &self.local().tn - } - pub fn export_map<'a>(&'a self) -> &'a ExportMap { &self.shared.export_map } @@ -885,6 +881,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.local().opaque_vec_type } + pub fn str_slice_type(&self) -> Type { + self.local().str_slice_type + } + pub fn closure_vals<'a>(&'a self) -> &'a RefCell, ValueRef>> { &self.local().closure_vals } diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index 2a6f79d3ed5..2b2776acab8 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -15,7 +15,6 @@ use llvm::{TypeRef, Bool, False, True, TypeKind}; use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128}; use context::CrateContext; -use util::nodemap::FxHashMap; use syntax::ast; use rustc::ty::layout; @@ -24,7 +23,6 @@ use std::ffi::CString; use std::fmt; use std::mem; use std::ptr; -use std::cell::RefCell; use libc::c_uint; @@ -321,26 +319,3 @@ impl Type { } } } - -/* Memory-managed object interface to type handles. */ - -pub struct TypeNames { - named_types: RefCell>, -} - -impl TypeNames { - pub fn new() -> TypeNames { - TypeNames { - named_types: RefCell::new(FxHashMap()) - } - } - - pub fn associate_type(&self, s: &str, t: &Type) { - assert!(self.named_types.borrow_mut().insert(s.to_string(), - t.to_ref()).is_none()); - } - - pub fn find_type(&self, s: &str) -> Option { - self.named_types.borrow().get(s).map(|x| Type::from_ref(*x)) - } -} diff --git a/src/librustc_trans/type_of.rs b/src/librustc_trans/type_of.rs index 132b0a910b9..dc794d5946a 100644 --- a/src/librustc_trans/type_of.rs +++ b/src/librustc_trans/type_of.rs @@ -238,7 +238,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) -> if let ty::TyStr = ty.sty { // This means we get a nicer name in the output (str is always // unsized). - cx.tn().find_type("str_slice").unwrap() + cx.str_slice_type() } else { let ptr_ty = in_memory_type_of(cx, ty).ptr_to(); let info_ty = unsized_info_ty(cx, ty);