@@ -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 ;
@@ -811,13 +811,13 @@ impl<'tcx> InferCtxt<'tcx> {
811
811
vars. extend (
812
812
( 0 ..inner. int_unification_table ( ) . len ( ) )
813
813
. map ( |i| ty:: IntVid :: from_u32 ( i as u32 ) )
814
- . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_none ( ) )
814
+ . filter ( |& vid| inner. int_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
815
815
. map ( |v| Ty :: new_int_var ( self . tcx , v) ) ,
816
816
) ;
817
817
vars. extend (
818
818
( 0 ..inner. float_unification_table ( ) . len ( ) )
819
819
. map ( |i| ty:: FloatVid :: from_u32 ( i as u32 ) )
820
- . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_none ( ) )
820
+ . filter ( |& vid| inner. float_unification_table ( ) . probe_value ( vid) . is_unknown ( ) )
821
821
. map ( |v| Ty :: new_float_var ( self . tcx , v) ) ,
822
822
) ;
823
823
vars
@@ -1025,14 +1025,28 @@ impl<'tcx> InferCtxt<'tcx> {
1025
1025
ty:: Const :: new_var ( self . tcx , vid, ty)
1026
1026
}
1027
1027
1028
+ pub fn next_const_var_id ( & self , origin : ConstVariableOrigin ) -> ConstVid {
1029
+ self . inner
1030
+ . borrow_mut ( )
1031
+ . const_unification_table ( )
1032
+ . new_key ( ConstVariableValue :: Unknown { origin, universe : self . universe ( ) } )
1033
+ . vid
1034
+ }
1035
+
1036
+ fn next_int_var_id ( & self ) -> IntVid {
1037
+ self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( ty:: IntVarValue :: Unknown )
1038
+ }
1039
+
1028
1040
pub fn next_int_var ( & self ) -> Ty < ' tcx > {
1029
- let vid = self . inner . borrow_mut ( ) . int_unification_table ( ) . new_key ( None ) ;
1030
- Ty :: new_int_var ( self . tcx , vid)
1041
+ Ty :: new_int_var ( self . tcx , self . next_int_var_id ( ) )
1042
+ }
1043
+
1044
+ fn next_float_var_id ( & self ) -> FloatVid {
1045
+ self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( ty:: FloatVarValue :: Unknown )
1031
1046
}
1032
1047
1033
1048
pub fn next_float_var ( & self ) -> Ty < ' tcx > {
1034
- let vid = self . inner . borrow_mut ( ) . float_unification_table ( ) . new_key ( None ) ;
1035
- Ty :: new_float_var ( self . tcx , vid)
1049
+ Ty :: new_float_var ( self . tcx , self . next_float_var_id ( ) )
1036
1050
}
1037
1051
1038
1052
/// Creates a fresh region variable with the next available index.
@@ -1234,45 +1248,44 @@ impl<'tcx> InferCtxt<'tcx> {
1234
1248
}
1235
1249
1236
1250
pub fn shallow_resolve ( & self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1237
- if let ty:: Infer ( v) = ty. kind ( ) { self . fold_infer_ty ( * v) . unwrap_or ( ty) } else { ty }
1238
- }
1239
-
1240
- // This is separate from `shallow_resolve` to keep that method small and inlinable.
1241
- #[ inline( never) ]
1242
- fn fold_infer_ty ( & self , v : InferTy ) -> Option < Ty < ' tcx > > {
1243
- match v {
1244
- ty:: TyVar ( v) => {
1245
- // Not entirely obvious: if `typ` is a type variable,
1246
- // it can be resolved to an int/float variable, which
1247
- // can then be recursively resolved, hence the
1248
- // recursion. Note though that we prevent type
1249
- // variables from unifying to other type variables
1250
- // directly (though they may be embedded
1251
- // structurally), and we prevent cycles in any case,
1252
- // so this recursion should always be of very limited
1253
- // depth.
1254
- //
1255
- // Note: if these two lines are combined into one we get
1256
- // dynamic borrow errors on `self.inner`.
1257
- let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1258
- known. map ( |t| self . shallow_resolve ( t) )
1259
- }
1251
+ if let ty:: Infer ( v) = * ty. kind ( ) {
1252
+ match v {
1253
+ ty:: TyVar ( v) => {
1254
+ // Not entirely obvious: if `typ` is a type variable,
1255
+ // it can be resolved to an int/float variable, which
1256
+ // can then be recursively resolved, hence the
1257
+ // recursion. Note though that we prevent type
1258
+ // variables from unifying to other type variables
1259
+ // directly (though they may be embedded
1260
+ // structurally), and we prevent cycles in any case,
1261
+ // so this recursion should always be of very limited
1262
+ // depth.
1263
+ //
1264
+ // Note: if these two lines are combined into one we get
1265
+ // dynamic borrow errors on `self.inner`.
1266
+ let known = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( v) . known ( ) ;
1267
+ known. map_or ( ty, |t| self . shallow_resolve ( t) )
1268
+ }
1269
+
1270
+ ty:: IntVar ( v) => {
1271
+ match self . inner . borrow_mut ( ) . int_unification_table ( ) . probe_value ( v) {
1272
+ ty:: IntVarValue :: Unknown => ty,
1273
+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1274
+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1275
+ }
1276
+ }
1260
1277
1261
- ty:: IntVar ( v) => self
1262
- . inner
1263
- . borrow_mut ( )
1264
- . int_unification_table ( )
1265
- . probe_value ( v)
1266
- . map ( |v| v. to_type ( self . tcx ) ) ,
1267
-
1268
- ty:: FloatVar ( v) => self
1269
- . inner
1270
- . borrow_mut ( )
1271
- . float_unification_table ( )
1272
- . probe_value ( v)
1273
- . map ( |v| v. to_type ( self . tcx ) ) ,
1274
-
1275
- ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => None ,
1278
+ ty:: FloatVar ( v) => {
1279
+ match self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) {
1280
+ ty:: FloatVarValue :: Unknown => ty,
1281
+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1282
+ }
1283
+ }
1284
+
1285
+ ty:: FreshTy ( _) | ty:: FreshIntTy ( _) | ty:: FreshFloatTy ( _) => ty,
1286
+ }
1287
+ } else {
1288
+ ty
1276
1289
}
1277
1290
}
1278
1291
@@ -1321,21 +1334,26 @@ impl<'tcx> InferCtxt<'tcx> {
1321
1334
/// or else the root int var in the unification table.
1322
1335
pub fn opportunistic_resolve_int_var ( & self , vid : ty:: IntVid ) -> Ty < ' tcx > {
1323
1336
let mut inner = self . inner . borrow_mut ( ) ;
1324
- if let Some ( value) = inner. int_unification_table ( ) . probe_value ( vid) {
1325
- value. to_type ( self . tcx )
1326
- } else {
1327
- Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1337
+ let value = inner. int_unification_table ( ) . probe_value ( vid) ;
1338
+ match value {
1339
+ ty:: IntVarValue :: IntType ( ty) => Ty :: new_int ( self . tcx , ty) ,
1340
+ ty:: IntVarValue :: UintType ( ty) => Ty :: new_uint ( self . tcx , ty) ,
1341
+ ty:: IntVarValue :: Unknown => {
1342
+ Ty :: new_int_var ( self . tcx , inner. int_unification_table ( ) . find ( vid) )
1343
+ }
1328
1344
}
1329
1345
}
1330
1346
1331
1347
/// Resolves a float var to a rigid int type, if it was constrained to one,
1332
1348
/// or else the root float var in the unification table.
1333
1349
pub fn opportunistic_resolve_float_var ( & self , vid : ty:: FloatVid ) -> Ty < ' tcx > {
1334
1350
let mut inner = self . inner . borrow_mut ( ) ;
1335
- if let Some ( value) = inner. float_unification_table ( ) . probe_value ( vid) {
1336
- value. to_type ( self . tcx )
1337
- } else {
1338
- Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1351
+ let value = inner. float_unification_table ( ) . probe_value ( vid) ;
1352
+ match value {
1353
+ ty:: FloatVarValue :: Known ( ty) => Ty :: new_float ( self . tcx , ty) ,
1354
+ ty:: FloatVarValue :: Unknown => {
1355
+ Ty :: new_float_var ( self . tcx , inner. float_unification_table ( ) . find ( vid) )
1356
+ }
1339
1357
}
1340
1358
}
1341
1359
@@ -1626,15 +1644,15 @@ impl<'tcx> InferCtxt<'tcx> {
1626
1644
// If `inlined_probe_value` returns a value it's always a
1627
1645
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
1628
1646
// `ty::Infer(_)`.
1629
- self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_some ( )
1647
+ ! self . inner . borrow_mut ( ) . int_unification_table ( ) . inlined_probe_value ( v) . is_unknown ( )
1630
1648
}
1631
1649
1632
1650
TyOrConstInferVar :: TyFloat ( v) => {
1633
1651
// If `probe_value` returns a value it's always a
1634
1652
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
1635
1653
//
1636
1654
// Not `inlined_probe_value(v)` because this call site is colder.
1637
- self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_some ( )
1655
+ ! self . inner . borrow_mut ( ) . float_unification_table ( ) . probe_value ( v) . is_unknown ( )
1638
1656
}
1639
1657
1640
1658
TyOrConstInferVar :: Const ( v) => {
0 commit comments