Skip to content

Commit a0f145b

Browse files
Ariel Ben-Yehudaarielb1
Ariel Ben-Yehuda
authored andcommitted
add a cache to impl_polarity
this is another one of these things that looks *much* worse on valgrind.
1 parent 81af6fb commit a0f145b

File tree

5 files changed

+15
-16
lines changed

5 files changed

+15
-16
lines changed

src/librustc/middle/cstore.rs

-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ pub trait CrateStore {
195195
fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
196196

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

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

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

336334
// trait/impl-item info

src/librustc/ty/maps.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use dep_graph::{DepGraph, DepNode, DepTrackingMap, DepTrackingMapConfig};
1212
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
13+
use hir;
1314
use middle::const_val;
1415
use middle::privacy::AccessLevels;
1516
use mir;
@@ -394,6 +395,7 @@ define_maps! { <'tcx>
394395
pub associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
395396

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

398400
/// Maps a DefId of a type to a list of its inherent impls.
399401
/// Contains implementations of methods that are inherent to a type.

src/librustc/ty/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -2149,14 +2149,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21492149
}
21502150

21512151
pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity {
2152-
if let Some(id) = self.hir.as_local_node_id(id) {
2153-
match self.hir.expect_item(id).node {
2154-
hir::ItemImpl(_, polarity, ..) => polarity,
2155-
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
2156-
}
2157-
} else {
2158-
self.sess.cstore.impl_polarity(id)
2159-
}
2152+
queries::impl_polarity::get(self, DUMMY_SP, id)
21602153
}
21612154

21622155
pub fn trait_relevant_for_never(self, did: DefId) -> bool {

src/librustc_metadata/cstore_impl.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ provide! { <'tcx> tcx, def_id, cdata
8989
}
9090
associated_item => { cdata.get_associated_item(def_id.index) }
9191
impl_trait_ref => { cdata.get_impl_trait(def_id.index, tcx) }
92+
impl_polarity => { cdata.get_impl_polarity(def_id.index) }
9293
coerce_unsized_info => {
9394
cdata.get_coerce_unsized_info(def_id.index).unwrap_or_else(|| {
9495
bug!("coerce_unsized_info: `{:?}` is missing its info", def_id);
@@ -177,12 +178,6 @@ impl CrateStore for cstore::CStore {
177178
result
178179
}
179180

180-
fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity
181-
{
182-
self.dep_graph.read(DepNode::MetaData(def));
183-
self.get_crate_data(def.krate).get_impl_polarity(def.index)
184-
}
185-
186181
fn impl_parent(&self, impl_def: DefId) -> Option<DefId> {
187182
self.dep_graph.read(DepNode::MetaData(impl_def));
188183
self.get_crate_data(impl_def.krate).get_parent_impl(impl_def.index)

src/librustc_typeck/collect.rs

+11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub fn provide(providers: &mut Providers) {
9999
trait_def,
100100
adt_def,
101101
impl_trait_ref,
102+
impl_polarity,
102103
is_foreign_item,
103104
..*providers
104105
};
@@ -1133,6 +1134,16 @@ fn impl_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11331134
}
11341135
}
11351136

1137+
fn impl_polarity<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1138+
def_id: DefId)
1139+
-> hir::ImplPolarity {
1140+
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
1141+
match tcx.hir.expect_item(node_id).node {
1142+
hir::ItemImpl(_, polarity, ..) => polarity,
1143+
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
1144+
}
1145+
}
1146+
11361147
// Is it marked with ?Sized
11371148
fn is_unsized<'gcx: 'tcx, 'tcx>(astconv: &AstConv<'gcx, 'tcx>,
11381149
ast_bounds: &[hir::TyParamBound],

0 commit comments

Comments
 (0)