@@ -273,7 +273,7 @@ where
273
273
Normalized { value, obligations }
274
274
}
275
275
276
- #[ instrument( level = "debug " , skip( selcx, param_env, cause, obligations) ) ]
276
+ #[ instrument( level = "info " , skip( selcx, param_env, cause, obligations) ) ]
277
277
pub fn normalize_with_depth_to < ' a , ' b , ' tcx , T > (
278
278
selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
279
279
param_env : ty:: ParamEnv < ' tcx > ,
@@ -285,13 +285,26 @@ pub fn normalize_with_depth_to<'a, 'b, 'tcx, T>(
285
285
where
286
286
T : TypeFoldable < ' tcx > ,
287
287
{
288
+ debug ! ( obligations. len = obligations. len( ) ) ;
288
289
let mut normalizer = AssocTypeNormalizer :: new ( selcx, param_env, cause, depth, obligations) ;
289
290
let result = ensure_sufficient_stack ( || normalizer. fold ( value) ) ;
290
291
debug ! ( ?result, obligations. len = normalizer. obligations. len( ) ) ;
291
292
debug ! ( ?normalizer. obligations, ) ;
292
293
result
293
294
}
294
295
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
+
295
308
struct AssocTypeNormalizer < ' a , ' b , ' tcx > {
296
309
selcx : & ' a mut SelectionContext < ' b , ' tcx > ,
297
310
param_env : ty:: ParamEnv < ' tcx > ,
@@ -314,14 +327,19 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
314
327
315
328
fn fold < T : TypeFoldable < ' tcx > > ( & mut self , value : T ) -> T {
316
329
let value = self . selcx . infcx ( ) . resolve_vars_if_possible ( value) ;
330
+ debug ! ( ?value) ;
317
331
318
332
assert ! (
319
333
!value. has_escaping_bound_vars( ) ,
320
334
"Normalizing {:?} without wrapping in a `Binder`" ,
321
335
value
322
336
) ;
323
337
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
+ }
325
343
}
326
344
}
327
345
@@ -341,7 +359,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
341
359
}
342
360
343
361
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
344
- if !ty . has_projections ( ) {
362
+ if !needs_normalization ( & ty , self . param_env . reveal ( ) ) {
345
363
return ty;
346
364
}
347
365
// 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>(
825
843
826
844
let cache_result = infcx. inner . borrow_mut ( ) . projection_cache ( ) . try_start ( cache_key) ;
827
845
match cache_result {
828
- Ok ( ( ) ) => { }
846
+ Ok ( ( ) ) => debug ! ( "no cache" ) ,
829
847
Err ( ProjectionCacheEntry :: Ambiguous ) => {
830
848
// If we found ambiguity the last time, that means we will continue
831
849
// 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>(
852
870
return Err ( InProgress ) ;
853
871
}
854
872
Err ( ProjectionCacheEntry :: Recur ) => {
873
+ debug ! ( "recur cache" ) ;
855
874
return Err ( InProgress ) ;
856
875
}
857
876
Err ( ProjectionCacheEntry :: NormalizedTy ( ty) ) => {
@@ -1058,12 +1077,11 @@ impl<'tcx> Progress<'tcx> {
1058
1077
///
1059
1078
/// IMPORTANT:
1060
1079
/// - `obligation` must be fully normalized
1080
+ #[ tracing:: instrument( level = "info" , skip( selcx) ) ]
1061
1081
fn project_type < ' cx , ' tcx > (
1062
1082
selcx : & mut SelectionContext < ' cx , ' tcx > ,
1063
1083
obligation : & ProjectionTyObligation < ' tcx > ,
1064
1084
) -> Result < ProjectedTy < ' tcx > , ProjectionTyError < ' tcx > > {
1065
- debug ! ( ?obligation, "project_type" ) ;
1066
-
1067
1085
if !selcx. tcx ( ) . recursion_limit ( ) . value_within_limit ( obligation. recursion_depth ) {
1068
1086
debug ! ( "project: overflow!" ) ;
1069
1087
// This should really be an immediate error, but some existing code
0 commit comments