1010
1111use llvm;
1212use llvm:: { ContextRef , ModuleRef , ValueRef , BuilderRef } ;
13+ use rustc:: dep_graph:: { DepNode , DepTrackingMap , DepTrackingMapConfig } ;
1314use middle:: cstore:: LinkMeta ;
1415use middle:: def:: ExportMap ;
1516use middle:: def_id:: DefId ;
@@ -33,6 +34,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet};
3334
3435use std:: ffi:: CString ;
3536use std:: cell:: { Cell , RefCell } ;
37+ use std:: marker:: PhantomData ;
3638use std:: ptr;
3739use std:: rc:: Rc ;
3840use 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
168185pub 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