Skip to content

Commit c6cff6a

Browse files
committed
Auto merge of #155921 - nnethercote:rm-Lift, r=<try>
Eliminate lifting
2 parents 4ddb0b7 + d4b0e05 commit c6cff6a

38 files changed

Lines changed: 454 additions & 895 deletions

File tree

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,10 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
216216
ty::tls::with(|tcx| {
217217
match self.imm {
218218
Immediate::Scalar(s) => {
219-
if let Some(ty) = tcx.lift(self.layout.ty) {
220-
let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
221-
print_scalar(p, s, ty)
222-
})?;
223-
f.write_str(&s)?;
224-
return Ok(());
225-
}
226-
write!(f, "{:x}: {}", s, self.layout.ty)
219+
let s = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
220+
print_scalar(p, s, self.layout.ty)
221+
})?;
222+
f.write_str(&s)
227223
}
228224
Immediate::ScalarPair(a, b) => {
229225
// FIXME(oli-obk): at least print tuples and slices nicely

compiler/rustc_macros/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ mod current_version;
1212
mod diagnostics;
1313
mod extension;
1414
mod hash_stable;
15-
mod lift;
1615
mod print_attribute;
1716
mod query;
1817
mod serialize;
@@ -176,7 +175,6 @@ decl_derive!(
176175
/// visited (and its type is not required to implement `Walkable`).
177176
visitable::visitable_derive
178177
);
179-
decl_derive!([Lift, attributes(lift)] => lift::lift_derive);
180178
decl_derive!(
181179
[Diagnostic, attributes(
182180
// struct attributes

compiler/rustc_macros/src/lift.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

compiler/rustc_middle/src/macros.rs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,11 @@ macro_rules! span_bug {
3636
}
3737

3838
///////////////////////////////////////////////////////////////////////////
39-
// Lift and TypeFoldable/TypeVisitable macros
39+
// TypeFoldable/TypeVisitable macros
4040
//
4141
// When possible, use one of these (relatively) convenient macros to write
4242
// the impls for you.
4343

44-
macro_rules! TrivialLiftImpls {
45-
($($ty:ty),+ $(,)?) => {
46-
$(
47-
impl<'tcx> $crate::ty::Lift<$crate::ty::TyCtxt<'tcx>> for $ty {
48-
type Lifted = Self;
49-
fn lift_to_interner(self, _: $crate::ty::TyCtxt<'tcx>) -> Option<Self> {
50-
Some(self)
51-
}
52-
}
53-
)+
54-
};
55-
}
56-
5744
/// Used for types that are `Copy` and which **do not care about arena
5845
/// allocated data** (i.e., don't need to be folded).
5946
macro_rules! TrivialTypeTraversalImpls {
@@ -89,10 +76,3 @@ macro_rules! TrivialTypeTraversalImpls {
8976
)+
9077
};
9178
}
92-
93-
macro_rules! TrivialTypeTraversalAndLiftImpls {
94-
($($t:tt)*) => {
95-
TrivialTypeTraversalImpls! { $($t)* }
96-
TrivialLiftImpls! { $($t)* }
97-
}
98-
}

compiler/rustc_middle/src/mir/consts.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt::{self, Debug, Display, Formatter};
22

33
use rustc_abi::{HasDataLayout, Size};
44
use rustc_hir::def_id::DefId;
5-
use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
5+
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable};
66
use rustc_span::{DUMMY_SP, RemapPathScopeComponents, Span, Symbol};
77
use rustc_type_ir::TypeVisitableExt;
88

@@ -208,7 +208,7 @@ impl ConstValue {
208208
/// Constants
209209
210210
#[derive(Clone, Copy, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable, Debug)]
211-
#[derive(TypeFoldable, TypeVisitable, Lift)]
211+
#[derive(TypeFoldable, TypeVisitable)]
212212
pub enum Const<'tcx> {
213213
/// This constant came from the type system.
214214
///
@@ -458,7 +458,7 @@ impl<'tcx> Const<'tcx> {
458458

459459
/// An unevaluated (potentially generic) constant used in MIR.
460460
#[derive(Copy, Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable)]
461-
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable, Lift)]
461+
#[derive(Hash, HashStable, TypeFoldable, TypeVisitable)]
462462
pub struct UnevaluatedConst<'tcx> {
463463
pub def: DefId,
464464
pub args: GenericArgsRef<'tcx>,
@@ -493,7 +493,6 @@ impl<'tcx> Display for Const<'tcx> {
493493
// FIXME(valtrees): Correctly print mir constants.
494494
Const::Unevaluated(c, _ty) => {
495495
ty::tls::with(move |tcx| {
496-
let c = tcx.lift(c).unwrap();
497496
// Matches `GlobalId` printing.
498497
let instance =
499498
with_no_trimmed_paths!(tcx.def_path_str_with_args(c.def, c.args));

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11651165
AggregateKind::Adt(adt_did, variant, args, _user_ty, _) => {
11661166
ty::tls::with(|tcx| {
11671167
let variant_def = &tcx.adt_def(adt_did).variant(variant);
1168-
let args = tcx.lift(args).expect("could not lift for printing");
11691168
let name = FmtPrinter::print_string(tcx, Namespace::ValueNS, |p| {
11701169
p.print_def_path(variant_def.def_id, args)
11711170
})?;
@@ -1187,7 +1186,6 @@ impl<'tcx> Debug for Rvalue<'tcx> {
11871186
AggregateKind::Closure(def_id, args)
11881187
| AggregateKind::CoroutineClosure(def_id, args) => ty::tls::with(|tcx| {
11891188
let name = if tcx.sess.opts.unstable_opts.span_free_formats {
1190-
let args = tcx.lift(args).unwrap();
11911189
format!("{{closure@{}}}", tcx.def_path_str_with_args(def_id, args),)
11921190
} else {
11931191
let span = tcx.def_span(def_id);
@@ -1911,8 +1909,6 @@ fn pretty_print_const_value_tcx<'tcx>(
19111909
// E.g. `transmute([0usize; 2]): (u8, *mut T)` needs to know `T: Sized`
19121910
// to be able to destructure the tuple into `(0u8, *mut T)`
19131911
(_, ty::Array(..) | ty::Tuple(..) | ty::Adt(..)) if !ty.has_non_region_param() => {
1914-
let ct = tcx.lift(ct).unwrap();
1915-
let ty = tcx.lift(ty).unwrap();
19161912
if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) {
19171913
let fields: Vec<(ConstValue, Ty<'_>)> = contents.fields.to_vec();
19181914
match *ty.kind() {
@@ -1937,7 +1933,6 @@ fn pretty_print_const_value_tcx<'tcx>(
19371933
.variant
19381934
.expect("destructed mir constant of adt without variant idx");
19391935
let variant_def = &def.variant(variant_idx);
1940-
let args = tcx.lift(args).unwrap();
19411936
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
19421937
p.print_alloc_ids = true;
19431938
p.pretty_print_value_path(variant_def.def_id, args)?;
@@ -1974,7 +1969,6 @@ fn pretty_print_const_value_tcx<'tcx>(
19741969
(ConstValue::Scalar(scalar), _) => {
19751970
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
19761971
p.print_alloc_ids = true;
1977-
let ty = tcx.lift(ty).unwrap();
19781972
p.pretty_print_const_scalar(scalar, ty)?;
19791973
fmt.write_str(&p.into_buffer())?;
19801974
return Ok(());
@@ -1999,11 +1993,7 @@ pub(crate) fn pretty_print_const_value<'tcx>(
19991993
ty: Ty<'tcx>,
20001994
fmt: &mut Formatter<'_>,
20011995
) -> fmt::Result {
2002-
ty::tls::with(|tcx| {
2003-
let ct = tcx.lift(ct).unwrap();
2004-
let ty = tcx.lift(ty).unwrap();
2005-
pretty_print_const_value_tcx(tcx, ct, ty, fmt)
2006-
})
1996+
ty::tls::with(|tcx| pretty_print_const_value_tcx(tcx, ct, ty, fmt))
20071997
}
20081998

20091999
///////////////////////////////////////////////////////////////////////////

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use std::ops::Deref;
44
use rustc_abi::{FIRST_VARIANT, VariantIdx};
55
use rustc_data_structures::intern::Interned;
66
use rustc_hir::def::Namespace;
7-
use rustc_macros::{
8-
HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension,
9-
};
7+
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension};
108

119
use super::ScalarInt;
1210
use crate::mir::interpret::{ErrorHandled, Scalar};
@@ -97,7 +95,7 @@ pub type ConstToValTreeResult<'tcx> = Result<Result<ValTree<'tcx>, Ty<'tcx>>, Er
9795
/// Note that this is also used by pattern elaboration to represent values which cannot occur in types,
9896
/// such as raw pointers and floats.
9997
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
100-
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable, Lift)]
98+
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
10199
pub struct Value<'tcx> {
102100
pub ty: Ty<'tcx>,
103101
pub valtree: ValTree<'tcx>,
@@ -238,9 +236,8 @@ impl<'tcx> rustc_type_ir::inherent::ValueConst<TyCtxt<'tcx>> for Value<'tcx> {
238236
impl<'tcx> fmt::Display for Value<'tcx> {
239237
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
240238
ty::tls::with(move |tcx| {
241-
let cv = tcx.lift(*self).unwrap();
242239
let mut p = FmtPrinter::new(tcx, Namespace::ValueNS);
243-
p.pretty_print_const_valtree(cv, /*print_ty*/ true)?;
240+
p.pretty_print_const_valtree(*self, /*print_ty*/ true)?;
244241
f.write_str(&p.into_buffer())
245242
})
246243
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::hash::{Hash, Hasher};
1313
use std::marker::{PhantomData, PointeeSized};
1414
use std::ops::{Bound, Deref};
1515
use std::sync::{Arc, OnceLock};
16-
use std::{fmt, iter, mem};
16+
use std::{fmt, iter};
1717

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

@@ -1002,10 +1001,6 @@ impl<'tcx> TyCtxt<'tcx> {
10021001
(start, end)
10031002
}
10041003

1005-
pub fn lift<T: Lift<TyCtxt<'tcx>>>(self, value: T) -> Option<T::Lifted> {
1006-
value.lift_to_interner(self)
1007-
}
1008-
10091004
/// Creates a type context. To use the context call `fn enter` which
10101005
/// provides a `TyCtxt`.
10111006
///
@@ -1729,82 +1724,6 @@ impl<'tcx> TyCtxt<'tcx> {
17291724
}
17301725
}
17311726

1732-
macro_rules! nop_lift {
1733-
($set:ident; $ty:ty => $lifted:ty) => {
1734-
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for $ty {
1735-
type Lifted = $lifted;
1736-
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1737-
// Assert that the set has the right type.
1738-
// Given an argument that has an interned type, the return type has the type of
1739-
// the corresponding interner set. This won't actually return anything, we're
1740-
// just doing this to compute said type!
1741-
fn _intern_set_ty_from_interned_ty<'tcx, Inner>(
1742-
_x: Interned<'tcx, Inner>,
1743-
) -> InternedSet<'tcx, Inner> {
1744-
unreachable!()
1745-
}
1746-
fn _type_eq<T>(_x: &T, _y: &T) {}
1747-
fn _test<'tcx>(x: $lifted, tcx: TyCtxt<'tcx>) {
1748-
// If `x` is a newtype around an `Interned<T>`, then `interner` is an
1749-
// interner of appropriate type. (Ideally we'd also check that `x` is a
1750-
// newtype with just that one field. Not sure how to do that.)
1751-
let interner = _intern_set_ty_from_interned_ty(x.0);
1752-
// Now check that this is the same type as `interners.$set`.
1753-
_type_eq(&interner, &tcx.interners.$set);
1754-
}
1755-
1756-
tcx.interners
1757-
.$set
1758-
.contains_pointer_to(&InternedInSet(&*self.0.0))
1759-
// SAFETY: `self` is interned and therefore valid
1760-
// for the entire lifetime of the `TyCtxt`.
1761-
.then(|| unsafe { mem::transmute(self) })
1762-
}
1763-
}
1764-
};
1765-
}
1766-
1767-
macro_rules! nop_list_lift {
1768-
($set:ident; $ty:ty => $lifted:ty) => {
1769-
impl<'a, 'tcx> Lift<TyCtxt<'tcx>> for &'a List<$ty> {
1770-
type Lifted = &'tcx List<$lifted>;
1771-
fn lift_to_interner(self, tcx: TyCtxt<'tcx>) -> Option<Self::Lifted> {
1772-
// Assert that the set has the right type.
1773-
if false {
1774-
let _x: &InternedSet<'tcx, List<$lifted>> = &tcx.interners.$set;
1775-
}
1776-
1777-
if self.is_empty() {
1778-
return Some(List::empty());
1779-
}
1780-
tcx.interners
1781-
.$set
1782-
.contains_pointer_to(&InternedInSet(self))
1783-
.then(|| unsafe { mem::transmute(self) })
1784-
}
1785-
}
1786-
};
1787-
}
1788-
1789-
nop_lift! { type_; Ty<'a> => Ty<'tcx> }
1790-
nop_lift! { region; Region<'a> => Region<'tcx> }
1791-
nop_lift! { const_; Const<'a> => Const<'tcx> }
1792-
nop_lift! { pat; Pattern<'a> => Pattern<'tcx> }
1793-
nop_lift! { const_allocation; ConstAllocation<'a> => ConstAllocation<'tcx> }
1794-
nop_lift! { predicate; Predicate<'a> => Predicate<'tcx> }
1795-
nop_lift! { predicate; Clause<'a> => Clause<'tcx> }
1796-
nop_lift! { layout; Layout<'a> => Layout<'tcx> }
1797-
nop_lift! { valtree; ValTree<'a> => ValTree<'tcx> }
1798-
1799-
nop_list_lift! { type_lists; Ty<'a> => Ty<'tcx> }
1800-
nop_list_lift! {
1801-
poly_existential_predicates; PolyExistentialPredicate<'a> => PolyExistentialPredicate<'tcx>
1802-
}
1803-
nop_list_lift! { bound_variable_kinds; ty::BoundVariableKind<'a> => ty::BoundVariableKind<'tcx> }
1804-
1805-
// This is the impl for `&'a GenericArgs<'a>`.
1806-
nop_list_lift! { args; GenericArg<'a> => GenericArg<'tcx> }
1807-
18081727
macro_rules! sty_debug_print {
18091728
($fmt: expr, $ctxt: expr, $($variant: ident),*) => {{
18101729
// Curious inner module to allow variant names to be used as

0 commit comments

Comments
 (0)