Skip to content

Commit

Permalink
remove the destructors table
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed Sep 26, 2015
1 parent 346088b commit f9b703e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 40 deletions.
14 changes: 9 additions & 5 deletions src/librustc/middle/reachable.rs
Expand Up @@ -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);
}
}
}
})
}
}

Expand Down
4 changes: 0 additions & 4 deletions src/librustc/middle/ty/context.rs
Expand Up @@ -245,9 +245,6 @@ pub struct ctxt<'tcx> {
/// True if the variance has been computed yet; false otherwise.
pub variance_computed: Cell<bool>,

/// A method will be in this list if and only if it is a destructor.
pub destructors: RefCell<DefIdSet>,

/// 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.
Expand Down Expand Up @@ -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()),
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/middle/ty/mod.rs
Expand Up @@ -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<AdtDef<'tcx>> {
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(
Expand Down
19 changes: 9 additions & 10 deletions src/librustc_lint/builtin.rs
Expand Up @@ -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, _) |
Expand All @@ -1247,6 +1246,6 @@ impl LateLintPass for DropWithReprExtern {
}
_ => {}
}
}
})
}
}
8 changes: 1 addition & 7 deletions src/librustc_typeck/check/method/confirm.rs
Expand Up @@ -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(..) => {}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -431,17 +431,19 @@ 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(()) => {
assert!(ccx.tcx.sess.has_errors());
}
}
}
}
});

ccx.tcx.sess.abort_if_errors();
}
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_typeck/coherence/mod.rs
Expand Up @@ -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();
Expand Down Expand Up @@ -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 }
Expand All @@ -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.
Expand Down

0 comments on commit f9b703e

Please sign in to comment.