From c96e3524e319e3654a5542a3b078c4f7537e94f6 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 11 Oct 2016 20:08:26 -0400 Subject: [PATCH 1/4] Don't use self type for cat_index on overloaded indexing. Fixes #20649. --- src/librustc/middle/mem_categorization.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index e3ed13e1e4017..fedf8c2ec7472 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -945,9 +945,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { let ref_ty = self.overloaded_method_return_ty(method_ty); base_cmt = self.cat_rvalue_node(elt.id(), elt.span(), ref_ty); - // FIXME(#20649) -- why are we using the `self_ty` as the element type...? - let self_ty = method_ty.fn_sig().input(0); - (self.tcx().no_late_bound_regions(&self_ty).unwrap(), + (ref_ty.builtin_deref(false, ty::NoPreference).unwrap().ty, ElementKind::OtherElement) } None => { From 6076fef6bd7af7fc34cb9adf8c2b3fa1a35c50bb Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 11 Oct 2016 20:42:26 -0400 Subject: [PATCH 2/4] ExprAssignable does not need the original Expr so let's just remove outdated FIXME. --- src/librustc/infer/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index ebafd206e26e2..8f4a12e03975b 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -184,7 +184,6 @@ pub enum TypeOrigin { MethodCompatCheck(Span), // Checking that this expression can be assigned where it needs to be - // FIXME(eddyb) #11161 is the original Expr required? ExprAssignable(Span), // Relating trait type parameters to those found in impl etc From 34f8e62c6bcf46aba647493bbc9e6da430d8b064 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 11 Oct 2016 22:10:54 -0400 Subject: [PATCH 3/4] Remove outdated FIXME: #10604 was fixed by #11717. --- src/librustc_trans/adt.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_trans/adt.rs b/src/librustc_trans/adt.rs index 4d3361c1873f0..d028dd7e7b5a0 100644 --- a/src/librustc_trans/adt.rs +++ b/src/librustc_trans/adt.rs @@ -245,8 +245,6 @@ fn generic_type_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, // So we start with the discriminant, pad it up to the alignment with // more of its own type, then use alignment-sized ints to get the rest // of the size. - // - // FIXME #10604: this breaks when vector types are present. let size = size.bytes(); let align = align.abi(); let discr_ty = Type::from_integer(cx, discr); From c2f1e5d16455057f86c1e3051e77009d90b167fc Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Tue, 11 Oct 2016 23:46:22 -0400 Subject: [PATCH 4/4] 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 464b261b08e05..d238cf7bb4582 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 264d4940c17f9..3930bcbdd9aea 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 2a6f79d3ed57a..2b2776acab869 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 132b0a910b9c1..dc794d5946a69 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);