@@ -268,7 +268,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
268268 ty:: ReVar ( vid) => {
269269 assert_eq ! (
270270 self . infcx. opportunistic_resolve_lt_var( vid) ,
271- None ,
271+ r ,
272272 "region vid should have been resolved fully before canonicalization"
273273 ) ;
274274 match self . canonicalize_mode {
@@ -302,13 +302,8 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
302302 ty:: Infer ( i) => match i {
303303 ty:: TyVar ( vid) => {
304304 assert_eq ! (
305- self . infcx. root_ty_var( vid) ,
306- vid,
307- "ty vid should have been resolved fully before canonicalization"
308- ) ;
309- assert_eq ! (
310- self . infcx. probe_ty_var( vid) ,
311- None ,
305+ self . infcx. opportunistic_resolve_ty_var( vid) ,
306+ t,
312307 "ty vid should have been resolved fully before canonicalization"
313308 ) ;
314309
@@ -318,10 +313,24 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
318313 . unwrap_or_else ( || panic ! ( "ty var should have been resolved: {t:?}" ) ) ,
319314 ) )
320315 }
321- ty:: IntVar ( _) => CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int ) ,
322- ty:: FloatVar ( _) => CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float ) ,
316+ ty:: IntVar ( vid) => {
317+ assert_eq ! (
318+ self . infcx. opportunistic_resolve_int_var( vid) ,
319+ t,
320+ "ty vid should have been resolved fully before canonicalization"
321+ ) ;
322+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Int )
323+ }
324+ ty:: FloatVar ( vid) => {
325+ assert_eq ! (
326+ self . infcx. opportunistic_resolve_float_var( vid) ,
327+ t,
328+ "ty vid should have been resolved fully before canonicalization"
329+ ) ;
330+ CanonicalVarKind :: Ty ( CanonicalTyVarKind :: Float )
331+ }
323332 ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => {
324- todo ! ( )
333+ panic ! ( "fresh vars not expected in canonicalization" )
325334 }
326335 } ,
327336 ty:: Placeholder ( placeholder) => match self . canonicalize_mode {
@@ -388,13 +397,8 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
388397 ty:: ConstKind :: Infer ( i) => match i {
389398 ty:: InferConst :: Var ( vid) => {
390399 assert_eq ! (
391- self . infcx. root_ct_var( vid) ,
392- vid,
393- "region vid should have been resolved fully before canonicalization"
394- ) ;
395- assert_eq ! (
396- self . infcx. probe_ct_var( vid) ,
397- None ,
400+ self . infcx. opportunistic_resolve_ct_var( vid, ty) ,
401+ c,
398402 "region vid should have been resolved fully before canonicalization"
399403 ) ;
400404 CanonicalVarKind :: Const ( self . infcx . universe_of_ct ( vid) . unwrap ( ) , ty)
@@ -467,3 +471,82 @@ impl<I: Interner> TypeFolder<I> for RegionsToStatic<I> {
467471 }
468472 }
469473}
474+
475+ ///////////////////////////////////////////////////////////////////////////
476+ // EAGER RESOLUTION
477+
478+ /// Resolves ty, region, and const vars to their inferred values or their root vars.
479+ pub struct EagerResolver <
480+ ' a ,
481+ Infcx : InferCtxtLike < Interner = I > ,
482+ I : Interner = <Infcx as InferCtxtLike >:: Interner ,
483+ > {
484+ infcx : & ' a Infcx ,
485+ }
486+
487+ impl < ' a , Infcx : InferCtxtLike > EagerResolver < ' a , Infcx > {
488+ pub fn new ( infcx : & ' a Infcx ) -> Self {
489+ EagerResolver { infcx }
490+ }
491+ }
492+
493+ impl < Infcx : InferCtxtLike < Interner = I > , I : Interner > TypeFolder < I > for EagerResolver < ' _ , Infcx > {
494+ fn interner ( & self ) -> I {
495+ self . infcx . interner ( )
496+ }
497+
498+ fn fold_ty ( & mut self , t : I :: Ty ) -> I :: Ty {
499+ match t. kind ( ) {
500+ ty:: Infer ( ty:: TyVar ( vid) ) => {
501+ let resolved = self . infcx . opportunistic_resolve_ty_var ( vid) ;
502+ if t != resolved && resolved. has_infer ( ) {
503+ resolved. super_fold_with ( self )
504+ } else {
505+ resolved
506+ }
507+ }
508+ ty:: Infer ( ty:: IntVar ( vid) ) => self . infcx . opportunistic_resolve_int_var ( vid) ,
509+ ty:: Infer ( ty:: FloatVar ( vid) ) => self . infcx . opportunistic_resolve_float_var ( vid) ,
510+ _ => {
511+ if t. has_infer ( ) {
512+ t. super_fold_with ( self )
513+ } else {
514+ t
515+ }
516+ }
517+ }
518+ }
519+
520+ fn fold_region ( & mut self , r : I :: Region ) -> I :: Region {
521+ match r. kind ( ) {
522+ ty:: ReVar ( vid) => self . infcx . opportunistic_resolve_lt_var ( vid) ,
523+ _ => r,
524+ }
525+ }
526+
527+ fn fold_const ( & mut self , c : I :: Const ) -> I :: Const {
528+ match c. kind ( ) {
529+ ty:: ConstKind :: Infer ( ty:: InferConst :: Var ( vid) ) => {
530+ let ty = c. ty ( ) . fold_with ( self ) ;
531+ let resolved = self . infcx . opportunistic_resolve_ct_var ( vid, ty) ;
532+ if c != resolved && resolved. has_infer ( ) {
533+ resolved. super_fold_with ( self )
534+ } else {
535+ resolved
536+ }
537+ }
538+ ty:: ConstKind :: Infer ( ty:: InferConst :: EffectVar ( vid) ) => {
539+ let bool = Ty :: new_bool ( self . infcx . interner ( ) ) ;
540+ debug_assert_eq ! ( c. ty( ) , bool ) ;
541+ self . infcx . opportunistic_resolve_effect_var ( vid, bool)
542+ }
543+ _ => {
544+ if c. has_infer ( ) {
545+ c. super_fold_with ( self )
546+ } else {
547+ c
548+ }
549+ }
550+ }
551+ }
552+ }
0 commit comments