Retire BraceStructLiftImpl.

This commit is contained in:
Camille GILLOT 2019-11-15 18:19:52 +01:00
parent 2add2075de
commit 033d1df19b
19 changed files with 26 additions and 196 deletions

View File

@ -32,7 +32,7 @@ use std::ops::Index;
use syntax::source_map::Span;
use crate::ty::fold::TypeFoldable;
use crate::ty::subst::GenericArg;
use crate::ty::{self, BoundVar, Lift, List, Region, TyCtxt};
use crate::ty::{self, BoundVar, List, Region, TyCtxt};
mod canonicalizer;
@ -44,7 +44,7 @@ mod substitute;
/// variables have been rewritten to "canonical vars". These are
/// numbered starting from 0 in order of first appearance.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
#[derive(HashStable, TypeFoldable)]
#[derive(HashStable, TypeFoldable, Lift)]
pub struct Canonical<'tcx, V> {
pub max_universe: ty::UniverseIndex,
pub variables: CanonicalVarInfos<'tcx>,
@ -65,7 +65,7 @@ impl<'tcx> UseSpecializedDecodable for CanonicalVarInfos<'tcx> {}
/// variables. You will need to supply it later to instantiate the
/// canonicalized query response.
#[derive(Clone, Debug, PartialEq, Eq, Hash, RustcDecodable, RustcEncodable)]
#[derive(HashStable, TypeFoldable)]
#[derive(HashStable, TypeFoldable, Lift)]
pub struct CanonicalVarValues<'tcx> {
pub var_values: IndexVec<BoundVar, GenericArg<'tcx>>,
}
@ -188,7 +188,7 @@ pub enum CanonicalTyVarKind {
/// After we execute a query with a canonicalized key, we get back a
/// `Canonical<QueryResponse<..>>`. You can use
/// `instantiate_query_result` to access the data in this result.
#[derive(Clone, Debug, HashStable, TypeFoldable)]
#[derive(Clone, Debug, HashStable, TypeFoldable, Lift)]
pub struct QueryResponse<'tcx, R> {
pub var_values: CanonicalVarValues<'tcx>,
pub region_constraints: QueryRegionConstraints<'tcx>,
@ -196,7 +196,7 @@ pub struct QueryResponse<'tcx, R> {
pub value: R,
}
#[derive(Clone, Debug, Default, HashStable, TypeFoldable)]
#[derive(Clone, Debug, Default, HashStable, TypeFoldable, Lift)]
pub struct QueryRegionConstraints<'tcx> {
pub outlives: Vec<QueryOutlivesConstraint<'tcx>>,
pub member_constraints: Vec<MemberConstraint<'tcx>>,
@ -469,13 +469,6 @@ CloneTypeFoldableImpls! {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx, T> Lift<'tcx> for Canonical<'a, T> {
type Lifted = Canonical<'tcx, T::Lifted>;
max_universe, variables, value
} where T: Lift<'tcx>
}
impl<'tcx> CanonicalVarValues<'tcx> {
pub fn len(&self) -> usize {
self.var_values.len()
@ -521,27 +514,6 @@ impl<'a, 'tcx> IntoIterator for &'a CanonicalVarValues<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for CanonicalVarValues<'a> {
type Lifted = CanonicalVarValues<'tcx>;
var_values,
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx, R> Lift<'tcx> for QueryResponse<'a, R> {
type Lifted = QueryResponse<'tcx, R::Lifted>;
var_values, region_constraints, certainty, value
} where R: Lift<'tcx>
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for QueryRegionConstraints<'a> {
type Lifted = QueryRegionConstraints<'tcx>;
outlives, member_constraints
}
}
impl<'tcx> Index<BoundVar> for CanonicalVarValues<'tcx> {
type Output = GenericArg<'tcx>;

View File

@ -151,7 +151,7 @@ impl Constraint<'_> {
/// ```
/// R0 member of [O1..On]
/// ```
#[derive(Debug, Clone, HashStable, TypeFoldable)]
#[derive(Debug, Clone, HashStable, TypeFoldable, Lift)]
pub struct MemberConstraint<'tcx> {
/// The `DefId` of the opaque type causing this constraint: used for error reporting.
pub opaque_type_def_id: DefId,
@ -169,13 +169,6 @@ pub struct MemberConstraint<'tcx> {
pub choice_regions: Lrc<Vec<Region<'tcx>>>,
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for MemberConstraint<'a> {
type Lifted = MemberConstraint<'tcx>;
opaque_type_def_id, definition_span, hidden_ty, member_region, choice_regions
}
}
/// `VerifyGenericBound(T, _, R, RS)`: the parameter type `T` (or
/// associated type) must outlive the region `R`. `T` is known to
/// outlive `RS`. Therefore, verify that `R <= RS[i]` for some

View File

@ -253,25 +253,6 @@ macro_rules! CloneTypeFoldableAndLiftImpls {
}
}
#[macro_export]
macro_rules! BraceStructLiftImpl {
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {
type Lifted = $lifted:ty;
$($field:ident),* $(,)?
} $(where $($wc:tt)*)*) => {
impl<$($p),*> $crate::ty::Lift<$tcx> for $s
$(where $($wc)*)*
{
type Lifted = $lifted;
fn lift_to_tcx(&self, tcx: TyCtxt<$tcx>) -> Option<$lifted> {
$(let $field = tcx.lift(&self.$field)?;)*
Some(Self::Lifted { $($field),* })
}
}
};
}
#[macro_export]
macro_rules! EnumLiftImpl {
(impl<$($p:tt),*> Lift<$tcx:tt> for $s:path {

View File

@ -124,7 +124,8 @@ use rustc_macros::HashStable;
use byteorder::{WriteBytesExt, ReadBytesExt, LittleEndian, BigEndian};
/// Uniquely identifies a specific constant or static.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable, HashStable)]
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, Lift)]
pub struct GlobalId<'tcx> {
/// For a constant or static, the `Instance` of the item itself.
/// For a promoted global, the `Instance` of the function they belong to.

View File

@ -79,7 +79,7 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
}
}
#[derive(Clone, Debug, Default, TypeFoldable)]
#[derive(Clone, Debug, Default, TypeFoldable, Lift)]
pub struct DropckOutlivesResult<'tcx> {
pub kinds: Vec<GenericArg<'tcx>>,
pub overflows: Vec<Ty<'tcx>>,
@ -152,13 +152,6 @@ impl<'tcx> FromIterator<DtorckConstraint<'tcx>> for DtorckConstraint<'tcx> {
result
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for DropckOutlivesResult<'a> {
type Lifted = DropckOutlivesResult<'tcx>;
kinds, overflows
}
}
impl_stable_hash_for!(struct DropckOutlivesResult<'tcx> {
kinds, overflows
});

View File

@ -66,7 +66,7 @@ impl<'cx, 'tcx> At<'cx, 'tcx> {
}
/// Result from the `normalize_projection_ty` query.
#[derive(Clone, Debug, TypeFoldable)]
#[derive(Clone, Debug, TypeFoldable, Lift)]
pub struct NormalizationResult<'tcx> {
/// Result of normalization.
pub normalized_ty: Ty<'tcx>,
@ -194,13 +194,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for NormalizationResult<'a> {
type Lifted = NormalizationResult<'tcx>;
normalized_ty
}
}
impl_stable_hash_for!(struct NormalizationResult<'tcx> {
normalized_ty
});

View File

@ -4,7 +4,7 @@ use crate::hir::def_id::DefId;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
use crate::ty::subst::UserSubsts;
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
pub struct AscribeUserType<'tcx> {
pub mir_ty: Ty<'tcx>,
pub def_id: DefId,
@ -39,13 +39,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for AscribeUserType<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for AscribeUserType<'a> {
type Lifted = AscribeUserType<'tcx>;
mir_ty, def_id, user_substs
}
}
impl_stable_hash_for! {
struct AscribeUserType<'tcx> {
mir_ty, def_id, user_substs

View File

@ -2,7 +2,7 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
pub struct Eq<'tcx> {
pub a: Ty<'tcx>,
pub b: Ty<'tcx>,
@ -36,14 +36,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Eq<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for Eq<'a> {
type Lifted = Eq<'tcx>;
a,
b,
}
}
impl_stable_hash_for! {
struct Eq<'tcx> { a, b }
}

View File

@ -3,7 +3,7 @@ use crate::traits::query::outlives_bounds::OutlivesBound;
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
#[derive(Clone, Debug, TypeFoldable)]
#[derive(Clone, Debug, TypeFoldable, Lift)]
pub struct ImpliedOutlivesBounds<'tcx> {
pub ty: Ty<'tcx>,
}
@ -40,13 +40,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ImpliedOutlivesBounds<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for ImpliedOutlivesBounds<'a> {
type Lifted = ImpliedOutlivesBounds<'tcx>;
ty,
}
}
impl_stable_hash_for! {
struct ImpliedOutlivesBounds<'tcx> { ty }
}

View File

@ -4,7 +4,7 @@ use crate::traits::query::Fallible;
use crate::ty::fold::TypeFoldable;
use crate::ty::{self, Lift, ParamEnvAnd, Ty, TyCtxt};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
pub struct Normalize<T> {
pub value: T,
}
@ -83,13 +83,6 @@ impl Normalizable<'tcx> for ty::FnSig<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'tcx, T> Lift<'tcx> for Normalize<T> {
type Lifted = Normalize<T::Lifted>;
value,
} where T: Lift<'tcx>,
}
impl_stable_hash_for! {
impl<T> for struct Normalize<T> {
value

View File

@ -3,7 +3,7 @@ use crate::traits::query::dropck_outlives::{DropckOutlivesResult, trivial_dropck
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
#[derive(Copy, Clone, Debug, TypeFoldable)]
#[derive(Copy, Clone, Debug, TypeFoldable, Lift)]
pub struct DropckOutlives<'tcx> {
dropped_ty: Ty<'tcx>,
}
@ -54,13 +54,6 @@ impl super::QueryTypeOp<'tcx> for DropckOutlives<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for DropckOutlives<'a> {
type Lifted = DropckOutlives<'tcx>;
dropped_ty
}
}
impl_stable_hash_for! {
struct DropckOutlives<'tcx> { dropped_ty }
}

View File

@ -2,7 +2,7 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Predicate, TyCtxt};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
pub struct ProvePredicate<'tcx> {
pub predicate: Predicate<'tcx>,
}
@ -45,13 +45,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for ProvePredicate<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for ProvePredicate<'a> {
type Lifted = ProvePredicate<'tcx>;
predicate,
}
}
impl_stable_hash_for! {
struct ProvePredicate<'tcx> { predicate }
}

View File

@ -2,7 +2,7 @@ use crate::infer::canonical::{Canonicalized, CanonicalizedQueryResponse};
use crate::traits::query::Fallible;
use crate::ty::{ParamEnvAnd, Ty, TyCtxt};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, TypeFoldable, Lift)]
pub struct Subtype<'tcx> {
pub sub: Ty<'tcx>,
pub sup: Ty<'tcx>,
@ -36,14 +36,6 @@ impl<'tcx> super::QueryTypeOp<'tcx> for Subtype<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for Subtype<'a> {
type Lifted = Subtype<'tcx>;
sub,
sup,
}
}
impl_stable_hash_for! {
struct Subtype<'tcx> { sub, sup }
}

View File

@ -826,20 +826,13 @@ rustc_index::newtype_index! {
pub type CanonicalUserTypeAnnotations<'tcx> =
IndexVec<UserTypeAnnotationIndex, CanonicalUserTypeAnnotation<'tcx>>;
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)]
#[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable, TypeFoldable, Lift)]
pub struct CanonicalUserTypeAnnotation<'tcx> {
pub user_ty: CanonicalUserType<'tcx>,
pub span: Span,
pub inferred_ty: Ty<'tcx>,
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for CanonicalUserTypeAnnotation<'a> {
type Lifted = CanonicalUserTypeAnnotation<'tcx>;
user_ty, span, inferred_ty
}
}
/// Canonicalized user type annotation.
pub type CanonicalUserType<'tcx> = Canonical<'tcx, UserType<'tcx>>;

View File

@ -12,7 +12,8 @@ use rustc_macros::HashStable;
use std::fmt;
use std::iter;
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable, HashStable)]
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)]
#[derive(HashStable, Lift)]
pub struct Instance<'tcx> {
pub def: InstanceDef<'tcx>,
pub substs: SubstsRef<'tcx>,

View File

@ -1,7 +1,6 @@
//! This module contains implements of the `Lift` and `TypeFoldable`
//! traits for various types in the Rust compiler. Most are written by
//! hand, though we've recently added some macros (e.g.,
//! `BraceStructLiftImpl!`) to help with the tedium.
//! hand, though we've recently added some macros and proc-macros to help with the tedium.
use crate::hir::def::Namespace;
use crate::mir::ProjectionKind;
@ -779,27 +778,6 @@ impl<'a, 'tcx> Lift<'tcx> for ty::InstanceDef<'a> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for ty::TypeAndMut<'a> {
type Lifted = ty::TypeAndMut<'tcx>;
ty, mutbl
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for ty::Instance<'a> {
type Lifted = ty::Instance<'tcx>;
def, substs
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for interpret::GlobalId<'a> {
type Lifted = interpret::GlobalId<'tcx>;
instance, promoted
}
}
///////////////////////////////////////////////////////////////////////////
// TypeFoldable implementations.
//

View File

@ -30,7 +30,7 @@ use self::InferTy::*;
use self::TyKind::*;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
#[derive(HashStable, TypeFoldable, Lift)]
pub struct TypeAndMut<'tcx> {
pub ty: Ty<'tcx>,
pub mutbl: hir::Mutability,

View File

@ -731,7 +731,7 @@ pub type CanonicalUserSubsts<'tcx> = Canonical<'tcx, UserSubsts<'tcx>>;
/// Stores the user-given substs to reach some fully qualified path
/// (e.g., `<T>::Item` or `<T as Trait>::Item`).
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
#[derive(HashStable, TypeFoldable, Lift)]
pub struct UserSubsts<'tcx> {
/// The substitutions for the item as given by the user.
pub substs: SubstsRef<'tcx>,
@ -741,14 +741,6 @@ pub struct UserSubsts<'tcx> {
pub user_self_ty: Option<UserSelfTy<'tcx>>,
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for UserSubsts<'a> {
type Lifted = UserSubsts<'tcx>;
substs,
user_self_ty,
}
}
/// Specifies the user-given self type. In the case of a path that
/// refers to a member in an inherent impl, this self type is
/// sometimes needed to constrain the type parameters on the impl. For
@ -766,16 +758,8 @@ BraceStructLiftImpl! {
/// the self type, giving `Foo<?A>`. Finally, we unify that with
/// the self type here, which contains `?A` to be `&'static u32`
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
#[derive(HashStable, TypeFoldable)]
#[derive(HashStable, TypeFoldable, Lift)]
pub struct UserSelfTy<'tcx> {
pub impl_def_id: DefId,
pub self_ty: Ty<'tcx>,
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for UserSelfTy<'a> {
type Lifted = UserSelfTy<'tcx>;
impl_def_id,
self_ty,
}
}

View File

@ -38,7 +38,7 @@ use rustc::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use rustc::ty::query::Providers;
use rustc::ty::subst::{GenericArg, GenericArgKind};
use syntax_pos::DUMMY_SP;
use rustc_macros::TypeFoldable;
use rustc_macros::{TypeFoldable, Lift};
use std::fmt::{self, Debug};
use std::marker::PhantomData;
@ -66,7 +66,7 @@ crate struct UniverseMap;
crate type RegionConstraint<'tcx> = ty::OutlivesPredicate<GenericArg<'tcx>, ty::Region<'tcx>>;
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, TypeFoldable, Lift)]
crate struct ConstrainedSubst<'tcx> {
subst: CanonicalVarValues<'tcx>,
constraints: Vec<RegionConstraint<'tcx>>,
@ -581,14 +581,6 @@ impl ExClauseFold<'tcx> for ChalkArenas<'tcx> {
}
}
BraceStructLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for ConstrainedSubst<'a> {
type Lifted = ConstrainedSubst<'tcx>;
subst, constraints
}
}
trait Upcast<'tcx>: 'tcx {
type Upcasted: 'tcx;