@@ -1211,8 +1211,29 @@ impl<'tcx> InferCtxt<'tcx> {
12111211 self . deep_resolve_non_region_vars ( t) . to_string ( )
12121212 }
12131213
1214- /// If `TyVar(vid)` resolves to a type, return that type. Else, return the
1215- /// universe index of `TyVar(vid)`.
1214+ /// If `TyVar(vid)` resolves to a type, return that type.
1215+ /// Else, return the universe index of `TyVar(vid)`.
1216+ ///
1217+ /// Also return the root `TyVid` of `vid`.
1218+ /// This is more efficient than calling [`try_resolve_ty_var`](Self::try_resolve_ty_var)
1219+ /// followed by [`root_ty_var`](Self::root_ty_var).
1220+ pub fn try_resolve_ty_var_with_root (
1221+ & self ,
1222+ vid : TyVid ,
1223+ ) -> ( Result < Ty < ' tcx > , ty:: UniverseIndex > , TyVid ) {
1224+ let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1225+
1226+ (
1227+ match value {
1228+ TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1229+ TypeVariableValue :: Unknown { universe } => Err ( universe) ,
1230+ } ,
1231+ root,
1232+ )
1233+ }
1234+
1235+ /// If `TyVar(vid)` resolves to a type, return that type.
1236+ /// Else, return the universe index of `TyVar(vid)`.
12161237 pub fn try_resolve_ty_var ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , ty:: UniverseIndex > {
12171238 let value = self . inner . borrow_mut ( ) . type_variables ( ) . probe ( vid) ;
12181239
@@ -1224,12 +1245,8 @@ impl<'tcx> InferCtxt<'tcx> {
12241245
12251246 /// If `vid` resolves to a type, return that type. Otherwise return the root variable id for `vid`.
12261247 pub fn shallow_resolve_ty_var_or_get_root ( & self , vid : TyVid ) -> Result < Ty < ' tcx > , TyVid > {
1227- let ( root, value) = self . inner . borrow_mut ( ) . type_variables ( ) . probe_with_root_vid ( vid) ;
1228-
1229- match value {
1230- TypeVariableValue :: Known { value } => Ok ( self . shallow_resolve_non_recursive ( value) ) ,
1231- TypeVariableValue :: Unknown { universe : _ } => Err ( root) ,
1232- }
1248+ let ( res, root) = self . try_resolve_ty_var_with_root ( vid) ;
1249+ res. map_err ( |_| root)
12331250 }
12341251
12351252 /// Resolve a type variable to a type, if known.
@@ -1430,7 +1447,7 @@ impl<'tcx> InferCtxt<'tcx> {
14301447 }
14311448 }
14321449
1433- pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
1450+ pub fn root_ty_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
14341451 self . inner . borrow_mut ( ) . type_variables ( ) . root_var ( var)
14351452 }
14361453
@@ -1513,6 +1530,29 @@ impl<'tcx> InferCtxt<'tcx> {
15131530 value. fold_with ( & mut r)
15141531 }
15151532
1533+ /// If `ConstVar(vid)` resolves to a const, return that const.
1534+ /// Else, return the universe index of `ConstVar(vid)`.
1535+ ///
1536+ /// Also return the root `ConstVid` of `vid`.
1537+ /// This is more efficient than calling [`try_resolve_const_var`](Self::try_resolve_const_var)
1538+ /// followed by [`root_const_var`](Self::root_const_var).
1539+ pub fn try_resolve_const_var_with_root (
1540+ & self ,
1541+ vid : ty:: ConstVid ,
1542+ ) -> ( Result < ty:: Const < ' tcx > , ty:: UniverseIndex > , ty:: ConstVid ) {
1543+ let ( root, value) =
1544+ self . inner . borrow_mut ( ) . const_unification_table ( ) . inlined_probe_key_value ( vid) ;
1545+ (
1546+ match value {
1547+ ConstVariableValue :: Known { value } => Ok ( value) ,
1548+ ConstVariableValue :: Unknown { origin : _, universe } => Err ( universe) ,
1549+ } ,
1550+ root. vid ,
1551+ )
1552+ }
1553+
1554+ /// If `ConstVar(vid)` resolves to a const, return that const.
1555+ /// Else, return the universe index of `ConstVar(vid)`.
15161556 pub fn try_resolve_const_var (
15171557 & self ,
15181558 vid : ty:: ConstVid ,
0 commit comments