Skip to content

Commit b279c5b

Browse files
Add dependency tracking to trait cache in translation context
1 parent 6866f13 commit b279c5b

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/librustc_trans/trans/context.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use llvm;
1212
use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef};
13+
use rustc::dep_graph::{DepNode, DepTrackingMap, DepTrackingMapConfig};
1314
use middle::cstore::LinkMeta;
1415
use middle::def::ExportMap;
1516
use middle::def_id::DefId;
@@ -33,6 +34,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet};
3334

3435
use std::ffi::CString;
3536
use std::cell::{Cell, RefCell};
37+
use std::marker::PhantomData;
3638
use std::ptr;
3739
use std::rc::Rc;
3840
use syntax::ast;
@@ -161,8 +163,23 @@ pub struct LocalCrateContext<'tcx> {
161163
/// Depth of the current type-of computation - used to bail out
162164
type_of_depth: Cell<usize>,
163165

164-
trait_cache: RefCell<FnvHashMap<ty::PolyTraitRef<'tcx>,
165-
traits::Vtable<'tcx, ()>>>,
166+
trait_cache: RefCell<DepTrackingMap<TraitSelectionCache<'tcx>>>,
167+
}
168+
169+
// Implement DepTrackingMapConfig for `trait_cache`
170+
pub struct TraitSelectionCache<'tcx> {
171+
data: PhantomData<&'tcx ()>
172+
}
173+
174+
impl<'tcx> DepTrackingMapConfig for TraitSelectionCache<'tcx> {
175+
type Key = ty::PolyTraitRef<'tcx>;
176+
type Value = traits::Vtable<'tcx, ()>;
177+
fn to_dep_node(key: &ty::PolyTraitRef<'tcx>) -> DepNode {
178+
ty::tls::with(|tcx| {
179+
let lifted_key = tcx.lift(key).unwrap();
180+
lifted_key.to_poly_trait_predicate().dep_node()
181+
})
182+
}
166183
}
167184

168185
pub struct CrateContext<'a, 'tcx: 'a> {
@@ -478,7 +495,9 @@ impl<'tcx> LocalCrateContext<'tcx> {
478495
intrinsics: RefCell::new(FnvHashMap()),
479496
n_llvm_insns: Cell::new(0),
480497
type_of_depth: Cell::new(0),
481-
trait_cache: RefCell::new(FnvHashMap()),
498+
trait_cache: RefCell::new(DepTrackingMap::new(shared.tcx
499+
.dep_graph
500+
.clone())),
482501
};
483502

484503
local_ccx.int_type = Type::int(&local_ccx.dummy_ccx(shared));
@@ -752,8 +771,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
752771
self.local.n_llvm_insns.set(self.local.n_llvm_insns.get() + 1);
753772
}
754773

755-
pub fn trait_cache(&self) -> &RefCell<FnvHashMap<ty::PolyTraitRef<'tcx>,
756-
traits::Vtable<'tcx, ()>>> {
774+
pub fn trait_cache(&self) -> &RefCell<DepTrackingMap<TraitSelectionCache<'tcx>>> {
757775
&self.local.trait_cache
758776
}
759777

0 commit comments

Comments
 (0)