Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,10 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
ty::tls::with(|tcx| {
match self.imm {
Immediate::Scalar(s) => {
if let Some(ty) = tcx.lift(self.layout.ty) {
let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
print_scalar(p, s, ty)
})?;
f.write_str(&s)?;
return Ok(());
}
write!(f, "{:x}: {}", s, self.layout.ty)
let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
print_scalar(p, s, self.layout.ty)
})?;
f.write_str(&s)
}
Immediate::ScalarPair(a, b) => {
// FIXME(oli-obk): at least print tuples and slices nicely
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mod current_version;
mod diagnostics;
mod extension;
mod hash_stable;
mod lift;
mod print_attribute;
mod query;
mod serialize;
Expand Down Expand Up @@ -176,7 +175,6 @@ decl_derive!(
/// visited (and its type is not required to implement `Walkable`).
visitable::visitable_derive
);
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
decl_derive!(
[Diagnostic, attributes(
// struct attributes
Expand Down
49 changes: 0 additions & 49 deletions compiler/rustc_macros/src/lift.rs

This file was deleted.

22 changes: 1 addition & 21 deletions compiler/rustc_middle/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,11 @@ macro_rules! span_bug {
}

///////////////////////////////////////////////////////////////////////////
// Lift and TypeFoldable/TypeVisitable macros
// TypeFoldable/TypeVisitable macros
//
// When possible, use one of these (relatively) convenient macros to write
// the impls for you.

macro_rules! TrivialLiftImpls {
($($ty:ty),+ $(,)?) => {
$(
impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
type Lifted = Self;
fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
Some(self)
}
}
)+
};
}

/// Used for types that are `Copy` and which **do not care about arena
/// allocated data** (i.e., don't need to be folded).
macro_rules! TrivialTypeTraversalImpls {
Expand Down Expand Up @@ -89,10 +76,3 @@ macro_rules! TrivialTypeTraversalImpls {
)+
};
}

macro_rules! TrivialTypeTraversalAndLiftImpls {
($($t:tt)*) => {
TrivialTypeTraversalImpls! { $($t)* }
TrivialLiftImpls! { $($t)* }
}
}
7 changes: 3 additions & 4 deletions compiler/rustc_middle/src/mir/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Display, Formatter};

use rustc_abi::{HasDataLayout, Size};
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
use rustc_span::{DUMMY_SP, RemapPathScopeComponents, Span, Symbol};
use rustc_type_ir::TypeVisitableExt;

Expand Down Expand Up @@ -208,7 +208,7 @@ impl ConstValue {
/// Constants

#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
#[derive(TypeFoldable, TypeVisitable, Lift)]
#[derive(TypeFoldable, TypeVisitable)]
pub enum Const<'tcx> {
/// This constant came from the type system.
///
Expand Down Expand Up @@ -458,7 +458,7 @@ impl<'tcx> Const<'tcx> {

/// An unevaluated (potentially generic) constant used in MIR.
#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)]
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
pub struct UnevaluatedConst<'tcx> {
pub def: DefId,
pub args: GenericArgsRef<'tcx>,
Expand Down Expand Up @@ -493,7 +493,6 @@ impl<'tcx> Display for Const<'tcx> {
// FIXME(valtrees): Correctly print mir constants.
Const::Unevaluated(c, _ty) => {
ty::tls::with(move |tcx| {
let c = tcx.lift(c).unwrap();
// Matches `GlobalId` printing.
let instance =
with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args));
Expand Down
12 changes: 1 addition & 11 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
AggregateKind::Adt(adt_did, variant, args, _user_ty, _) => {
ty::tls::with(|tcx| {
let variant_def = &tcx.adt_def(adt_did).variant(variant);
let args = tcx.lift(args).expect("could not lift for printing");
let name = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
p.print_def_path(variant_def.def_id, args)
})?;
Expand All @@ -1187,7 +1186,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
AggregateKind::Closure(def_id, args)
| AggregateKind::CoroutineClosure(def_id, args) => ty::tls::with(|tcx| {
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
let args = tcx.lift(args).unwrap();
format!("{{closure@{}}}", tcx.def_path_str_with_args(def_id, args),)
} else {
let span = tcx.def_span(def_id);
Expand Down Expand Up @@ -1911,8 +1909,6 @@ fn pretty_print_const_value_tcx<'tcx>(
// E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized`
// to be able to destructure the tuple into `(0u8, *mut T)`
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => {
let ct = tcx.lift(ct).unwrap();
let ty = tcx.lift(ty).unwrap();
if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) {
let fields: Vec<(ConstValue, Ty<'_>)> = contents.fields.to_vec();
match *ty.kind() {
Expand All @@ -1937,7 +1933,6 @@ fn pretty_print_const_value_tcx<'tcx>(
.variant
.expect("destructed mir constant of adt without variant idx");
let variant_def = &def.variant(variant_idx);
let args = tcx.lift(args).unwrap();
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
p.print_alloc_ids = true;
p.pretty_print_value_path(variant_def.def_id, args)?;
Expand Down Expand Up @@ -1974,7 +1969,6 @@ fn pretty_print_const_value_tcx<'tcx>(
(ConstValue::Scalar(scalar), _) => {
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
p.print_alloc_ids = true;
let ty = tcx.lift(ty).unwrap();
p.pretty_print_const_scalar(scalar, ty)?;
fmt.write_str(&p.into_buffer())?;
return Ok(());
Expand All @@ -1999,11 +1993,7 @@ pub(crate) fn pretty_print_const_value<'tcx>(
ty: Ty<'tcx>,
fmt: &mut Formatter<'_>,
) -> fmt::Result {
ty::tls::with(|tcx| {
let ct = tcx.lift(ct).unwrap();
let ty = tcx.lift(ty).unwrap();
pretty_print_const_value_tcx(tcx, ct, ty, fmt)
})
ty::tls::with(|tcx| pretty_print_const_value_tcx(tcx, ct, ty, fmt))
}

///////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_middle/src/ty/consts/valtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ use std::ops::Deref;
use rustc_abi::{FIRST_VARIANT, VariantIdx};
use rustc_data_structures::intern::Interned;
use rustc_hir::def::Namespace;
use rustc_macros::{
HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension,
};
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension};

use super::ScalarInt;
use crate::mir::interpret::{ErrorHandled, Scalar};
Expand Down Expand Up @@ -97,7 +95,7 @@ pub type ConstToValTreeResult<'tcx> = Result<Result<ValTree<'tcx>, Ty<'tcx>>, Er
/// Note that this is also used by pattern elaboration to represent values which cannot occur in types,
/// such as raw pointers and floats.
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable, Lift)]
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
pub struct Value<'tcx> {
pub ty: Ty<'tcx>,
pub valtree: ValTree<'tcx>,
Expand Down Expand Up @@ -238,9 +236,8 @@ impl<'tcx> rustc_type_ir::inherent::ValueConst<TyCtxt<'tcx>> for Value<'tcx> {
impl<'tcx> fmt::Display for Value<'tcx> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
ty::tls::with(move |tcx| {
let cv = tcx.lift(*self).unwrap();
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
p.pretty_print_const_valtree(cv, /*print_ty*/ true)?;
p.pretty_print_const_valtree(*self, /*print_ty*/ true)?;
f.write_str(&p.into_buffer())
})
}
Expand Down
83 changes: 1 addition & 82 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::hash::{Hash, Hasher};
use std::marker::{PhantomData, PointeeSized};
use std::ops::{Bound, Deref};
use std::sync::{Arc, OnceLock};
use std::{fmt, iter, mem};
use std::{fmt, iter};

use rustc_abi::{ExternAbi, FieldIdx, Layout, LayoutData, TargetDataLayout, VariantIdx};
use rustc_ast as ast;
Expand Down Expand Up @@ -45,7 +45,6 @@ use rustc_session::lint::Lint;
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_type_ir::TyKind::*;
pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{CollectAndApply, FnSigKind, WithCachedTypeInfo, elaborate, search_graph};
use tracing::{debug, instrument};

Expand Down Expand Up @@ -1002,10 +1001,6 @@ impl<'tcx> TyCtxt<'tcx> {
(start, end)
}

pub fn lift<T: Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> {
value.lift_to_interner(self)
}

/// Creates a type context. To use the context call `fn enter` which
/// provides a `TyCtxt`.
///
Expand Down Expand Up @@ -1729,82 +1724,6 @@ impl<'tcx> TyCtxt<'tcx> {
}
}

macro_rules! nop_lift {
($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for $ty {
type Lifted = $lifted;
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
// Assert that the set has the right type.
// Given an argument that has an interned type, the return type has the type of
// the corresponding interner set. This won't actually return anything, we're
// just doing this to compute said type!
fn _intern_set_ty_from_interned_ty<'tcx, Inner>(
_x: Interned<'tcx, Inner>,
) -> InternedSet<'tcx, Inner> {
unreachable!()
}
fn _type_eq<T>(_x: &T, _y: &T) {}
fn _test<'tcx>(x: $lifted, tcx: TyCtxt<'tcx>) {
// If `x` is a newtype around an `Interned<T>`, then `interner` is an
// interner of appropriate type. (Ideally we'd also check that `x` is a
// newtype with just that one field. Not sure how to do that.)
let interner = _intern_set_ty_from_interned_ty(x.0);
// Now check that this is the same type as `interners.$set`.
_type_eq(&interner, &tcx.interners.$set);
}

tcx.interners
.$set
.contains_pointer_to(&InternedInSet(&*self.0.0))
// SAFETY: `self` is interned and therefore valid
// for the entire lifetime of the `TyCtxt`.
.then(|| unsafe { mem::transmute(self) })
}
}
};
}

macro_rules! nop_list_lift {
($set:ident; $ty:ty => $lifted:ty) => {
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<$ty> {
type Lifted = &'tcx List<$lifted>;
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
// Assert that the set has the right type.
if false {
let _x: &InternedSet<'tcx, List<$lifted>> = &tcx.interners.$set;
}

if self.is_empty() {
return Some(List::empty());
}
tcx.interners
.$set
.contains_pointer_to(&InternedInSet(self))
.then(|| unsafe { mem::transmute(self) })
}
}
};
}

nop_lift! { type_; Ty<'a> => Ty<'tcx> }
nop_lift! { region; Region<'a> => Region<'tcx> }
nop_lift! { const_; Const<'a> => Const<'tcx> }
nop_lift! { pat; Pattern<'a> => Pattern<'tcx> }
nop_lift! { const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx> }
nop_lift! { predicate; Predicate<'a> => Predicate<'tcx> }
nop_lift! { predicate; Clause<'a> => Clause<'tcx> }
nop_lift! { layout; Layout<'a> => Layout<'tcx> }
nop_lift! { valtree; ValTree<'a> => ValTree<'tcx> }

nop_list_lift! { type_lists; Ty<'a> => Ty<'tcx> }
nop_list_lift! {
poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>
}
nop_list_lift! { bound_variable_kinds; ty::BoundVariableKind<'a> => ty::BoundVariableKind<'tcx> }

// This is the impl for `&'a GenericArgs<'a>`.
nop_list_lift! { args; GenericArg<'a> => GenericArg<'tcx> }

macro_rules! sty_debug_print {
($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{
// Curious inner module to allow variant names to be used as
Expand Down
Loading
Loading