@@ -30,7 +30,6 @@ use super::{VtableImplData, VtableObjectData, VtableBuiltinData,
30
30
VtableClosureData , VtableDefaultImplData , VtableFnPointerData } ;
31
31
use super :: util;
32
32
33
- use dep_graph:: { DepNodeIndex , DepKind } ;
34
33
use hir:: def_id:: DefId ;
35
34
use infer;
36
35
use infer:: { InferCtxt , InferOk , TypeFreshener } ;
@@ -106,7 +105,7 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> {
106
105
#[ derive( Clone ) ]
107
106
pub struct SelectionCache < ' tcx > {
108
107
hashmap : RefCell < FxHashMap < ty:: TraitRef < ' tcx > ,
109
- WithDepNode < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > > > ,
108
+ SelectionResult < ' tcx , SelectionCandidate < ' tcx > > > > ,
110
109
}
111
110
112
111
/// The selection process begins by considering all impls, where
@@ -370,7 +369,7 @@ impl EvaluationResult {
370
369
371
370
#[ derive( Clone ) ]
372
371
pub struct EvaluationCache < ' tcx > {
373
- hashmap : RefCell < FxHashMap < ty:: PolyTraitRef < ' tcx > , WithDepNode < EvaluationResult > > >
372
+ hashmap : RefCell < FxHashMap < ty:: PolyTraitRef < ' tcx > , EvaluationResult > >
374
373
}
375
374
376
375
impl < ' cx , ' gcx , ' tcx > SelectionContext < ' cx , ' gcx , ' tcx > {
@@ -467,6 +466,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
467
466
assert ! ( !obligation. predicate. has_escaping_regions( ) ) ;
468
467
469
468
let tcx = self . tcx ( ) ;
469
+ let dep_node = obligation. predicate . dep_node ( tcx) ;
470
+ let _task = tcx. dep_graph . in_task ( dep_node) ;
470
471
471
472
let stack = self . push_stack ( TraitObligationStackList :: empty ( ) , obligation) ;
472
473
let ret = match self . candidate_from_obligation ( & stack) ? {
@@ -709,12 +710,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
709
710
return result;
710
711
}
711
712
712
- let ( result, dep_node ) = self . in_task ( |this| this . evaluate_stack ( & stack) ) ;
713
+ let result = self . evaluate_stack ( & stack) ;
713
714
714
715
debug ! ( "CACHE MISS: EVAL({:?})={:?}" ,
715
716
fresh_trait_ref,
716
717
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) ;
718
719
719
720
result
720
721
}
@@ -869,23 +870,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
869
870
trait_ref : ty:: PolyTraitRef < ' tcx > )
870
871
-> Option < EvaluationResult >
871
872
{
872
- let tcx = self . tcx ( ) ;
873
873
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 ( ) ;
875
875
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 ( ) ) ;
877
881
}
878
882
}
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 ( )
883
884
}
884
885
885
886
fn insert_evaluation_cache ( & mut self ,
886
887
param_env : ty:: ParamEnv < ' tcx > ,
887
888
trait_ref : ty:: PolyTraitRef < ' tcx > ,
888
- dep_node : DepNodeIndex ,
889
889
result : EvaluationResult )
890
890
{
891
891
// Avoid caching results that depend on more than just the trait-ref:
@@ -902,14 +902,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
902
902
if self . can_use_global_caches ( param_env) {
903
903
let mut cache = self . tcx ( ) . evaluation_cache . hashmap . borrow_mut ( ) ;
904
904
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) ;
906
906
return ;
907
907
}
908
908
}
909
909
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) ;
913
911
}
914
912
915
913
///////////////////////////////////////////////////////////////////////////
@@ -951,32 +949,19 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
951
949
}
952
950
953
951
// 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) ;
957
953
958
954
if self . should_update_candidate_cache ( & cache_fresh_trait_pred, & candidate) {
959
955
debug ! ( "CACHE MISS: SELECT({:?})={:?}" ,
960
956
cache_fresh_trait_pred, candidate) ;
961
957
self . insert_candidate_cache ( stack. obligation . param_env ,
962
958
cache_fresh_trait_pred,
963
- dep_node,
964
959
candidate. clone ( ) ) ;
965
960
}
966
961
967
962
candidate
968
963
}
969
964
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
-
980
965
// Treat negative impls as unimplemented
981
966
fn filter_negative_impls ( & self , candidate : SelectionCandidate < ' tcx > )
982
967
-> SelectionResult < ' tcx , SelectionCandidate < ' tcx > > {
@@ -1166,41 +1151,33 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1166
1151
cache_fresh_trait_pred : & ty:: PolyTraitPredicate < ' tcx > )
1167
1152
-> Option < SelectionResult < ' tcx , SelectionCandidate < ' tcx > > >
1168
1153
{
1169
- let tcx = self . tcx ( ) ;
1170
1154
let trait_ref = & cache_fresh_trait_pred. 0 . trait_ref ;
1171
1155
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 ( ) ;
1173
1157
if let Some ( cached) = cache. get ( & trait_ref) {
1174
- return Some ( cached. get ( tcx ) ) ;
1158
+ return Some ( cached. clone ( ) ) ;
1175
1159
}
1176
1160
}
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 ( )
1181
1162
}
1182
1163
1183
1164
fn insert_candidate_cache ( & mut self ,
1184
1165
param_env : ty:: ParamEnv < ' tcx > ,
1185
1166
cache_fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
1186
- dep_node : DepNodeIndex ,
1187
1167
candidate : SelectionResult < ' tcx , SelectionCandidate < ' tcx > > )
1188
1168
{
1189
- let tcx = self . tcx ( ) ;
1190
1169
let trait_ref = cache_fresh_trait_pred. 0 . trait_ref ;
1191
1170
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) ;
1196
1175
return ;
1197
1176
}
1198
1177
}
1199
1178
}
1200
1179
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) ;
1204
1181
}
1205
1182
1206
1183
fn should_update_candidate_cache ( & mut self ,
@@ -3161,20 +3138,3 @@ impl<'o,'tcx> fmt::Debug for TraitObligationStack<'o,'tcx> {
3161
3138
write ! ( f, "TraitObligationStack({:?})" , self . obligation)
3162
3139
}
3163
3140
}
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