@@ -1222,8 +1222,29 @@ impl<'tcx> InferCtxt<'tcx> {
12221222 self . deeply_resolve_ignoring_regions ( t) . to_string ( )
12231223 }
12241224
1225- /// If `TyVar(vid)` resolves to a type, return that type. Else, return the
1226- /// universe index of `TyVar(vid)`.
1225+ /// If `TyVar(vid)` resolves to a type, return that type.
1226+ /// Else, return the universe index of `TyVar(vid)`.
1227+ ///
1228+ /// Also return the root `TyVid` of `vid`.
1229+ /// This is more efficient than calling [`try_resolve_ty_var`](Self::try_resolve_ty_var)
1230+ /// followed by [`root_ty_var`](Self::root_ty_var).
1231+ pub fn try_resolve_ty_var_with_root (
1232+ & self ,
1233+ vid : TyVid ,
1234+ ) -> ( Result < Ty < ' tcx > , ty:: UniverseIndex > , TyVid ) {
1235+ let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1236+
1237+ (
1238+ match value {
1239+ TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1240+ TypeVariableValue :: Unknown { universe } => Err ( universe) ,
1241+ } ,
1242+ root,
1243+ )
1244+ }
1245+
1246+ /// If `TyVar(vid)` resolves to a type, return that type.
1247+ /// Else, return the universe index of `TyVar(vid)`.
12271248 pub fn try_resolve_ty_var ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , ty:: UniverseIndex > {
12281249 let value = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( vid) ;
12291250
@@ -1235,12 +1256,8 @@ impl<'tcx> InferCtxt<'tcx> {
12351256
12361257 /// If `vid` resolves to a type, return that type. Otherwise return the root variable id for `vid`.
12371258 pub fn shallow_resolve_ty_var_or_get_root ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , TyVid > {
1238- let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1239-
1240- match value {
1241- TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1242- TypeVariableValue :: Unknown { universe : _ } => Err ( root) ,
1243- }
1259+ let ( res, root) = self . try_resolve_ty_var_with_root ( vid) ;
1260+ res. map_err ( |_| root)
12441261 }
12451262
12461263 /// Resolve a type variable to a type, if known.
@@ -1441,7 +1458,7 @@ impl<'tcx> InferCtxt<'tcx> {
14411458 }
14421459 }
14431460
1444- pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
1461+ pub fn root_ty_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
14451462 self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
14461463 }
14471464
@@ -1524,6 +1541,29 @@ impl<'tcx> InferCtxt<'tcx> {
15241541 value. fold_with ( & mut r)
15251542 }
15261543
1544+ /// If `ConstVar(vid)` resolves to a const, return that const.
1545+ /// Else, return the universe index of `ConstVar(vid)`.
1546+ ///
1547+ /// Also return the root `ConstVid` of `vid`.
1548+ /// This is more efficient than calling [`try_resolve_const_var`](Self::try_resolve_const_var)
1549+ /// followed by [`root_const_var`](Self::root_const_var).
1550+ pub fn try_resolve_const_var_with_root (
1551+ & self ,
1552+ vid : ty:: ConstVid ,
1553+ ) -> ( Result < ty:: Const < ' tcx > , ty:: UniverseIndex > , ty:: ConstVid ) {
1554+ let ( root, value) =
1555+ self . inner . borrow_mut ( ) . const_unification_table ( ) . inlined_probe_key_value ( vid) ;
1556+ (
1557+ match value {
1558+ ConstVariableValue :: Known { value } => Ok ( value) ,
1559+ ConstVariableValue :: Unknown { origin : _, universe } => Err ( universe) ,
1560+ } ,
1561+ root. vid ,
1562+ )
1563+ }
1564+
1565+ /// If `ConstVar(vid)` resolves to a const, return that const.
1566+ /// Else, return the universe index of `ConstVar(vid)`.
15271567 pub fn try_resolve_const_var (
15281568 & self ,
15291569 vid : ty:: ConstVid ,
0 commit comments