@@ -29,9 +29,9 @@ use rustc_errors::{Diag, DiagCtxt, ErrorGuaranteed};
29
29
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
30
30
use rustc_macros:: extension;
31
31
use rustc_middle:: infer:: canonical:: { Canonical , CanonicalVarValues } ;
32
+ use rustc_middle:: infer:: unify_key:: ConstVariableOrigin ;
32
33
use rustc_middle:: infer:: unify_key:: ConstVariableValue ;
33
34
use rustc_middle:: infer:: unify_key:: EffectVarValue ;
34
- use rustc_middle:: infer:: unify_key:: { ConstVariableOrigin , ToType } ;
35
35
use rustc_middle:: infer:: unify_key:: { ConstVidKey , EffectVidKey } ;
36
36
use rustc_middle:: mir:: interpret:: { ErrorHandled , EvalToValTreeResult } ;
37
37
use rustc_middle:: mir:: ConstraintCategory ;
@@ -41,7 +41,7 @@ use rustc_middle::ty::fold::BoundVarReplacerDelegate;
41
41
use rustc_middle:: ty:: fold:: { TypeFoldable , TypeFolder , TypeSuperFoldable } ;
42
42
use rustc_middle:: ty:: relate:: RelateResult ;
43
43
use 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 } ;
45
45
use rustc_middle:: ty:: { ConstVid , EffectVid , FloatVid , IntVid , TyVid } ;
46
46
use rustc_middle:: ty:: { GenericArg , GenericArgKind , GenericArgs , GenericArgsRef } ;
47
47
use rustc_middle:: { bug, span_bug} ;
@@ -813,13 +813,13 @@ impl<'tcx> InferCtxt<'tcx> {
813
813
vars. extend (
814
814
( 0 ..inner. int_unification_table ( ) . len ( ) )
815
815
. 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 ( ) )
817
817
. map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
818
818
) ;
819
819
vars. extend (
820
820
( 0 ..inner. float_unification_table ( ) . len ( ) )
821
821
. 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 ( ) )
823
823
. map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
824
824
) ;
825
825
vars
@@ -1027,14 +1027,28 @@ impl<'tcx> InferCtxt<'tcx> {
1027
1027
ty:: Const :: new_var ( self . tcx , vid, ty)
1028
1028
}
1029
1029
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
+
1030
1042
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 )
1033
1048
}
1034
1049
1035
1050
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 ( ) )
1038
1052
}
1039
1053
1040
1054
/// Creates a fresh region variable with the next available index.
@@ -1236,45 +1250,44 @@ impl<'tcx> InferCtxt<'tcx> {
1236
1250
}
1237
1251
1238
1252
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
+ }
1262
1279
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
1278
1291
}
1279
1292
}
1280
1293
@@ -1323,21 +1336,26 @@ impl<'tcx> InferCtxt<'tcx> {
1323
1336
/// or else the root int var in the unification table.
1324
1337
pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
1325
1338
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
+ }
1330
1346
}
1331
1347
}
1332
1348
1333
1349
/// Resolves a float var to a rigid int type, if it was constrained to one,
1334
1350
/// or else the root float var in the unification table.
1335
1351
pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
1336
1352
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
+ }
1341
1359
}
1342
1360
}
1343
1361
@@ -1628,15 +1646,15 @@ impl<'tcx> InferCtxt<'tcx> {
1628
1646
// If `inlined_probe_value` returns a value it's always a
1629
1647
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
1630
1648
// `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 ( )
1632
1650
}
1633
1651
1634
1652
TyOrConstInferVar :: TyFloat ( v) => {
1635
1653
// If `probe_value` returns a value it's always a
1636
1654
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
1637
1655
//
1638
1656
// 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 ( )
1640
1658
}
1641
1659
1642
1660
TyOrConstInferVar :: Const ( v) => {
0 commit comments