Skip to content

Commit

Permalink
add a cache to impl_polarity
Browse files Browse the repository at this point in the history
this is another one of these things that looks *much* worse on valgrind.
  • Loading branch information
Ariel Ben-Yehuda authored and arielb1 committed Apr 22, 2017
1 parent 81af6fb commit a0f145b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/librustc/middle/cstore.rs
Expand Up @@ -195,7 +195,6 @@ pub trait CrateStore {
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;

// impl info
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;

// trait/impl-item info
Expand Down Expand Up @@ -330,7 +329,6 @@ impl CrateStore for DummyCrateStore {
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }

// impl info
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }

// trait/impl-item info
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/maps.rs
Expand Up @@ -10,6 +10,7 @@

use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
use hir;
use middle::const_val;
use middle::privacy::AccessLevels;
use mir;
Expand Down Expand Up @@ -394,6 +395,7 @@ define_maps! { <'tcx>
pub associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,

pub impl_trait_ref: ItemSignature(DefId) -> Option<ty::TraitRef<'tcx>>,
pub impl_polarity: ItemSignature(DefId) -> hir::ImplPolarity,

/// Maps a DefId of a type to a list of its inherent impls.
/// Contains implementations of methods that are inherent to a type.
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/ty/mod.rs
Expand Up @@ -2149,14 +2149,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
}

pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity {
if let Some(id) = self.hir.as_local_node_id(id) {
match self.hir.expect_item(id).node {
hir::ItemImpl(_, polarity, ..) => polarity,
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
}
} else {
self.sess.cstore.impl_polarity(id)
}
queries::impl_polarity::get(self, DUMMY_SP, id)
}

pub fn trait_relevant_for_never(self, did: DefId) -> bool {
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -89,6 +89,7 @@ provide! { <'tcx> tcx, def_id, cdata
}
associated_item => { cdata.get_associated_item(def_id.index) }
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
coerce_unsized_info => {
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
Expand Down Expand Up @@ -177,12 +178,6 @@ impl CrateStore for cstore::CStore {
result
}

fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity
{
self.dep_graph.read(DepNode::MetaData(def));
self.get_crate_data(def.krate).get_impl_polarity(def.index)
}

fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
self.dep_graph.read(DepNode::MetaData(impl_def));
self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index)
Expand Down
11 changes: 11 additions & 0 deletions src/librustc_typeck/collect.rs
Expand Up @@ -99,6 +99,7 @@ pub fn provide(providers: &mut Providers) {
trait_def,
adt_def,
impl_trait_ref,
impl_polarity,
is_foreign_item,
..*providers
};
Expand Down Expand Up @@ -1133,6 +1134,16 @@ fn impl_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
}

fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> hir::ImplPolarity {
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
match tcx.hir.expect_item(node_id).node {
hir::ItemImpl(_, polarity, ..) => polarity,
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
}
}

// Is it marked with ?Sized
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
ast_bounds: &[hir::TyParamBound],
Expand Down

0 comments on commit a0f145b

Please sign in to comment.