@@ -39,7 +39,6 @@ use rustc_middle::ty::fast_reject;
39
39
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
40
40
use rustc_middle:: ty:: relate:: TypeRelation ;
41
41
use rustc_middle:: ty:: subst:: { GenericArgKind , Subst , SubstsRef } ;
42
- use rustc_middle:: ty:: WithConstness ;
43
42
use rustc_middle:: ty:: { self , PolyProjectionPredicate , ToPolyTraitRef , ToPredicate } ;
44
43
use rustc_middle:: ty:: { Ty , TyCtxt , TypeFoldable } ;
45
44
use rustc_span:: symbol:: sym;
@@ -138,9 +137,9 @@ pub struct SelectionContext<'cx, 'tcx> {
138
137
struct TraitObligationStack < ' prev , ' tcx > {
139
138
obligation : & ' prev TraitObligation < ' tcx > ,
140
139
141
- /// The trait ref from `obligation` but "freshened" with the
140
+ /// The trait predicate from `obligation` but "freshened" with the
142
141
/// selection-context's freshener. Used to check for recursion.
143
- fresh_trait_ref : ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > ,
142
+ fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
144
143
145
144
/// Starts out equal to `depth` -- if, during evaluation, we
146
145
/// encounter a cycle, then we will set this flag to the minimum
@@ -676,20 +675,16 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
676
675
}
677
676
678
677
let stack = self . push_stack ( previous_stack, & obligation) ;
679
- let fresh_trait_ref = stack. fresh_trait_ref ;
678
+ let fresh_trait_pred = stack. fresh_trait_pred ;
680
679
681
- debug ! ( ?fresh_trait_ref ) ;
680
+ debug ! ( ?fresh_trait_pred ) ;
682
681
683
- if let Some ( result) = self . check_evaluation_cache (
684
- obligation. param_env ,
685
- fresh_trait_ref,
686
- obligation. polarity ( ) ,
687
- ) {
682
+ if let Some ( result) = self . check_evaluation_cache ( obligation. param_env , fresh_trait_pred) {
688
683
debug ! ( ?result, "CACHE HIT" ) ;
689
684
return Ok ( result) ;
690
685
}
691
686
692
- if let Some ( result) = stack. cache ( ) . get_provisional ( fresh_trait_ref ) {
687
+ if let Some ( result) = stack. cache ( ) . get_provisional ( fresh_trait_pred ) {
693
688
debug ! ( ?result, "PROVISIONAL CACHE HIT" ) ;
694
689
stack. update_reached_depth ( result. reached_depth ) ;
695
690
return Ok ( result. result ) ;
@@ -714,19 +709,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
714
709
let reached_depth = stack. reached_depth . get ( ) ;
715
710
if reached_depth >= stack. depth {
716
711
debug ! ( ?result, "CACHE MISS" ) ;
717
- self . insert_evaluation_cache (
718
- obligation. param_env ,
719
- fresh_trait_ref,
720
- obligation. polarity ( ) ,
721
- dep_node,
722
- result,
723
- ) ;
712
+ self . insert_evaluation_cache ( obligation. param_env , fresh_trait_pred, dep_node, result) ;
724
713
725
- stack. cache ( ) . on_completion ( stack. dfn , |fresh_trait_ref , provisional_result| {
714
+ stack. cache ( ) . on_completion ( stack. dfn , |fresh_trait_pred , provisional_result| {
726
715
self . insert_evaluation_cache (
727
716
obligation. param_env ,
728
- fresh_trait_ref,
729
- obligation. polarity ( ) ,
717
+ fresh_trait_pred,
730
718
dep_node,
731
719
provisional_result. max ( result) ,
732
720
) ;
@@ -736,10 +724,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
736
724
debug ! (
737
725
"caching provisionally because {:?} \
738
726
is a cycle participant (at depth {}, reached depth {})",
739
- fresh_trait_ref , stack. depth, reached_depth,
727
+ fresh_trait_pred , stack. depth, reached_depth,
740
728
) ;
741
729
742
- stack. cache ( ) . insert_provisional ( stack. dfn , reached_depth, fresh_trait_ref , result) ;
730
+ stack. cache ( ) . insert_provisional ( stack. dfn , reached_depth, fresh_trait_pred , result) ;
743
731
}
744
732
745
733
Ok ( result)
@@ -773,7 +761,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
773
761
. skip ( 1 ) // Skip top-most frame.
774
762
. find ( |prev| {
775
763
stack. obligation . param_env == prev. obligation . param_env
776
- && stack. fresh_trait_ref == prev. fresh_trait_ref
764
+ && stack. fresh_trait_pred == prev. fresh_trait_pred
777
765
} )
778
766
. map ( |stack| stack. depth )
779
767
{
@@ -836,7 +824,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
836
824
// terms of `Fn` etc, but we could probably make this more
837
825
// precise still.
838
826
let unbound_input_types =
839
- stack. fresh_trait_ref . value . skip_binder ( ) . substs . types ( ) . any ( |ty| ty. is_fresh ( ) ) ;
827
+ stack. fresh_trait_pred . skip_binder ( ) . trait_ref . substs . types ( ) . any ( |ty| ty. is_fresh ( ) ) ;
840
828
841
829
if stack. obligation . polarity ( ) != ty:: ImplPolarity :: Negative {
842
830
// This check was an imperfect workaround for a bug in the old
@@ -874,8 +862,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
874
862
&& stack. iter ( ) . skip ( 1 ) . any ( |prev| {
875
863
stack. obligation . param_env == prev. obligation . param_env
876
864
&& self . match_fresh_trait_refs (
877
- stack. fresh_trait_ref ,
878
- prev. fresh_trait_ref ,
865
+ stack. fresh_trait_pred ,
866
+ prev. fresh_trait_pred ,
879
867
prev. obligation . param_env ,
880
868
)
881
869
} )
@@ -953,7 +941,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
953
941
// not just the lifetime choice for this particular (non-erased)
954
942
// predicate.
955
943
// See issue #80691
956
- if stack. fresh_trait_ref . has_erased_regions ( ) {
944
+ if stack. fresh_trait_pred . has_erased_regions ( ) {
957
945
result = result. max ( EvaluatedToOkModuloRegions ) ;
958
946
}
959
947
@@ -964,8 +952,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
964
952
fn check_evaluation_cache (
965
953
& self ,
966
954
param_env : ty:: ParamEnv < ' tcx > ,
967
- trait_ref : ty:: ConstnessAnd < ty:: PolyTraitRef < ' tcx > > ,
968
- polarity : ty:: ImplPolarity ,
955
+ trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
969
956
) -> Option < EvaluationResult > {
970
957
// Neither the global nor local cache is aware of intercrate
971
958
// mode, so don't do any caching. In particular, we might
@@ -977,19 +964,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
977
964
978
965
let tcx = self . tcx ( ) ;
979
966
if self . can_use_global_caches ( param_env) {
980
- if let Some ( res) = tcx. evaluation_cache . get ( & ( param_env. and ( trait_ref) , polarity) , tcx)
981
- {
967
+ if let Some ( res) = tcx. evaluation_cache . get ( & param_env. and ( trait_pred) , tcx) {
982
968
return Some ( res) ;
983
969
}
984
970
}
985
- self . infcx . evaluation_cache . get ( & ( param_env. and ( trait_ref ) , polarity ) , tcx)
971
+ self . infcx . evaluation_cache . get ( & param_env. and ( trait_pred ) , tcx)
986
972
}
987
973
988
974
fn insert_evaluation_cache (
989
975
& mut self ,
990
976
param_env : ty:: ParamEnv < ' tcx > ,
991
- trait_ref : ty:: ConstnessAnd < ty:: PolyTraitRef < ' tcx > > ,
992
- polarity : ty:: ImplPolarity ,
977
+ trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
993
978
dep_node : DepNodeIndex ,
994
979
result : EvaluationResult ,
995
980
) {
@@ -1008,23 +993,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
1008
993
}
1009
994
1010
995
if self . can_use_global_caches ( param_env) {
1011
- if !trait_ref . needs_infer ( ) {
1012
- debug ! ( ?trait_ref , ?result, "insert_evaluation_cache global" ) ;
996
+ if !trait_pred . needs_infer ( ) {
997
+ debug ! ( ?trait_pred , ?result, "insert_evaluation_cache global" ) ;
1013
998
// This may overwrite the cache with the same value
1014
999
// FIXME: Due to #50507 this overwrites the different values
1015
1000
// This should be changed to use HashMapExt::insert_same
1016
1001
// when that is fixed
1017
- self . tcx ( ) . evaluation_cache . insert (
1018
- ( param_env. and ( trait_ref) , polarity) ,
1019
- dep_node,
1020
- result,
1021
- ) ;
1002
+ self . tcx ( ) . evaluation_cache . insert ( param_env. and ( trait_pred) , dep_node, result) ;
1022
1003
return ;
1023
1004
}
1024
1005
}
1025
1006
1026
- debug ! ( ?trait_ref , ?result, "insert_evaluation_cache" ) ;
1027
- self . infcx . evaluation_cache . insert ( ( param_env. and ( trait_ref ) , polarity ) , dep_node, result) ;
1007
+ debug ! ( ?trait_pred , ?result, "insert_evaluation_cache" ) ;
1008
+ self . infcx . evaluation_cache . insert ( param_env. and ( trait_pred ) , dep_node, result) ;
1028
1009
}
1029
1010
1030
1011
/// For various reasons, it's possible for a subobligation
@@ -2157,8 +2138,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2157
2138
2158
2139
fn match_fresh_trait_refs (
2159
2140
& self ,
2160
- previous : ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > ,
2161
- current : ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > ,
2141
+ previous : ty:: PolyTraitPredicate < ' tcx > ,
2142
+ current : ty:: PolyTraitPredicate < ' tcx > ,
2162
2143
param_env : ty:: ParamEnv < ' tcx > ,
2163
2144
) -> bool {
2164
2145
let mut matcher = ty:: _match:: Match :: new ( self . tcx ( ) , param_env) ;
@@ -2170,17 +2151,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2170
2151
previous_stack : TraitObligationStackList < ' o , ' tcx > ,
2171
2152
obligation : & ' o TraitObligation < ' tcx > ,
2172
2153
) -> TraitObligationStack < ' o , ' tcx > {
2173
- let fresh_trait_ref = obligation
2174
- . predicate
2175
- . to_poly_trait_ref ( )
2176
- . fold_with ( & mut self . freshener )
2177
- . with_constness ( obligation. predicate . skip_binder ( ) . constness ) ;
2154
+ let fresh_trait_pred = obligation. predicate . fold_with ( & mut self . freshener ) ;
2178
2155
2179
2156
let dfn = previous_stack. cache . next_dfn ( ) ;
2180
2157
let depth = previous_stack. depth ( ) + 1 ;
2181
2158
TraitObligationStack {
2182
2159
obligation,
2183
- fresh_trait_ref ,
2160
+ fresh_trait_pred ,
2184
2161
reached_depth : Cell :: new ( depth) ,
2185
2162
previous : previous_stack,
2186
2163
dfn,
@@ -2374,7 +2351,7 @@ impl<'o, 'tcx> TraitObligationStack<'o, 'tcx> {
2374
2351
debug ! ( reached_depth, "update_reached_depth" ) ;
2375
2352
let mut p = self ;
2376
2353
while reached_depth < p. depth {
2377
- debug ! ( ?p. fresh_trait_ref , "update_reached_depth: marking as cycle participant" ) ;
2354
+ debug ! ( ?p. fresh_trait_pred , "update_reached_depth: marking as cycle participant" ) ;
2378
2355
p. reached_depth . set ( p. reached_depth . get ( ) . min ( reached_depth) ) ;
2379
2356
p = p. previous . head . unwrap ( ) ;
2380
2357
}
@@ -2453,7 +2430,7 @@ struct ProvisionalEvaluationCache<'tcx> {
2453
2430
/// - then we determine that `E` is in error -- we will then clear
2454
2431
/// all cache values whose DFN is >= 4 -- in this case, that
2455
2432
/// means the cached value for `F`.
2456
- map : RefCell < FxHashMap < ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > , ProvisionalEvaluation > > ,
2433
+ map : RefCell < FxHashMap < ty:: PolyTraitPredicate < ' tcx > , ProvisionalEvaluation > > ,
2457
2434
}
2458
2435
2459
2436
/// A cache value for the provisional cache: contains the depth-first
@@ -2485,28 +2462,28 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
2485
2462
/// `reached_depth` (from the returned value).
2486
2463
fn get_provisional (
2487
2464
& self ,
2488
- fresh_trait_ref : ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > ,
2465
+ fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
2489
2466
) -> Option < ProvisionalEvaluation > {
2490
2467
debug ! (
2491
- ?fresh_trait_ref ,
2468
+ ?fresh_trait_pred ,
2492
2469
"get_provisional = {:#?}" ,
2493
- self . map. borrow( ) . get( & fresh_trait_ref ) ,
2470
+ self . map. borrow( ) . get( & fresh_trait_pred ) ,
2494
2471
) ;
2495
- Some ( * self . map . borrow ( ) . get ( & fresh_trait_ref ) ?)
2472
+ Some ( * self . map . borrow ( ) . get ( & fresh_trait_pred ) ?)
2496
2473
}
2497
2474
2498
2475
/// Insert a provisional result into the cache. The result came
2499
2476
/// from the node with the given DFN. It accessed a minimum depth
2500
- /// of `reached_depth` to compute. It evaluated `fresh_trait_ref `
2477
+ /// of `reached_depth` to compute. It evaluated `fresh_trait_pred `
2501
2478
/// and resulted in `result`.
2502
2479
fn insert_provisional (
2503
2480
& self ,
2504
2481
from_dfn : usize ,
2505
2482
reached_depth : usize ,
2506
- fresh_trait_ref : ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > ,
2483
+ fresh_trait_pred : ty:: PolyTraitPredicate < ' tcx > ,
2507
2484
result : EvaluationResult ,
2508
2485
) {
2509
- debug ! ( ?from_dfn, ?fresh_trait_ref , ?result, "insert_provisional" ) ;
2486
+ debug ! ( ?from_dfn, ?fresh_trait_pred , ?result, "insert_provisional" ) ;
2510
2487
2511
2488
let mut map = self . map . borrow_mut ( ) ;
2512
2489
@@ -2530,7 +2507,7 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
2530
2507
}
2531
2508
}
2532
2509
2533
- map. insert ( fresh_trait_ref , ProvisionalEvaluation { from_dfn, reached_depth, result } ) ;
2510
+ map. insert ( fresh_trait_pred , ProvisionalEvaluation { from_dfn, reached_depth, result } ) ;
2534
2511
}
2535
2512
2536
2513
/// Invoked when the node with dfn `dfn` does not get a successful
@@ -2581,16 +2558,16 @@ impl<'tcx> ProvisionalEvaluationCache<'tcx> {
2581
2558
fn on_completion (
2582
2559
& self ,
2583
2560
dfn : usize ,
2584
- mut op : impl FnMut ( ty:: ConstnessAnd < ty :: PolyTraitRef < ' tcx > > , EvaluationResult ) ,
2561
+ mut op : impl FnMut ( ty:: PolyTraitPredicate < ' tcx > , EvaluationResult ) ,
2585
2562
) {
2586
2563
debug ! ( ?dfn, "on_completion" ) ;
2587
2564
2588
- for ( fresh_trait_ref , eval) in
2565
+ for ( fresh_trait_pred , eval) in
2589
2566
self . map . borrow_mut ( ) . drain_filter ( |_k, eval| eval. from_dfn >= dfn)
2590
2567
{
2591
- debug ! ( ?fresh_trait_ref , ?eval, "on_completion" ) ;
2568
+ debug ! ( ?fresh_trait_pred , ?eval, "on_completion" ) ;
2592
2569
2593
- op ( fresh_trait_ref , eval. result ) ;
2570
+ op ( fresh_trait_pred , eval. result ) ;
2594
2571
}
2595
2572
}
2596
2573
}
0 commit comments