From f9b703e7ab10383236ff687870c186220019f442 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Sat, 26 Sep 2015 22:25:49 +0300 Subject: [PATCH] remove the destructors table --- src/librustc/middle/reachable.rs | 14 +++++++++----- src/librustc/middle/ty/context.rs | 4 ---- src/librustc/middle/ty/mod.rs | 5 ----- src/librustc_lint/builtin.rs | 19 +++++++++---------- src/librustc_typeck/check/method/confirm.rs | 8 +------- src/librustc_typeck/check/mod.rs | 10 ++++++---- src/librustc_typeck/coherence/mod.rs | 7 ++----- 7 files changed, 27 insertions(+), 40 deletions(-) diff --git a/src/librustc/middle/reachable.rs b/src/librustc/middle/reachable.rs index 3fb3d575f93c6..017c8f1e42bec 100644 --- a/src/librustc/middle/reachable.rs +++ b/src/librustc/middle/reachable.rs @@ -348,13 +348,17 @@ impl<'a, 'tcx> ReachableContext<'a, 'tcx> { // this properly would result in the necessity of computing *type* // reachability, which might result in a compile time loss. fn mark_destructors_reachable(&mut self) { - for adt in self.tcx.adt_defs() { - if let Some(destructor_def_id) = adt.destructor() { - if destructor_def_id.is_local() { - self.reachable_symbols.insert(destructor_def_id.node); + let drop_trait = match self.tcx.lang_items.drop_trait() { + Some(id) => self.tcx.lookup_trait_def(id), None => { return } + }; + drop_trait.for_each_impl(self.tcx, |drop_impl| { + for destructor in &self.tcx.impl_items.borrow()[&drop_impl] { + let destructor_did = destructor.def_id(); + if destructor_did.is_local() { + self.reachable_symbols.insert(destructor_did.node); } } - } + }) } } diff --git a/src/librustc/middle/ty/context.rs b/src/librustc/middle/ty/context.rs index 31e4765aaaa60..f32e86e276c71 100644 --- a/src/librustc/middle/ty/context.rs +++ b/src/librustc/middle/ty/context.rs @@ -245,9 +245,6 @@ pub struct ctxt<'tcx> { /// True if the variance has been computed yet; false otherwise. pub variance_computed: Cell, - /// A method will be in this list if and only if it is a destructor. - pub destructors: RefCell, - /// Maps a DefId of a type to a list of its inherent impls. /// Contains implementations of methods that are inherent to a type. /// Methods in these implementations don't need to be exported. @@ -475,7 +472,6 @@ impl<'tcx> ctxt<'tcx> { normalized_cache: RefCell::new(FnvHashMap()), lang_items: lang_items, provided_method_sources: RefCell::new(DefIdMap()), - destructors: RefCell::new(DefIdSet()), inherent_impls: RefCell::new(DefIdMap()), impl_items: RefCell::new(DefIdMap()), used_unsafe: RefCell::new(NodeSet()), diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index a726b4f5b6673..eb93c58f38c55 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -2329,11 +2329,6 @@ impl<'tcx> ctxt<'tcx> { self.lookup_adt_def_master(did) } - /// Return the list of all interned ADT definitions - pub fn adt_defs(&self) -> Vec> { - self.adt_defs.borrow().values().cloned().collect() - } - /// Given the did of an item, returns its full set of predicates. pub fn lookup_predicates(&self, did: DefId) -> GenericPredicates<'tcx> { lookup_locally_or_in_crate_store( diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 111913adb8aa8..dbd6286e42606 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -1213,15 +1213,14 @@ impl LintPass for DropWithReprExtern { impl LateLintPass for DropWithReprExtern { fn check_crate(&mut self, ctx: &LateContext, _: &hir::Crate) { - for dtor_did in ctx.tcx.destructors.borrow().iter() { - let (drop_impl_did, dtor_self_type) = - if dtor_did.is_local() { - let impl_did = ctx.tcx.map.get_parent_did(dtor_did.node); - let ty = ctx.tcx.lookup_item_type(impl_did).ty; - (impl_did, ty) - } else { - continue; - }; + let drop_trait = match ctx.tcx.lang_items.drop_trait() { + Some(id) => ctx.tcx.lookup_trait_def(id), None => { return } + }; + drop_trait.for_each_impl(ctx.tcx, |drop_impl_did| { + if !drop_impl_did.is_local() { + return; + } + let dtor_self_type = ctx.tcx.lookup_item_type(drop_impl_did).ty; match dtor_self_type.sty { ty::TyEnum(self_type_def, _) | @@ -1247,6 +1246,6 @@ impl LateLintPass for DropWithReprExtern { } _ => {} } - } + }) } } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index abdcbf099a57a..b0e81803ba72f 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -620,13 +620,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> { ty::TraitContainer(trait_def_id) => { callee::check_legal_trait_for_method_call(self.fcx.ccx, self.span, trait_def_id) } - ty::ImplContainer(..) => { - // Since `drop` is a trait method, we expect that any - // potential calls to it will wind up in the other - // arm. But just to be sure, check that the method id - // does not appear in the list of destructors. - assert!(!self.tcx().destructors.borrow().contains(&pick.item.def_id())); - } + ty::ImplContainer(..) => {} } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index dec2e49272b48..66a3790e52d44 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -431,9 +431,11 @@ pub fn check_item_bodies(ccx: &CrateCtxt) { } pub fn check_drop_impls(ccx: &CrateCtxt) { - for drop_method_did in ccx.tcx.destructors.borrow().iter() { - if drop_method_did.is_local() { - let drop_impl_did = ccx.tcx.map.get_parent_did(drop_method_did.node); + let drop_trait = match ccx.tcx.lang_items.drop_trait() { + Some(id) => ccx.tcx.lookup_trait_def(id), None => { return } + }; + drop_trait.for_each_impl(ccx.tcx, |drop_impl_did| { + if drop_impl_did.is_local() { match dropck::check_drop_impl(ccx.tcx, drop_impl_did) { Ok(()) => {} Err(()) => { @@ -441,7 +443,7 @@ pub fn check_drop_impls(ccx: &CrateCtxt) { } } } - } + }); ccx.tcx.sess.abort_if_errors(); } diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 228f1f0fe445b..0c152a419d25f 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -126,7 +126,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { // Populate the table of destructors. It might seem a bit strange to // do this here, but it's actually the most convenient place, since // the coherence tables contain the trait -> type mappings. - self.populate_destructor_table(); + self.populate_destructors(); // Check to make sure implementations of `Copy` are legal. self.check_implementations_of_copy(); @@ -286,7 +286,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { // Destructors // - fn populate_destructor_table(&self) { + fn populate_destructors(&self) { let tcx = self.crate_context.tcx; let drop_trait = match tcx.lang_items.drop_trait() { Some(id) => id, None => { return } @@ -309,9 +309,6 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { ty::TyEnum(type_def, _) | ty::TyStruct(type_def, _) => { type_def.set_destructor(method_def_id.def_id()); - tcx.destructors - .borrow_mut() - .insert(method_def_id.def_id()); } _ => { // Destructors only work on nominal types.