@@ -273,7 +273,7 @@ where
273273 Normalized { value, obligations }
274274}
275275
276- #[ instrument( level = "debug " , skip( selcx, param_env, cause, obligations) ) ]
276+ #[ instrument( level = "info " , skip( selcx, param_env, cause, obligations) ) ]
277277pub fn normalize_with_depth_to < ' a , ' b , ' tcx , T > (
278278 selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
279279 param_env : ty:: ParamEnv < ' tcx > ,
@@ -285,13 +285,26 @@ pub fn normalize_with_depth_to<'a, 'b, 'tcx, T>(
285285where
286286 T : TypeFoldable < ' tcx > ,
287287{
288+ debug ! ( obligations. len = obligations. len( ) ) ;
288289 let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth, obligations) ;
289290 let result = ensure_sufficient_stack ( || normalizer. fold ( value) ) ;
290291 debug ! ( ?result, obligations. len = normalizer. obligations. len( ) ) ;
291292 debug ! ( ?normalizer. obligations, ) ;
292293 result
293294}
294295
296+ pub ( crate ) fn needs_normalization < ' tcx , T : TypeFoldable < ' tcx > > ( value : & T , reveal : Reveal ) -> bool {
297+ match reveal {
298+ Reveal :: UserFacing => value
299+ . has_type_flags ( ty:: TypeFlags :: HAS_TY_PROJECTION | ty:: TypeFlags :: HAS_CT_PROJECTION ) ,
300+ Reveal :: All => value. has_type_flags (
301+ ty:: TypeFlags :: HAS_TY_PROJECTION
302+ | ty:: TypeFlags :: HAS_TY_OPAQUE
303+ | ty:: TypeFlags :: HAS_CT_PROJECTION ,
304+ ) ,
305+ }
306+ }
307+
295308struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
296309 selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
297310 param_env : ty:: ParamEnv < ' tcx > ,
@@ -314,14 +327,19 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
314327
315328 fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : T ) -> T {
316329 let value = self . selcx . infcx ( ) . resolve_vars_if_possible ( value) ;
330+ debug ! ( ?value) ;
317331
318332 assert ! (
319333 !value. has_escaping_bound_vars( ) ,
320334 "Normalizing {:?} without wrapping in a `Binder`" ,
321335 value
322336 ) ;
323337
324- if !value. has_projections ( ) { value } else { value. fold_with ( self ) }
338+ if !needs_normalization ( & value, self . param_env . reveal ( ) ) {
339+ value
340+ } else {
341+ value. fold_with ( self )
342+ }
325343 }
326344}
327345
@@ -341,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
341359 }
342360
343361 fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
344- if !ty . has_projections ( ) {
362+ if !needs_normalization ( & ty , self . param_env . reveal ( ) ) {
345363 return ty;
346364 }
347365 // We don't want to normalize associated types that occur inside of region
@@ -825,7 +843,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
825843
826844 let cache_result = infcx. inner . borrow_mut ( ) . projection_cache ( ) . try_start ( cache_key) ;
827845 match cache_result {
828- Ok ( ( ) ) => { }
846+ Ok ( ( ) ) => debug ! ( "no cache" ) ,
829847 Err ( ProjectionCacheEntry :: Ambiguous ) => {
830848 // If we found ambiguity the last time, that means we will continue
831849 // to do so until some type in the key changes (and we know it
@@ -852,6 +870,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
852870 return Err ( InProgress ) ;
853871 }
854872 Err ( ProjectionCacheEntry :: Recur ) => {
873+ debug ! ( "recur cache" ) ;
855874 return Err ( InProgress ) ;
856875 }
857876 Err ( ProjectionCacheEntry :: NormalizedTy ( ty) ) => {
@@ -1058,12 +1077,11 @@ impl<'tcx> Progress<'tcx> {
10581077///
10591078/// IMPORTANT:
10601079/// - `obligation` must be fully normalized
1080+ #[ tracing:: instrument( level = "info" , skip( selcx) ) ]
10611081fn project_type < ' cx , ' tcx > (
10621082 selcx : & mut SelectionContext < ' cx , ' tcx > ,
10631083 obligation : & ProjectionTyObligation < ' tcx > ,
10641084) -> Result < ProjectedTy < ' tcx > , ProjectionTyError < ' tcx > > {
1065- debug ! ( ?obligation, "project_type" ) ;
1066-
10671085 if !selcx. tcx ( ) . recursion_limit ( ) . value_within_limit ( obligation. recursion_depth ) {
10681086 debug ! ( "project: overflow!" ) ;
10691087 // This should really be an immediate error, but some existing code
0 commit comments