@@ -20,7 +20,6 @@ use crate::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime};
20
20
use crate :: traits:: error_reporting:: TypeErrCtxtExt as _;
21
21
use crate :: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
22
22
use crate :: traits:: select:: ProjectionMatchesProjection ;
23
- use crate :: traits:: TraitEngineExt as _;
24
23
use rustc_data_structures:: sso:: SsoHashSet ;
25
24
use rustc_data_structures:: stack:: ensure_sufficient_stack;
26
25
use rustc_errors:: ErrorGuaranteed ;
@@ -32,7 +31,6 @@ use rustc_infer::infer::DefineOpaqueTypes;
32
31
use rustc_infer:: traits:: FulfillmentError ;
33
32
use rustc_infer:: traits:: ObligationCauseCode ;
34
33
use rustc_infer:: traits:: TraitEngine ;
35
- use rustc_infer:: traits:: TraitEngineExt as _;
36
34
use rustc_middle:: traits:: select:: OverflowError ;
37
35
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
38
36
use rustc_middle:: ty:: visit:: { MaxUniverse , TypeVisitable , TypeVisitableExt } ;
@@ -59,17 +57,17 @@ pub trait NormalizeExt<'tcx> {
59
57
fn normalize < T : TypeFoldable < TyCtxt < ' tcx > > > ( & self , t : T ) -> InferOk < ' tcx , T > ;
60
58
61
59
/// Deeply normalizes `value`, replacing all aliases which can by normalized in
62
- /// the current environment. Unlike other normalization routines, this errors
63
- /// in case normalization fails or is ambiguous.
60
+ /// the current environment. In the new solver this errors in case normalization
61
+ /// fails or is ambiguous. This only normalize opaque types with `Reveal::All` .
64
62
///
65
- /// In the old solver this simply uses `normalize` and errors in
66
- /// case of ambiguity. The new solver only normalizes in this function and
67
- /// `normalize` is a noop.
68
- ///
69
- /// This only normalize opaque types with `Reveal::All`.
63
+ /// In the old solver this simply uses `normalizes` and adds the nested obligations
64
+ /// to the `fulfill_cx`. This is necessary as we otherwise end up recomputing the
65
+ /// same goals in both a temporary and the shared context which negatively impacts
66
+ /// performance as these don't share caching.
70
67
fn deeply_normalize < T : TypeFoldable < TyCtxt < ' tcx > > > (
71
68
self ,
72
69
value : T ,
70
+ fulfill_cx : & mut dyn TraitEngine < ' tcx > ,
73
71
) -> Result < T , Vec < FulfillmentError < ' tcx > > > ;
74
72
}
75
73
@@ -88,15 +86,16 @@ impl<'tcx> NormalizeExt<'tcx> for At<'_, 'tcx> {
88
86
fn deeply_normalize < T : TypeFoldable < TyCtxt < ' tcx > > > (
89
87
self ,
90
88
value : T ,
89
+ fulfill_cx : & mut dyn TraitEngine < ' tcx > ,
91
90
) -> Result < T , Vec < FulfillmentError < ' tcx > > > {
92
91
if self . infcx . next_trait_solver ( ) {
93
92
crate :: solve:: deeply_normalize ( self , value)
94
93
} else {
95
- let mut fulfill_cx = <dyn TraitEngine < ' tcx > >:: new ( & self . infcx ) ;
96
94
let value = self
97
95
. normalize ( value)
98
96
. into_value_registering_obligations ( self . infcx , & mut * fulfill_cx) ;
99
- let errors = fulfill_cx. select_all_or_error ( self . infcx ) ;
97
+ let errors = fulfill_cx. select_where_possible ( self . infcx ) ;
98
+ let value = self . infcx . resolve_vars_if_possible ( value) ;
100
99
if errors. is_empty ( ) { Ok ( value) } else { Err ( errors) }
101
100
}
102
101
}
0 commit comments