@@ -29,9 +29,9 @@ use rustc_errors::{Diag, DiagCtxt, ErrorGuaranteed};
2929use rustc_hir:: def_id:: { DefId , LocalDefId } ;
3030use rustc_macros:: extension;
3131use rustc_middle:: infer:: canonical:: { Canonical , CanonicalVarValues } ;
32+ use rustc_middle:: infer:: unify_key:: ConstVariableOrigin ;
3233use rustc_middle:: infer:: unify_key:: ConstVariableValue ;
3334use rustc_middle:: infer:: unify_key:: EffectVarValue ;
34- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ToType } ;
3535use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
3636use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
3737use rustc_middle:: mir:: ConstraintCategory ;
@@ -41,7 +41,7 @@ use rustc_middle::ty::fold::BoundVarReplacerDelegate;
4141use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
4242use rustc_middle:: ty:: relate:: RelateResult ;
4343use rustc_middle:: ty:: visit:: TypeVisitableExt ;
44- use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , InferTy , Ty , TyCtxt } ;
44+ use rustc_middle:: ty:: { self , GenericParamDefKind , InferConst , Ty , TyCtxt } ;
4545use rustc_middle:: ty:: { ConstVid , EffectVid , FloatVid , IntVid , TyVid } ;
4646use rustc_middle:: ty:: { GenericArg , GenericArgKind , GenericArgs , GenericArgsRef } ;
4747use rustc_middle:: { bug, span_bug} ;
@@ -813,13 +813,13 @@ impl<'tcx> InferCtxt<'tcx> {
813813 vars. extend (
814814 ( 0 ..inner. int_unification_table ( ) . len ( ) )
815815 . map ( |i| ty:: IntVid :: from_u32 ( i as u32 ) )
816- . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_none ( ) )
816+ . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
817817 . map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
818818 ) ;
819819 vars. extend (
820820 ( 0 ..inner. float_unification_table ( ) . len ( ) )
821821 . map ( |i| ty:: FloatVid :: from_u32 ( i as u32 ) )
822- . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_none ( ) )
822+ . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
823823 . map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
824824 ) ;
825825 vars
@@ -1027,14 +1027,28 @@ impl<'tcx> InferCtxt<'tcx> {
10271027 ty:: Const :: new_var ( self . tcx , vid, ty)
10281028 }
10291029
1030+ pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
1031+ self . inner
1032+ . borrow_mut ( )
1033+ . const_unification_table ( )
1034+ . new_key ( ConstVariableValue :: Unknown { origin, universe : self . universe ( ) } )
1035+ . vid
1036+ }
1037+
1038+ fn next_int_var_id ( & self ) -> IntVid {
1039+ self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown )
1040+ }
1041+
10301042 pub fn next_int_var ( & self ) -> Ty < ' tcx > {
1031- let vid = self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( None ) ;
1032- Ty :: new_int_var ( self . tcx , vid)
1043+ Ty :: new_int_var ( self . tcx , self . next_int_var_id ( ) )
1044+ }
1045+
1046+ fn next_float_var_id ( & self ) -> FloatVid {
1047+ self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown )
10331048 }
10341049
10351050 pub fn next_float_var ( & self ) -> Ty < ' tcx > {
1036- let vid = self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( None ) ;
1037- Ty :: new_float_var ( self . tcx , vid)
1051+ Ty :: new_float_var ( self . tcx , self . next_float_var_id ( ) )
10381052 }
10391053
10401054 /// Creates a fresh region variable with the next available index.
@@ -1236,45 +1250,44 @@ impl<'tcx> InferCtxt<'tcx> {
12361250 }
12371251
12381252 pub fn shallow_resolve ( & self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1239- if let ty:: Infer ( v) = ty. kind ( ) { self . fold_infer_ty ( * v) . unwrap_or ( ty) } else { ty }
1240- }
1241-
1242- // This is separate from `shallow_resolve` to keep that method small and inlinable.
1243- #[ inline( never) ]
1244- fn fold_infer_ty ( & self , v : InferTy ) -> Option < Ty < ' tcx > > {
1245- match v {
1246- ty:: TyVar ( v) => {
1247- // Not entirely obvious: if `typ` is a type variable,
1248- // it can be resolved to an int/float variable, which
1249- // can then be recursively resolved, hence the
1250- // recursion. Note though that we prevent type
1251- // variables from unifying to other type variables
1252- // directly (though they may be embedded
1253- // structurally), and we prevent cycles in any case,
1254- // so this recursion should always be of very limited
1255- // depth.
1256- //
1257- // Note: if these two lines are combined into one we get
1258- // dynamic borrow errors on `self.inner`.
1259- let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1260- known. map ( |t| self . shallow_resolve ( t) )
1261- }
1253+ if let ty:: Infer ( v) = * ty. kind ( ) {
1254+ match v {
1255+ ty:: TyVar ( v) => {
1256+ // Not entirely obvious: if `typ` is a type variable,
1257+ // it can be resolved to an int/float variable, which
1258+ // can then be recursively resolved, hence the
1259+ // recursion. Note though that we prevent type
1260+ // variables from unifying to other type variables
1261+ // directly (though they may be embedded
1262+ // structurally), and we prevent cycles in any case,
1263+ // so this recursion should always be of very limited
1264+ // depth.
1265+ //
1266+ // Note: if these two lines are combined into one we get
1267+ // dynamic borrow errors on `self.inner`.
1268+ let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1269+ known. map_or ( ty, |t| self . shallow_resolve ( t) )
1270+ }
1271+
1272+ ty:: IntVar ( v) => {
1273+ match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1274+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1275+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1276+ ty:: IntVarValue :: Unknown => ty,
1277+ }
1278+ }
12621279
1263- ty:: IntVar ( v) => self
1264- . inner
1265- . borrow_mut ( )
1266- . int_unification_table ( )
1267- . probe_value ( v)
1268- . map ( |v| v. to_type ( self . tcx ) ) ,
1269-
1270- ty:: FloatVar ( v) => self
1271- . inner
1272- . borrow_mut ( )
1273- . float_unification_table ( )
1274- . probe_value ( v)
1275- . map ( |v| v. to_type ( self . tcx ) ) ,
1276-
1277- ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
1280+ ty:: FloatVar ( v) => {
1281+ match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) {
1282+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1283+ ty:: FloatVarValue :: Unknown => ty,
1284+ }
1285+ }
1286+
1287+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => ty,
1288+ }
1289+ } else {
1290+ ty
12781291 }
12791292 }
12801293
@@ -1323,21 +1336,26 @@ impl<'tcx> InferCtxt<'tcx> {
13231336 /// or else the root int var in the unification table.
13241337 pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
13251338 let mut inner = self . inner . borrow_mut ( ) ;
1326- if let Some ( value) = inner. int_unification_table ( ) . probe_value ( vid) {
1327- value. to_type ( self . tcx )
1328- } else {
1329- Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1339+ let value = inner. int_unification_table ( ) . probe_value ( vid) ;
1340+ match value {
1341+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1342+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1343+ ty:: IntVarValue :: Unknown => {
1344+ Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1345+ }
13301346 }
13311347 }
13321348
13331349 /// Resolves a float var to a rigid int type, if it was constrained to one,
13341350 /// or else the root float var in the unification table.
13351351 pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
13361352 let mut inner = self . inner . borrow_mut ( ) ;
1337- if let Some ( value) = inner. float_unification_table ( ) . probe_value ( vid) {
1338- value. to_type ( self . tcx )
1339- } else {
1340- Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1353+ let value = inner. float_unification_table ( ) . probe_value ( vid) ;
1354+ match value {
1355+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1356+ ty:: FloatVarValue :: Unknown => {
1357+ Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1358+ }
13411359 }
13421360 }
13431361
@@ -1628,15 +1646,15 @@ impl<'tcx> InferCtxt<'tcx> {
16281646 // If `inlined_probe_value` returns a value it's always a
16291647 // `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16301648 // `ty::Infer(_)`.
1631- self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_some ( )
1649+ self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_known ( )
16321650 }
16331651
16341652 TyOrConstInferVar :: TyFloat ( v) => {
16351653 // If `probe_value` returns a value it's always a
16361654 // `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16371655 //
16381656 // Not `inlined_probe_value(v)` because this call site is colder.
1639- self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_some ( )
1657+ self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_known ( )
16401658 }
16411659
16421660 TyOrConstInferVar :: Const ( v) => {
0 commit comments