|
4 | 4 |
|
5 | 5 | pub mod tls;
|
6 | 6 |
|
| 7 | +pub use rustc_type_ir::lift::Lift; |
| 8 | + |
7 | 9 | use crate::arena::Arena;
|
8 | 10 | use crate::dep_graph::{DepGraph, DepKindStruct};
|
9 | 11 | use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos};
|
@@ -138,6 +140,19 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
138 | 140 | fn mk_canonical_var_infos(self, infos: &[ty::CanonicalVarInfo<Self>]) -> Self::CanonicalVars {
|
139 | 141 | self.mk_canonical_var_infos(infos)
|
140 | 142 | }
|
| 143 | + |
| 144 | + type GenericsOf = &'tcx ty::Generics; |
| 145 | + fn generics_of(self, def_id: DefId) -> &'tcx ty::Generics { |
| 146 | + self.generics_of(def_id) |
| 147 | + } |
| 148 | + |
| 149 | + fn check_and_mk_args( |
| 150 | + self, |
| 151 | + def_id: DefId, |
| 152 | + args: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>, |
| 153 | + ) -> ty::GenericArgsRef<'tcx> { |
| 154 | + self.check_and_mk_args(def_id, args) |
| 155 | + } |
141 | 156 | }
|
142 | 157 |
|
143 | 158 | type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
|
@@ -917,7 +932,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
917 | 932 | )
|
918 | 933 | }
|
919 | 934 |
|
920 |
| - pub fn lift<T: Lift<'tcx>>(self, value: T) -> Option<T::Lifted> { |
| 935 | + pub fn lift<T: Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> { |
921 | 936 | value.lift_to_tcx(self)
|
922 | 937 | }
|
923 | 938 |
|
@@ -1524,31 +1539,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
1524 | 1539 | }
|
1525 | 1540 | }
|
1526 | 1541 |
|
1527 |
| -/// A trait implemented for all `X<'a>` types that can be safely and |
1528 |
| -/// efficiently converted to `X<'tcx>` as long as they are part of the |
1529 |
| -/// provided `TyCtxt<'tcx>`. |
1530 |
| -/// This can be done, for example, for `Ty<'tcx>` or `GenericArgsRef<'tcx>` |
1531 |
| -/// by looking them up in their respective interners. |
1532 |
| -/// |
1533 |
| -/// However, this is still not the best implementation as it does |
1534 |
| -/// need to compare the components, even for interned values. |
1535 |
| -/// It would be more efficient if `TypedArena` provided a way to |
1536 |
| -/// determine whether the address is in the allocated range. |
1537 |
| -/// |
1538 |
| -/// `None` is returned if the value or one of the components is not part |
1539 |
| -/// of the provided context. |
1540 |
| -/// For `Ty`, `None` can be returned if either the type interner doesn't |
1541 |
| -/// contain the `TyKind` key or if the address of the interned |
1542 |
| -/// pointer differs. The latter case is possible if a primitive type, |
1543 |
| -/// e.g., `()` or `u8`, was interned in a different context. |
1544 |
| -pub trait Lift<'tcx>: fmt::Debug { |
1545 |
| - type Lifted: fmt::Debug + 'tcx; |
1546 |
| - fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted>; |
1547 |
| -} |
1548 |
| - |
1549 | 1542 | macro_rules! nop_lift {
|
1550 | 1543 | ($set:ident; $ty:ty => $lifted:ty) => {
|
1551 |
| - impl<'a, 'tcx> Lift<'tcx> for $ty { |
| 1544 | + impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for $ty { |
1552 | 1545 | type Lifted = $lifted;
|
1553 | 1546 | fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
1554 | 1547 | // Assert that the set has the right type.
|
@@ -1583,7 +1576,7 @@ macro_rules! nop_lift {
|
1583 | 1576 |
|
1584 | 1577 | macro_rules! nop_list_lift {
|
1585 | 1578 | ($set:ident; $ty:ty => $lifted:ty) => {
|
1586 |
| - impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> { |
| 1579 | + impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<$ty> { |
1587 | 1580 | type Lifted = &'tcx List<$lifted>;
|
1588 | 1581 | fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
1589 | 1582 | // Assert that the set has the right type.
|
@@ -1621,7 +1614,7 @@ nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}
|
1621 | 1614 |
|
1622 | 1615 | macro_rules! nop_slice_lift {
|
1623 | 1616 | ($ty:ty => $lifted:ty) => {
|
1624 |
| - impl<'a, 'tcx> Lift<'tcx> for &'a [$ty] { |
| 1617 | + impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a [$ty] { |
1625 | 1618 | type Lifted = &'tcx [$lifted];
|
1626 | 1619 | fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
|
1627 | 1620 | if self.is_empty() {
|
|
0 commit comments