@@ -30,7 +30,6 @@ use super::{VtableImplData, VtableObjectData, VtableBuiltinData,
3030 VtableClosureData , VtableDefaultImplData , VtableFnPointerData } ;
3131use super :: util;
3232
33- use dep_graph:: { DepNodeIndex , DepKind } ;
3433use hir:: def_id:: DefId ;
3534use infer;
3635use infer:: { InferCtxt , InferOk , TypeFreshener } ;
@@ -106,7 +105,7 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> {
106105#[ derive( Clone ) ]
107106pub struct SelectionCache < ' tcx > {
108107 hashmap : RefCell < FxHashMap < ty:: TraitRef < ' tcx > ,
109- WithDepNode < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > > > ,
108+ SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > > ,
110109}
111110
112111/// The selection process begins by considering all impls, where
@@ -370,7 +369,7 @@ impl EvaluationResult {
370369
371370#[ derive( Clone ) ]
372371pub struct EvaluationCache < ' tcx > {
373- hashmap : RefCell < FxHashMap < ty:: PolyTraitRef < ' tcx > , WithDepNode < EvaluationResult > > >
372+ hashmap : RefCell < FxHashMap < ty:: PolyTraitRef < ' tcx > , EvaluationResult > >
374373}
375374
376375impl < ' cx , ' gcx , ' tcx > SelectionContext < ' cx , ' gcx , ' tcx > {
@@ -467,6 +466,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
467466 assert ! ( !obligation. predicate. has_escaping_regions( ) ) ;
468467
469468 let tcx = self . tcx ( ) ;
469+ let dep_node = obligation. predicate . dep_node ( tcx) ;
470+ let _task = tcx. dep_graph . in_task ( dep_node) ;
470471
471472 let stack = self . push_stack ( TraitObligationStackList :: empty ( ) , obligation) ;
472473 let ret = match self . candidate_from_obligation ( & stack) ? {
@@ -709,12 +710,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
709710 return result;
710711 }
711712
712- let ( result, dep_node ) = self . in_task ( |this| this . evaluate_stack ( & stack) ) ;
713+ let result = self . evaluate_stack ( & stack) ;
713714
714715 debug ! ( "CACHE MISS: EVAL({:?})={:?}" ,
715716 fresh_trait_ref,
716717 result) ;
717- self . insert_evaluation_cache ( obligation. param_env , fresh_trait_ref, dep_node , result) ;
718+ self . insert_evaluation_cache ( obligation. param_env , fresh_trait_ref, result) ;
718719
719720 result
720721 }
@@ -869,23 +870,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
869870 trait_ref : ty:: PolyTraitRef < ' tcx > )
870871 -> Option < EvaluationResult >
871872 {
872- let tcx = self . tcx ( ) ;
873873 if self . can_use_global_caches ( param_env) {
874- let cache = tcx. evaluation_cache . hashmap . borrow ( ) ;
874+ let cache = self . tcx ( ) . evaluation_cache . hashmap . borrow ( ) ;
875875 if let Some ( cached) = cache. get ( & trait_ref) {
876- return Some ( cached. get ( tcx) ) ;
876+ let dep_node = trait_ref
877+ . to_poly_trait_predicate ( )
878+ . dep_node ( self . tcx ( ) ) ;
879+ self . tcx ( ) . hir . dep_graph . read ( dep_node) ;
880+ return Some ( cached. clone ( ) ) ;
877881 }
878882 }
879- self . infcx . evaluation_cache . hashmap
880- . borrow ( )
881- . get ( & trait_ref)
882- . map ( |v| v. get ( tcx) )
883+ self . infcx . evaluation_cache . hashmap . borrow ( ) . get ( & trait_ref) . cloned ( )
883884 }
884885
885886 fn insert_evaluation_cache ( & mut self ,
886887 param_env : ty:: ParamEnv < ' tcx > ,
887888 trait_ref : ty:: PolyTraitRef < ' tcx > ,
888- dep_node : DepNodeIndex ,
889889 result : EvaluationResult )
890890 {
891891 // Avoid caching results that depend on more than just the trait-ref:
@@ -902,14 +902,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
902902 if self . can_use_global_caches ( param_env) {
903903 let mut cache = self . tcx ( ) . evaluation_cache . hashmap . borrow_mut ( ) ;
904904 if let Some ( trait_ref) = self . tcx ( ) . lift_to_global ( & trait_ref) {
905- cache. insert ( trait_ref, WithDepNode :: new ( dep_node , result) ) ;
905+ cache. insert ( trait_ref, result) ;
906906 return ;
907907 }
908908 }
909909
910- self . infcx . evaluation_cache . hashmap
911- . borrow_mut ( )
912- . insert ( trait_ref, WithDepNode :: new ( dep_node, result) ) ;
910+ self . infcx . evaluation_cache . hashmap . borrow_mut ( ) . insert ( trait_ref, result) ;
913911 }
914912
915913 ///////////////////////////////////////////////////////////////////////////
@@ -951,32 +949,19 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
951949 }
952950
953951 // If no match, compute result and insert into cache.
954- let ( candidate, dep_node) = self . in_task ( |this| {
955- this. candidate_from_obligation_no_cache ( stack)
956- } ) ;
952+ let candidate = self . candidate_from_obligation_no_cache ( stack) ;
957953
958954 if self . should_update_candidate_cache ( & cache_fresh_trait_pred, & candidate) {
959955 debug ! ( "CACHE MISS: SELECT({:?})={:?}" ,
960956 cache_fresh_trait_pred, candidate) ;
961957 self . insert_candidate_cache ( stack. obligation . param_env ,
962958 cache_fresh_trait_pred,
963- dep_node,
964959 candidate. clone ( ) ) ;
965960 }
966961
967962 candidate
968963 }
969964
970- fn in_task < OP , R > ( & mut self , op : OP ) -> ( R , DepNodeIndex )
971- where OP : FnOnce ( & mut Self ) -> R
972- {
973- let ( result, dep_node) = self . tcx ( ) . dep_graph . with_anon_task ( DepKind :: TraitSelect , || {
974- op ( self )
975- } ) ;
976- self . tcx ( ) . dep_graph . read_index ( dep_node) ;
977- ( result, dep_node)
978- }
979-
980965 // Treat negative impls as unimplemented
981966 fn filter_negative_impls ( & self , candidate : SelectionCandidate < ' tcx > )
982967 -> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
@@ -1166,41 +1151,33 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
11661151 cache_fresh_trait_pred : & ty:: PolyTraitPredicate < ' tcx > )
11671152 -> Option < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > >
11681153 {
1169- let tcx = self . tcx ( ) ;
11701154 let trait_ref = & cache_fresh_trait_pred. 0 . trait_ref ;
11711155 if self . can_use_global_caches ( param_env) {
1172- let cache = tcx. selection_cache . hashmap . borrow ( ) ;
1156+ let cache = self . tcx ( ) . selection_cache . hashmap . borrow ( ) ;
11731157 if let Some ( cached) = cache. get ( & trait_ref) {
1174- return Some ( cached. get ( tcx ) ) ;
1158+ return Some ( cached. clone ( ) ) ;
11751159 }
11761160 }
1177- self . infcx . selection_cache . hashmap
1178- . borrow ( )
1179- . get ( trait_ref)
1180- . map ( |v| v. get ( tcx) )
1161+ self . infcx . selection_cache . hashmap . borrow ( ) . get ( trait_ref) . cloned ( )
11811162 }
11821163
11831164 fn insert_candidate_cache ( & mut self ,
11841165 param_env : ty:: ParamEnv < ' tcx > ,
11851166 cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
1186- dep_node : DepNodeIndex ,
11871167 candidate : SelectionResult < ' tcx , SelectionCandidate < ' tcx > > )
11881168 {
1189- let tcx = self . tcx ( ) ;
11901169 let trait_ref = cache_fresh_trait_pred. 0 . trait_ref ;
11911170 if self . can_use_global_caches ( param_env) {
1192- let mut cache = tcx. selection_cache . hashmap . borrow_mut ( ) ;
1193- if let Some ( trait_ref) = tcx. lift_to_global ( & trait_ref) {
1194- if let Some ( candidate) = tcx. lift_to_global ( & candidate) {
1195- cache. insert ( trait_ref, WithDepNode :: new ( dep_node , candidate) ) ;
1171+ let mut cache = self . tcx ( ) . selection_cache . hashmap . borrow_mut ( ) ;
1172+ if let Some ( trait_ref) = self . tcx ( ) . lift_to_global ( & trait_ref) {
1173+ if let Some ( candidate) = self . tcx ( ) . lift_to_global ( & candidate) {
1174+ cache. insert ( trait_ref, candidate) ;
11961175 return ;
11971176 }
11981177 }
11991178 }
12001179
1201- self . infcx . selection_cache . hashmap
1202- . borrow_mut ( )
1203- . insert ( trait_ref, WithDepNode :: new ( dep_node, candidate) ) ;
1180+ self . infcx . selection_cache . hashmap . borrow_mut ( ) . insert ( trait_ref, candidate) ;
12041181 }
12051182
12061183 fn should_update_candidate_cache ( & mut self ,
@@ -3161,20 +3138,3 @@ impl<'o,'tcx> fmt::Debug for TraitObligationStack<'o,'tcx> {
31613138 write ! ( f, "TraitObligationStack({:?})" , self . obligation)
31623139 }
31633140}
3164-
3165- #[ derive( Clone ) ]
3166- pub struct WithDepNode < T > {
3167- dep_node : DepNodeIndex ,
3168- cached_value : T
3169- }
3170-
3171- impl < T : Clone > WithDepNode < T > {
3172- pub fn new ( dep_node : DepNodeIndex , cached_value : T ) -> Self {
3173- WithDepNode { dep_node, cached_value }
3174- }
3175-
3176- pub fn get ( & self , tcx : TyCtxt ) -> T {
3177- tcx. dep_graph . read_index ( self . dep_node ) ;
3178- self . cached_value . clone ( )
3179- }
3180- }
0 commit comments