Skip to content

Commit c2f1e5d

Browse files
committed
Get rid of superfluous HashMap in LocalCrateContext. We only need the str slice type.
1 parent 34f8e62 commit c2f1e5d

File tree

4 files changed

+10
-35
lines changed

4 files changed

+10
-35
lines changed

src/librustc_trans/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
815815
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
816816
let len = s.len();
817817
let cs = consts::ptrcast(C_cstr(cx, s, false), Type::i8p(cx));
818-
C_named_struct(cx.tn().find_type("str_slice").unwrap(), &[cs, C_uint(cx, len)])
818+
C_named_struct(cx.str_slice_type(), &[cs, C_uint(cx, len)])
819819
}
820820

821821
pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef {

src/librustc_trans/context.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use monomorphize::Instance;
2525

2626
use partitioning::CodegenUnit;
2727
use trans_item::TransItem;
28-
use type_::{Type, TypeNames};
28+
use type_::Type;
2929
use rustc::ty::subst::Substs;
3030
use rustc::ty::{self, Ty, TyCtxt};
3131
use session::config::NoDebugInfo;
@@ -87,7 +87,6 @@ pub struct LocalCrateContext<'tcx> {
8787
llmod: ModuleRef,
8888
llcx: ContextRef,
8989
previous_work_product: Option<WorkProduct>,
90-
tn: TypeNames, // FIXME: This seems to be largely unused.
9190
codegen_unit: CodegenUnit<'tcx>,
9291
needs_unwind_cleanup_cache: RefCell<FxHashMap<Ty<'tcx>, bool>>,
9392
fn_pointer_shims: RefCell<FxHashMap<Ty<'tcx>, ValueRef>>,
@@ -137,6 +136,7 @@ pub struct LocalCrateContext<'tcx> {
137136
type_hashcodes: RefCell<FxHashMap<Ty<'tcx>, String>>,
138137
int_type: Type,
139138
opaque_vec_type: Type,
139+
str_slice_type: Type,
140140
builder: BuilderRef_res,
141141

142142
/// Holds the LLVM values for closure IDs.
@@ -611,7 +611,6 @@ impl<'tcx> LocalCrateContext<'tcx> {
611611
llcx: llcx,
612612
previous_work_product: previous_work_product,
613613
codegen_unit: codegen_unit,
614-
tn: TypeNames::new(),
615614
needs_unwind_cleanup_cache: RefCell::new(FxHashMap()),
616615
fn_pointer_shims: RefCell::new(FxHashMap()),
617616
drop_glues: RefCell::new(FxHashMap()),
@@ -631,6 +630,7 @@ impl<'tcx> LocalCrateContext<'tcx> {
631630
type_hashcodes: RefCell::new(FxHashMap()),
632631
int_type: Type::from_ref(ptr::null_mut()),
633632
opaque_vec_type: Type::from_ref(ptr::null_mut()),
633+
str_slice_type: Type::from_ref(ptr::null_mut()),
634634
builder: BuilderRef_res(llvm::LLVMCreateBuilderInContext(llcx)),
635635
closure_vals: RefCell::new(FxHashMap()),
636636
dbg_cx: dbg_cx,
@@ -662,7 +662,7 @@ impl<'tcx> LocalCrateContext<'tcx> {
662662

663663
local_ccx.int_type = int_type;
664664
local_ccx.opaque_vec_type = opaque_vec_type;
665-
local_ccx.tn.associate_type("str_slice", &str_slice_ty);
665+
local_ccx.str_slice_type = str_slice_ty;
666666

667667
if shared.tcx.sess.count_llvm_insns() {
668668
base::init_insn_ctxt()
@@ -778,10 +778,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
778778
unsafe { llvm::LLVMRustGetModuleDataLayout(self.llmod()) }
779779
}
780780

781-
pub fn tn<'a>(&'a self) -> &'a TypeNames {
782-
&self.local().tn
783-
}
784-
785781
pub fn export_map<'a>(&'a self) -> &'a ExportMap {
786782
&self.shared.export_map
787783
}
@@ -885,6 +881,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
885881
self.local().opaque_vec_type
886882
}
887883

884+
pub fn str_slice_type(&self) -> Type {
885+
self.local().str_slice_type
886+
}
887+
888888
pub fn closure_vals<'a>(&'a self) -> &'a RefCell<FxHashMap<Instance<'tcx>, ValueRef>> {
889889
&self.local().closure_vals
890890
}

src/librustc_trans/type_.rs

-25
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use llvm::{TypeRef, Bool, False, True, TypeKind};
1515
use llvm::{Float, Double, X86_FP80, PPC_FP128, FP128};
1616

1717
use context::CrateContext;
18-
use util::nodemap::FxHashMap;
1918

2019
use syntax::ast;
2120
use rustc::ty::layout;
@@ -24,7 +23,6 @@ use std::ffi::CString;
2423
use std::fmt;
2524
use std::mem;
2625
use std::ptr;
27-
use std::cell::RefCell;
2826

2927
use libc::c_uint;
3028

@@ -321,26 +319,3 @@ impl Type {
321319
}
322320
}
323321
}
324-
325-
/* Memory-managed object interface to type handles. */
326-
327-
pub struct TypeNames {
328-
named_types: RefCell<FxHashMap<String, TypeRef>>,
329-
}
330-
331-
impl TypeNames {
332-
pub fn new() -> TypeNames {
333-
TypeNames {
334-
named_types: RefCell::new(FxHashMap())
335-
}
336-
}
337-
338-
pub fn associate_type(&self, s: &str, t: &Type) {
339-
assert!(self.named_types.borrow_mut().insert(s.to_string(),
340-
t.to_ref()).is_none());
341-
}
342-
343-
pub fn find_type(&self, s: &str) -> Option<Type> {
344-
self.named_types.borrow().get(s).map(|x| Type::from_ref(*x))
345-
}
346-
}

src/librustc_trans/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn in_memory_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>) ->
238238
if let ty::TyStr = ty.sty {
239239
// This means we get a nicer name in the output (str is always
240240
// unsized).
241-
cx.tn().find_type("str_slice").unwrap()
241+
cx.str_slice_type()
242242
} else {
243243
let ptr_ty = in_memory_type_of(cx, ty).ptr_to();
244244
let info_ty = unsized_info_ty(cx, ty);

0 commit comments

Comments
 (0)