Skip to content

Commit 5e606c0

Browse files
Lift Lift
1 parent 6a19a87 commit 5e606c0

File tree

8 files changed

+17
-33
lines changed

8 files changed

+17
-33
lines changed

compiler/rustc_macros/src/lift.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn lift_derive(mut s: synstructure::Structure<'_>) -> proc_macro2::TokenStre
4141

4242
s.add_impl_generic(newtcx);
4343
s.bound_impl(
44-
quote!(::rustc_middle::ty::Lift<'__lifted>),
44+
quote!(::rustc_middle::ty::Lift<::rustc_middle::ty::TyCtxt<'__lifted>>),
4545
quote! {
4646
type Lifted = #lifted;
4747

compiler/rustc_middle/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ macro_rules! span_bug {
5757
macro_rules! TrivialLiftImpls {
5858
($($ty:ty),+ $(,)?) => {
5959
$(
60-
impl<'tcx> $crate::ty::Lift<'tcx> for $ty {
60+
impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
6161
type Lifted = Self;
6262
fn lift_to_tcx(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
6363
Some(self)

compiler/rustc_middle/src/ty/context.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
pub mod tls;
66

7+
pub use rustc_type_ir::lift::Lift;
8+
79
use crate::arena::Arena;
810
use crate::dep_graph::{DepGraph, DepKindStruct};
911
use crate::infer::canonical::{CanonicalParamEnvCache, CanonicalVarInfo, CanonicalVarInfos};
@@ -917,7 +919,7 @@ impl<'tcx> TyCtxt<'tcx> {
917919
)
918920
}
919921

920-
pub fn lift<T: Lift<'tcx>>(self, value: T) -> Option<T::Lifted> {
922+
pub fn lift<T: Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> {
921923
value.lift_to_tcx(self)
922924
}
923925

@@ -1524,31 +1526,9 @@ impl<'tcx> TyCtxt<'tcx> {
15241526
}
15251527
}
15261528

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-
15491529
macro_rules! nop_lift {
15501530
($set:ident; $ty:ty => $lifted:ty) => {
1551-
impl<'a, 'tcx> Lift<'tcx> for $ty {
1531+
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for $ty {
15521532
type Lifted = $lifted;
15531533
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
15541534
// Assert that the set has the right type.
@@ -1583,7 +1563,7 @@ macro_rules! nop_lift {
15831563

15841564
macro_rules! nop_list_lift {
15851565
($set:ident; $ty:ty => $lifted:ty) => {
1586-
impl<'a, 'tcx> Lift<'tcx> for &'a List<$ty> {
1566+
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<$ty> {
15871567
type Lifted = &'tcx List<$lifted>;
15881568
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
15891569
// Assert that the set has the right type.
@@ -1621,7 +1601,7 @@ nop_list_lift! {args; GenericArg<'a> => GenericArg<'tcx>}
16211601

16221602
macro_rules! nop_slice_lift {
16231603
($ty:ty => $lifted:ty) => {
1624-
impl<'a, 'tcx> Lift<'tcx> for &'a [$ty] {
1604+
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a [$ty] {
16251605
type Lifted = &'tcx [$lifted];
16261606
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
16271607
if self.is_empty() {

compiler/rustc_middle/src/ty/generic_args.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<'tcx> GenericArg<'tcx> {
205205
}
206206
}
207207

208-
impl<'a, 'tcx> Lift<'tcx> for GenericArg<'a> {
208+
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for GenericArg<'a> {
209209
type Lifted = GenericArg<'tcx>;
210210

211211
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {

compiler/rustc_middle/src/ty/structural_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ TrivialTypeTraversalAndLiftImpls! {
478478
///////////////////////////////////////////////////////////////////////////
479479
// Lift implementations
480480

481-
impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
481+
impl<'tcx, T: Lift<TyCtxt<'tcx>>> Lift<TyCtxt<'tcx>> for Option<T> {
482482
type Lifted = Option<T::Lifted>;
483483
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
484484
Some(match self {
@@ -488,7 +488,7 @@ impl<'tcx, T: Lift<'tcx>> Lift<'tcx> for Option<T> {
488488
}
489489
}
490490

491-
impl<'a, 'tcx> Lift<'tcx> for Term<'a> {
491+
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for Term<'a> {
492492
type Lifted = ty::Term<'tcx>;
493493
fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
494494
Some(

compiler/rustc_trait_selection/src/traits/query/type_op/normalize.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ where
3434
}
3535
}
3636

37-
pub trait Normalizable<'tcx>: fmt::Debug + TypeFoldable<TyCtxt<'tcx>> + Lift<'tcx> + Copy {
37+
pub trait Normalizable<'tcx>:
38+
fmt::Debug + TypeFoldable<TyCtxt<'tcx>> + Lift<TyCtxt<'tcx>> + Copy
39+
{
3840
fn type_op_method(
3941
tcx: TyCtxt<'tcx>,
4042
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Normalize<Self>>>,

compiler/rustc_traits/src/type_op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn type_op_normalize<'tcx, T>(
5454
key: ParamEnvAnd<'tcx, Normalize<T>>,
5555
) -> Result<T, NoSolution>
5656
where
57-
T: fmt::Debug + TypeFoldable<TyCtxt<'tcx>> + Lift<'tcx>,
57+
T: fmt::Debug + TypeFoldable<TyCtxt<'tcx>>,
5858
{
5959
let (param_env, Normalize { value }) = key.into_parts();
6060
let Normalized { value, obligations } =

compiler/rustc_type_ir/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub mod fold;
2626
pub mod new;
2727
pub mod ty_info;
2828
pub mod ty_kind;
29+
pub mod lift;
2930

3031
#[macro_use]
3132
mod macros;
@@ -57,6 +58,7 @@ pub use DynKind::*;
5758
pub use InferTy::*;
5859
pub use RegionKind::*;
5960
pub use TyKind::*;
61+
pub use lift::*;
6062

6163
rustc_index::newtype_index! {
6264
/// A [De Bruijn index][dbi] is a standard means of representing

0 commit comments

Comments
 (0)