@@ -17,8 +17,7 @@ use tracing::debug;
1717
1818use crate :: infer:: InferCtxt ;
1919use crate :: infer:: canonical:: {
20- Canonical , CanonicalQueryInput , CanonicalTyVarKind , CanonicalVarInfo , CanonicalVarKind ,
21- OriginalQueryValues ,
20+ Canonical , CanonicalQueryInput , CanonicalTyVarKind , CanonicalVarKind , OriginalQueryValues ,
2221} ;
2322
2423impl < ' tcx > InferCtxt < ' tcx > {
@@ -174,10 +173,8 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
174173 match r. kind ( ) {
175174 ty:: ReLateParam ( _) | ty:: ReErased | ty:: ReStatic | ty:: ReEarlyParam ( ..) => r,
176175
177- ty:: RePlaceholder ( placeholder) => canonicalizer. canonical_var_for_region (
178- CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderRegion ( placeholder) } ,
179- r,
180- ) ,
176+ ty:: RePlaceholder ( placeholder) => canonicalizer
177+ . canonical_var_for_region ( CanonicalVarKind :: PlaceholderRegion ( placeholder) , r) ,
181178
182179 ty:: ReVar ( vid) => {
183180 let universe = infcx
@@ -186,10 +183,7 @@ impl CanonicalizeMode for CanonicalizeQueryResponse {
186183 . unwrap_region_constraints ( )
187184 . probe_value ( vid)
188185 . unwrap_err ( ) ;
189- canonicalizer. canonical_var_for_region (
190- CanonicalVarInfo { kind : CanonicalVarKind :: Region ( universe) } ,
191- r,
192- )
186+ canonicalizer. canonical_var_for_region ( CanonicalVarKind :: Region ( universe) , r)
193187 }
194188
195189 _ => {
@@ -294,7 +288,7 @@ struct Canonicalizer<'cx, 'tcx> {
294288 /// Set to `None` to disable the resolution of inference variables.
295289 infcx : Option < & ' cx InferCtxt < ' tcx > > ,
296290 tcx : TyCtxt < ' tcx > ,
297- variables : SmallVec < [ CanonicalVarInfo < ' tcx > ; 8 ] > ,
291+ variables : SmallVec < [ CanonicalVarKind < ' tcx > ; 8 ] > ,
298292 query_state : & ' cx mut OriginalQueryValues < ' tcx > ,
299293 // Note that indices is only used once `var_values` is big enough to be
300294 // heap-allocated.
@@ -368,9 +362,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
368362 ui = ty:: UniverseIndex :: ROOT ;
369363 }
370364 self . canonicalize_ty_var (
371- CanonicalVarInfo {
372- kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) ) ,
373- } ,
365+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( ui) ) ,
374366 t,
375367 )
376368 }
@@ -382,21 +374,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
382374 if nt != t {
383375 return self . fold_ty ( nt) ;
384376 } else {
385- self . canonicalize_ty_var (
386- CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) } ,
387- t,
388- )
377+ self . canonicalize_ty_var ( CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) , t)
389378 }
390379 }
391380 ty:: Infer ( ty:: FloatVar ( vid) ) => {
392381 let nt = self . infcx . unwrap ( ) . opportunistic_resolve_float_var ( vid) ;
393382 if nt != t {
394383 return self . fold_ty ( nt) ;
395384 } else {
396- self . canonicalize_ty_var (
397- CanonicalVarInfo { kind : CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) } ,
398- t,
399- )
385+ self . canonicalize_ty_var ( CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) , t)
400386 }
401387 }
402388
@@ -408,10 +394,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
408394 if !self . canonicalize_mode . preserve_universes ( ) {
409395 placeholder. universe = ty:: UniverseIndex :: ROOT ;
410396 }
411- self . canonicalize_ty_var (
412- CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderTy ( placeholder) } ,
413- t,
414- )
397+ self . canonicalize_ty_var ( CanonicalVarKind :: PlaceholderTy ( placeholder) , t)
415398 }
416399
417400 ty:: Bound ( debruijn, _) => {
@@ -483,10 +466,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
483466 // FIXME: perf problem described in #55921.
484467 ui = ty:: UniverseIndex :: ROOT ;
485468 }
486- return self . canonicalize_const_var (
487- CanonicalVarInfo { kind : CanonicalVarKind :: Const ( ui) } ,
488- ct,
489- ) ;
469+ return self . canonicalize_const_var ( CanonicalVarKind :: Const ( ui) , ct) ;
490470 }
491471 }
492472 }
@@ -501,10 +481,8 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
501481 }
502482 }
503483 ty:: ConstKind :: Placeholder ( placeholder) => {
504- return self . canonicalize_const_var (
505- CanonicalVarInfo { kind : CanonicalVarKind :: PlaceholderConst ( placeholder) } ,
506- ct,
507- ) ;
484+ return self
485+ . canonicalize_const_var ( CanonicalVarKind :: PlaceholderConst ( placeholder) , ct) ;
508486 }
509487 _ => { }
510488 }
@@ -595,7 +573,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
595573 debug_assert ! ( !out_value. has_infer( ) && !out_value. has_placeholders( ) ) ;
596574
597575 let canonical_variables =
598- tcx. mk_canonical_var_infos ( & canonicalizer. universe_canonicalized_variables ( ) ) ;
576+ tcx. mk_canonical_var_kinds ( & canonicalizer. universe_canonicalized_variables ( ) ) ;
599577
600578 let max_universe = canonical_variables
601579 . iter ( )
@@ -610,18 +588,22 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
610588 /// or returns an existing variable if `kind` has already been
611589 /// seen. `kind` is expected to be an unbound variable (or
612590 /// potentially a free region).
613- fn canonical_var ( & mut self , info : CanonicalVarInfo < ' tcx > , kind : GenericArg < ' tcx > ) -> BoundVar {
591+ fn canonical_var (
592+ & mut self ,
593+ var_kind : CanonicalVarKind < ' tcx > ,
594+ value : GenericArg < ' tcx > ,
595+ ) -> BoundVar {
614596 let Canonicalizer { variables, query_state, indices, .. } = self ;
615597
616598 let var_values = & mut query_state. var_values ;
617599
618- let universe = info . universe ( ) ;
600+ let universe = var_kind . universe ( ) ;
619601 if universe != ty:: UniverseIndex :: ROOT {
620602 assert ! ( self . canonicalize_mode. preserve_universes( ) ) ;
621603
622604 // Insert universe into the universe map. To preserve the order of the
623605 // universes in the value being canonicalized, we don't update the
624- // universe in `info ` until we have finished canonicalizing.
606+ // universe in `var_kind ` until we have finished canonicalizing.
625607 match query_state. universe_map . binary_search ( & universe) {
626608 Err ( idx) => query_state. universe_map . insert ( idx, universe) ,
627609 Ok ( _) => { }
@@ -636,14 +618,14 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
636618 if !var_values. spilled ( ) {
637619 // `var_values` is stack-allocated. `indices` isn't used yet. Do a
638620 // direct linear search of `var_values`.
639- if let Some ( idx) = var_values. iter ( ) . position ( |& k| k == kind ) {
621+ if let Some ( idx) = var_values. iter ( ) . position ( |& v| v == value ) {
640622 // `kind` is already present in `var_values`.
641623 BoundVar :: new ( idx)
642624 } else {
643625 // `kind` isn't present in `var_values`. Append it. Likewise
644- // for `info ` and `variables`.
645- variables. push ( info ) ;
646- var_values. push ( kind ) ;
626+ // for `var_kind ` and `variables`.
627+ variables. push ( var_kind ) ;
628+ var_values. push ( value ) ;
647629 assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
648630
649631 // If `var_values` has become big enough to be heap-allocated,
@@ -653,17 +635,17 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
653635 * indices = var_values
654636 . iter ( )
655637 . enumerate ( )
656- . map ( |( i, & kind ) | ( kind , BoundVar :: new ( i) ) )
638+ . map ( |( i, & value ) | ( value , BoundVar :: new ( i) ) )
657639 . collect ( ) ;
658640 }
659641 // The cv is the index of the appended element.
660642 BoundVar :: new ( var_values. len ( ) - 1 )
661643 }
662644 } else {
663645 // `var_values` is large. Do a hashmap search via `indices`.
664- * indices. entry ( kind ) . or_insert_with ( || {
665- variables. push ( info ) ;
666- var_values. push ( kind ) ;
646+ * indices. entry ( value ) . or_insert_with ( || {
647+ variables. push ( var_kind ) ;
648+ var_values. push ( value ) ;
667649 assert_eq ! ( variables. len( ) , var_values. len( ) ) ;
668650 BoundVar :: new ( variables. len ( ) - 1 )
669651 } )
@@ -673,7 +655,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
673655 /// Replaces the universe indexes used in `var_values` with their index in
674656 /// `query_state.universe_map`. This minimizes the maximum universe used in
675657 /// the canonicalized value.
676- fn universe_canonicalized_variables ( self ) -> SmallVec < [ CanonicalVarInfo < ' tcx > ; 8 ] > {
658+ fn universe_canonicalized_variables ( self ) -> SmallVec < [ CanonicalVarKind < ' tcx > ; 8 ] > {
677659 if self . query_state . universe_map . len ( ) == 1 {
678660 return self . variables ;
679661 }
@@ -688,37 +670,33 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
688670
689671 self . variables
690672 . iter ( )
691- . map ( |v| CanonicalVarInfo {
692- kind : match v. kind {
693- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
694- return * v;
695- }
696- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( u) ) => {
697- CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( reverse_universe_map[ & u] ) )
698- }
699- CanonicalVarKind :: Region ( u) => {
700- CanonicalVarKind :: Region ( reverse_universe_map[ & u] )
701- }
702- CanonicalVarKind :: Const ( u) => CanonicalVarKind :: Const ( reverse_universe_map[ & u] ) ,
703- CanonicalVarKind :: PlaceholderTy ( placeholder) => {
704- CanonicalVarKind :: PlaceholderTy ( ty:: Placeholder {
705- universe : reverse_universe_map[ & placeholder. universe ] ,
706- ..placeholder
707- } )
708- }
709- CanonicalVarKind :: PlaceholderRegion ( placeholder) => {
710- CanonicalVarKind :: PlaceholderRegion ( ty:: Placeholder {
711- universe : reverse_universe_map[ & placeholder. universe ] ,
712- ..placeholder
713- } )
714- }
715- CanonicalVarKind :: PlaceholderConst ( placeholder) => {
716- CanonicalVarKind :: PlaceholderConst ( ty:: Placeholder {
717- universe : reverse_universe_map[ & placeholder. universe ] ,
718- ..placeholder
719- } )
720- }
721- } ,
673+ . map ( |& kind| match kind {
674+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int | CanonicalTyVarKind :: Float ) => {
675+ return kind;
676+ }
677+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( u) ) => {
678+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: General ( reverse_universe_map[ & u] ) )
679+ }
680+ CanonicalVarKind :: Region ( u) => CanonicalVarKind :: Region ( reverse_universe_map[ & u] ) ,
681+ CanonicalVarKind :: Const ( u) => CanonicalVarKind :: Const ( reverse_universe_map[ & u] ) ,
682+ CanonicalVarKind :: PlaceholderTy ( placeholder) => {
683+ CanonicalVarKind :: PlaceholderTy ( ty:: Placeholder {
684+ universe : reverse_universe_map[ & placeholder. universe ] ,
685+ ..placeholder
686+ } )
687+ }
688+ CanonicalVarKind :: PlaceholderRegion ( placeholder) => {
689+ CanonicalVarKind :: PlaceholderRegion ( ty:: Placeholder {
690+ universe : reverse_universe_map[ & placeholder. universe ] ,
691+ ..placeholder
692+ } )
693+ }
694+ CanonicalVarKind :: PlaceholderConst ( placeholder) => {
695+ CanonicalVarKind :: PlaceholderConst ( ty:: Placeholder {
696+ universe : reverse_universe_map[ & placeholder. universe ] ,
697+ ..placeholder
698+ } )
699+ }
722700 } )
723701 . collect ( )
724702 }
@@ -740,20 +718,17 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
740718 & mut self ,
741719 r : ty:: Region < ' tcx > ,
742720 ) -> ty:: Region < ' tcx > {
743- self . canonical_var_for_region (
744- CanonicalVarInfo { kind : CanonicalVarKind :: Region ( ty:: UniverseIndex :: ROOT ) } ,
745- r,
746- )
721+ self . canonical_var_for_region ( CanonicalVarKind :: Region ( ty:: UniverseIndex :: ROOT ) , r)
747722 }
748723
749724 /// Creates a canonical variable (with the given `info`)
750725 /// representing the region `r`; return a region referencing it.
751726 fn canonical_var_for_region (
752727 & mut self ,
753- info : CanonicalVarInfo < ' tcx > ,
728+ var_kind : CanonicalVarKind < ' tcx > ,
754729 r : ty:: Region < ' tcx > ,
755730 ) -> ty:: Region < ' tcx > {
756- let var = self . canonical_var ( info , r. into ( ) ) ;
731+ let var = self . canonical_var ( var_kind , r. into ( ) ) ;
757732 let br = ty:: BoundRegion { var, kind : ty:: BoundRegionKind :: Anon } ;
758733 ty:: Region :: new_bound ( self . cx ( ) , self . binder_index , br)
759734 }
@@ -762,9 +737,13 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
762737 /// if `ty_var` is bound to anything; if so, canonicalize
763738 /// *that*. Otherwise, create a new canonical variable for
764739 /// `ty_var`.
765- fn canonicalize_ty_var ( & mut self , info : CanonicalVarInfo < ' tcx > , ty_var : Ty < ' tcx > ) -> Ty < ' tcx > {
740+ fn canonicalize_ty_var (
741+ & mut self ,
742+ var_kind : CanonicalVarKind < ' tcx > ,
743+ ty_var : Ty < ' tcx > ,
744+ ) -> Ty < ' tcx > {
766745 debug_assert ! ( !self . infcx. is_some_and( |infcx| ty_var != infcx. shallow_resolve( ty_var) ) ) ;
767- let var = self . canonical_var ( info , ty_var. into ( ) ) ;
746+ let var = self . canonical_var ( var_kind , ty_var. into ( ) ) ;
768747 Ty :: new_bound ( self . tcx , self . binder_index , var. into ( ) )
769748 }
770749
@@ -774,13 +753,13 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
774753 /// `const_var`.
775754 fn canonicalize_const_var (
776755 & mut self ,
777- info : CanonicalVarInfo < ' tcx > ,
778- const_var : ty:: Const < ' tcx > ,
756+ var_kind : CanonicalVarKind < ' tcx > ,
757+ ct_var : ty:: Const < ' tcx > ,
779758 ) -> ty:: Const < ' tcx > {
780759 debug_assert ! (
781- !self . infcx. is_some_and( |infcx| const_var != infcx. shallow_resolve_const( const_var ) )
760+ !self . infcx. is_some_and( |infcx| ct_var != infcx. shallow_resolve_const( ct_var ) )
782761 ) ;
783- let var = self . canonical_var ( info , const_var . into ( ) ) ;
762+ let var = self . canonical_var ( var_kind , ct_var . into ( ) ) ;
784763 ty:: Const :: new_bound ( self . tcx , self . binder_index , var)
785764 }
786765}
0 commit comments