@@ -1347,8 +1347,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1347
1347
where
1348
1348
T : TypeFoldable < ' tcx > ,
1349
1349
{
1350
- let mut r = ShallowResolver :: new ( self ) ;
1351
- value. fold_with ( & mut r)
1350
+ value. fold_with ( & mut ShallowResolver { infcx : self } )
1352
1351
}
1353
1352
1354
1353
pub fn root_var ( & self , var : ty:: TyVid ) -> ty:: TyVid {
@@ -1565,22 +1564,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
1565
1564
// variables, thus we don't need to substitute back the original values.
1566
1565
self . tcx . const_eval_resolve ( param_env, def_id, substs, promoted, span)
1567
1566
}
1568
- }
1569
-
1570
- pub struct ShallowResolver < ' a , ' tcx > {
1571
- infcx : & ' a InferCtxt < ' a , ' tcx > ,
1572
- }
1573
-
1574
- impl < ' a , ' tcx > ShallowResolver < ' a , ' tcx > {
1575
- #[ inline( always) ]
1576
- pub fn new ( infcx : & ' a InferCtxt < ' a , ' tcx > ) -> Self {
1577
- ShallowResolver { infcx }
1578
- }
1579
1567
1580
1568
/// If `typ` is a type variable of some kind, resolve it one level
1581
1569
/// (but do not resolve types found in the result). If `typ` is
1582
1570
/// not a type variable, just return it unmodified.
1583
- pub fn shallow_resolve ( & mut self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
1571
+ // FIXME(eddyb) inline into `ShallowResolver::visit_ty`.
1572
+ fn shallow_resolve_ty ( & self , typ : Ty < ' tcx > ) -> Ty < ' tcx > {
1584
1573
match typ. kind {
1585
1574
ty:: Infer ( ty:: TyVar ( v) ) => {
1586
1575
// Not entirely obvious: if `typ` is a type variable,
@@ -1594,78 +1583,80 @@ impl<'a, 'tcx> ShallowResolver<'a, 'tcx> {
1594
1583
// depth.
1595
1584
//
1596
1585
// Note: if these two lines are combined into one we get
1597
- // dynamic borrow errors on `self.infcx. inner`.
1598
- let known = self . infcx . inner . borrow_mut ( ) . type_variables . probe ( v) . known ( ) ;
1599
- known. map ( |t| self . fold_ty ( t) ) . unwrap_or ( typ)
1586
+ // dynamic borrow errors on `self.inner`.
1587
+ let known = self . inner . borrow_mut ( ) . type_variables . probe ( v) . known ( ) ;
1588
+ known. map ( |t| self . shallow_resolve_ty ( t) ) . unwrap_or ( typ)
1600
1589
}
1601
1590
1602
1591
ty:: Infer ( ty:: IntVar ( v) ) => self
1603
- . infcx
1604
1592
. inner
1605
1593
. borrow_mut ( )
1606
1594
. int_unification_table
1607
1595
. probe_value ( v)
1608
- . map ( |v| v. to_type ( self . infcx . tcx ) )
1596
+ . map ( |v| v. to_type ( self . tcx ) )
1609
1597
. unwrap_or ( typ) ,
1610
1598
1611
1599
ty:: Infer ( ty:: FloatVar ( v) ) => self
1612
- . infcx
1613
1600
. inner
1614
1601
. borrow_mut ( )
1615
1602
. float_unification_table
1616
1603
. probe_value ( v)
1617
- . map ( |v| v. to_type ( self . infcx . tcx ) )
1604
+ . map ( |v| v. to_type ( self . tcx ) )
1618
1605
. unwrap_or ( typ) ,
1619
1606
1620
1607
_ => typ,
1621
1608
}
1622
1609
}
1623
1610
1624
- // `resolver.shallow_resolve_changed(ty )` is equivalent to
1625
- // `resolver.shallow_resolve(ty) ! = ty` , but more efficient. It's always
1626
- // inlined, despite being large, because it has only two call sites that
1627
- // are extremely hot.
1611
+ /// `infer_ty_changed(infer_ty )` is equivalent to `shallow_resolve(ty) != ty`
1612
+ /// (where `ty.kind = ty::Infer(infer_ty)`) , but more efficient. It's always
1613
+ /// inlined, despite being large, because it has only two call sites that
1614
+ /// are extremely hot.
1628
1615
#[ inline( always) ]
1629
- pub fn shallow_resolve_changed ( & self , infer : ty:: InferTy ) -> bool {
1630
- match infer {
1616
+ pub fn infer_ty_changed ( & self , infer_ty : ty:: InferTy ) -> bool {
1617
+ match infer_ty {
1631
1618
ty:: TyVar ( v) => {
1632
1619
use self :: type_variable:: TypeVariableValue ;
1633
1620
1634
- // If `inlined_probe` returns a `Known` value its `kind` never
1635
- // matches `infer `.
1636
- match self . infcx . inner . borrow_mut ( ) . type_variables . inlined_probe ( v) {
1621
+ // If `inlined_probe` returns a `Known` value, it never equals
1622
+ // `ty::Infer(ty::TyVar(v)) `.
1623
+ match self . inner . borrow_mut ( ) . type_variables . inlined_probe ( v) {
1637
1624
TypeVariableValue :: Unknown { .. } => false ,
1638
1625
TypeVariableValue :: Known { .. } => true ,
1639
1626
}
1640
1627
}
1641
1628
1642
1629
ty:: IntVar ( v) => {
1643
- // If inlined_probe_value returns a value it's always a
1630
+ // If ` inlined_probe_value` returns a value it's always a
1644
1631
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
1645
1632
// `ty::Infer(_)`.
1646
- self . infcx . inner . borrow_mut ( ) . int_unification_table . inlined_probe_value ( v) . is_some ( )
1633
+ self . inner . borrow_mut ( ) . int_unification_table . inlined_probe_value ( v) . is_some ( )
1647
1634
}
1648
1635
1649
1636
ty:: FloatVar ( v) => {
1650
- // If inlined_probe_value returns a value it's always a
1637
+ // If ` inlined_probe_value` returns a value it's always a
1651
1638
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
1652
1639
//
1653
1640
// Not `inlined_probe_value(v)` because this call site is colder.
1654
- self . infcx . inner . borrow_mut ( ) . float_unification_table . probe_value ( v) . is_some ( )
1641
+ self . inner . borrow_mut ( ) . float_unification_table . probe_value ( v) . is_some ( )
1655
1642
}
1656
1643
1657
1644
_ => unreachable ! ( ) ,
1658
1645
}
1659
1646
}
1660
1647
}
1661
1648
1649
+ struct ShallowResolver < ' a , ' tcx > {
1650
+ infcx : & ' a InferCtxt < ' a , ' tcx > ,
1651
+ }
1652
+
1662
1653
impl < ' a , ' tcx > TypeFolder < ' tcx > for ShallowResolver < ' a , ' tcx > {
1663
1654
fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' tcx > {
1664
1655
self . infcx . tcx
1665
1656
}
1666
1657
1667
1658
fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
1668
- self . shallow_resolve ( ty)
1659
+ self . infcx . shallow_resolve_ty ( ty)
1669
1660
}
1670
1661
1671
1662
fn fold_const ( & mut self , ct : & ' tcx ty:: Const < ' tcx > ) -> & ' tcx ty:: Const < ' tcx > {
0 commit comments