mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Get rid of superfluous HashMap in LocalCrateContext. We only need the str slice type.
This commit is contained in:
parent
34f8e62c6b
commit
c2f1e5d164
@ -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 {
|
||||
|
@ -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<WorkProduct>,
|
||||
tn: TypeNames, // FIXME: This seems to be largely unused.
|
||||
codegen_unit: CodegenUnit<'tcx>,
|
||||
needs_unwind_cleanup_cache: RefCell<FxHashMap<Ty<'tcx>, bool>>,
|
||||
fn_pointer_shims: RefCell<FxHashMap<Ty<'tcx>, ValueRef>>,
|
||||
@ -137,6 +136,7 @@ pub struct LocalCrateContext<'tcx> {
|
||||
type_hashcodes: RefCell<FxHashMap<Ty<'tcx>, 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<FxHashMap<Instance<'tcx>, ValueRef>> {
|
||||
&self.local().closure_vals
|
||||
}
|
||||
|
@ -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<FxHashMap<String, TypeRef>>,
|
||||
}
|
||||
|
||||
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<Type> {
|
||||
self.named_types.borrow().get(s).map(|x| Type::from_ref(*x))
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user