10
10
11
11
use llvm;
12
12
use llvm:: { ContextRef , ModuleRef , ValueRef , BuilderRef } ;
13
+ use rustc:: dep_graph:: { DepNode , DepTrackingMap , DepTrackingMapConfig } ;
13
14
use middle:: cstore:: LinkMeta ;
14
15
use middle:: def:: ExportMap ;
15
16
use middle:: def_id:: DefId ;
@@ -33,6 +34,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet};
33
34
34
35
use std:: ffi:: CString ;
35
36
use std:: cell:: { Cell , RefCell } ;
37
+ use std:: marker:: PhantomData ;
36
38
use std:: ptr;
37
39
use std:: rc:: Rc ;
38
40
use syntax:: ast;
@@ -161,8 +163,23 @@ pub struct LocalCrateContext<'tcx> {
161
163
/// Depth of the current type-of computation - used to bail out
162
164
type_of_depth : Cell < usize > ,
163
165
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
+ }
166
183
}
167
184
168
185
pub struct CrateContext < ' a , ' tcx : ' a > {
@@ -478,7 +495,9 @@ impl<'tcx> LocalCrateContext<'tcx> {
478
495
intrinsics : RefCell :: new ( FnvHashMap ( ) ) ,
479
496
n_llvm_insns : Cell :: new ( 0 ) ,
480
497
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 ( ) ) ) ,
482
501
} ;
483
502
484
503
local_ccx. int_type = Type :: int ( & local_ccx. dummy_ccx ( shared) ) ;
@@ -752,8 +771,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
752
771
self . local . n_llvm_insns . set ( self . local . n_llvm_insns . get ( ) + 1 ) ;
753
772
}
754
773
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 > > > {
757
775
& self . local . trait_cache
758
776
}
759
777
0 commit comments