Skip to content

Commit 82092ca

Browse files
author
Ariel Ben-Yehuda
committed
fix specialization caching
1 parent 71d3270 commit 82092ca

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/librustc/traits/specialize/mod.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
150150
impl1_def_id: DefId,
151151
impl2_def_id: DefId) -> bool {
152152
debug!("specializes({:?}, {:?})", impl1_def_id, impl2_def_id);
153-
154-
if let Some(r) = tcx.specializes_cache.borrow().check(impl1_def_id, impl2_def_id) {
153+
if let Some(r) =
154+
tcx.global_tcx().specializes_cache.borrow().check(impl1_def_id, impl2_def_id) {
155155
return r;
156156
}
157157

@@ -203,7 +203,8 @@ pub fn specializes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
203203
fulfill_implication(&infcx, impl1_trait_ref, impl2_def_id).is_ok()
204204
});
205205

206-
tcx.specializes_cache.borrow_mut().insert(impl1_def_id, impl2_def_id, result);
206+
tcx.global_tcx().specializes_cache.borrow_mut()
207+
.insert(impl1_def_id, impl2_def_id, result);
207208
result
208209
}
209210

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;
@@ -391,6 +392,7 @@ define_maps! { <'tcx>
391392
pub associated_item: AssociatedItems(DefId) -> ty::AssociatedItem,
392393

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

395397
/// Maps a DefId of a type to a list of its inherent impls.
396398
/// 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
@@ -2136,14 +2136,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
21362136
}
21372137

21382138
pub fn trait_impl_polarity(self, id: DefId) -> hir::ImplPolarity {
2139-
if let Some(id) = self.hir.as_local_node_id(id) {
2140-
match self.hir.expect_item(id).node {
2141-
hir::ItemImpl(_, polarity, ..) => polarity,
2142-
ref item => bug!("trait_impl_polarity: {:?} not an impl", item)
2143-
}
2144-
} else {
2145-
self.sess.cstore.impl_polarity(id)
2146-
}
2139+
queries::impl_polarity::get(self, DUMMY_SP, id)
21472140
}
21482141

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

src/librustc_metadata/cstore_impl.rs

+1
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);

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
..*providers
103104
};
104105
}
@@ -1132,6 +1133,16 @@ fn impl_trait_ref<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11321133
}
11331134
}
11341135

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

0 commit comments

Comments
 (0)