@@ -709,7 +709,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
709
709
710
710
debug ! ( ?fresh_trait_ref) ;
711
711
712
- if let Some ( result) = self . check_evaluation_cache ( obligation. param_env , fresh_trait_ref) {
712
+ if let Some ( result) = self . check_evaluation_cache (
713
+ obligation. param_env ,
714
+ fresh_trait_ref,
715
+ obligation. predicate . skip_binder ( ) . polarity ,
716
+ ) {
713
717
debug ! ( ?result, "CACHE HIT" ) ;
714
718
return Ok ( result) ;
715
719
}
@@ -739,12 +743,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
739
743
let reached_depth = stack. reached_depth . get ( ) ;
740
744
if reached_depth >= stack. depth {
741
745
debug ! ( ?result, "CACHE MISS" ) ;
742
- self . insert_evaluation_cache ( obligation. param_env , fresh_trait_ref, dep_node, result) ;
746
+ self . insert_evaluation_cache (
747
+ obligation. param_env ,
748
+ fresh_trait_ref,
749
+ obligation. predicate . skip_binder ( ) . polarity ,
750
+ dep_node,
751
+ result,
752
+ ) ;
743
753
744
754
stack. cache ( ) . on_completion ( stack. dfn , |fresh_trait_ref, provisional_result| {
745
755
self . insert_evaluation_cache (
746
756
obligation. param_env ,
747
757
fresh_trait_ref,
758
+ obligation. predicate . skip_binder ( ) . polarity ,
748
759
dep_node,
749
760
provisional_result. max ( result) ,
750
761
) ;
@@ -977,6 +988,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
977
988
& self ,
978
989
param_env : ty:: ParamEnv < ' tcx > ,
979
990
trait_ref : ty:: ConstnessAnd < ty:: PolyTraitRef < ' tcx > > ,
991
+ polarity : ty:: ImplPolarity ,
980
992
) -> Option < EvaluationResult > {
981
993
// Neither the global nor local cache is aware of intercrate
982
994
// mode, so don't do any caching. In particular, we might
@@ -988,17 +1000,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
988
1000
989
1001
let tcx = self . tcx ( ) ;
990
1002
if self . can_use_global_caches ( param_env) {
991
- if let Some ( res) = tcx. evaluation_cache . get ( & param_env. and ( trait_ref) , tcx) {
1003
+ if let Some ( res) = tcx. evaluation_cache . get ( & ( param_env. and ( trait_ref) , polarity) , tcx)
1004
+ {
992
1005
return Some ( res) ;
993
1006
}
994
1007
}
995
- self . infcx . evaluation_cache . get ( & param_env. and ( trait_ref) , tcx)
1008
+ self . infcx . evaluation_cache . get ( & ( param_env. and ( trait_ref) , polarity ) , tcx)
996
1009
}
997
1010
998
1011
fn insert_evaluation_cache (
999
1012
& mut self ,
1000
1013
param_env : ty:: ParamEnv < ' tcx > ,
1001
1014
trait_ref : ty:: ConstnessAnd < ty:: PolyTraitRef < ' tcx > > ,
1015
+ polarity : ty:: ImplPolarity ,
1002
1016
dep_node : DepNodeIndex ,
1003
1017
result : EvaluationResult ,
1004
1018
) {
@@ -1023,13 +1037,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1023
1037
// FIXME: Due to #50507 this overwrites the different values
1024
1038
// This should be changed to use HashMapExt::insert_same
1025
1039
// when that is fixed
1026
- self . tcx ( ) . evaluation_cache . insert ( param_env. and ( trait_ref) , dep_node, result) ;
1040
+ self . tcx ( ) . evaluation_cache . insert (
1041
+ ( param_env. and ( trait_ref) , polarity) ,
1042
+ dep_node,
1043
+ result,
1044
+ ) ;
1027
1045
return ;
1028
1046
}
1029
1047
}
1030
1048
1031
1049
debug ! ( ?trait_ref, ?result, "insert_evaluation_cache" ) ;
1032
- self . infcx . evaluation_cache . insert ( param_env. and ( trait_ref) , dep_node, result) ;
1050
+ self . infcx . evaluation_cache . insert ( ( param_env. and ( trait_ref) , polarity ) , dep_node, result) ;
1033
1051
}
1034
1052
1035
1053
/// For various reasons, it's possible for a subobligation
0 commit comments