From e94723452083283be04f6f55fca468b57bca32f3 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 11 Dec 2023 21:06:26 +0000 Subject: [PATCH 1/2] Simplify some Copy impls in rustc_type_ir --- compiler/rustc_type_ir/src/canonical.rs | 18 ++-------- compiler/rustc_type_ir/src/predicate_kind.rs | 35 +++++--------------- compiler/rustc_type_ir/src/region_kind.rs | 13 +------- 3 files changed, 11 insertions(+), 55 deletions(-) diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 572c6f201d3..5bc2bfe2893 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -119,12 +119,7 @@ where /// a copy of the canonical value in some other inference context, /// with fresh inference variables replacing the canonical values. #[derive(derivative::Derivative)] -#[derivative( - Clone(bound = ""), - Hash(bound = ""), - Copy(bound = "CanonicalVarKind: Copy"), - Debug(bound = "") -)] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Debug(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] pub struct CanonicalVarInfo { pub kind: CanonicalVarKind, @@ -207,7 +202,7 @@ impl CanonicalVarInfo { /// in the type-theory sense of the term -- i.e., a "meta" type system /// that analyzes type-like values. #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""), Hash(bound = ""), Debug(bound = ""))] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""), Debug(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyDecodable, TyEncodable, HashStable_NoContext))] pub enum CanonicalVarKind { /// Some kind of type inference variable. @@ -234,15 +229,6 @@ pub enum CanonicalVarKind { PlaceholderConst(I::PlaceholderConst, I::Ty), } -impl Copy for CanonicalVarKind -where - I::PlaceholderTy: Copy, - I::PlaceholderRegion: Copy, - I::PlaceholderConst: Copy, - I::Ty: Copy, -{ -} - impl PartialEq for CanonicalVarKind { fn eq(&self, other: &Self) -> bool { match (self, other) { diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index b567fa8e2f6..8c4d0fda6af 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -8,7 +8,7 @@ use crate::Interner; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""), Hash(bound = ""))] +#[derivative(Clone(bound = ""), Copy(bound = ""), Hash(bound = ""))] #[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))] pub enum ClauseKind { /// Corresponds to `where Foo: Bar`. `Foo` here would be @@ -37,18 +37,6 @@ pub enum ClauseKind { ConstEvaluatable(I::Const), } -impl Copy for ClauseKind -where - I::Ty: Copy, - I::Const: Copy, - I::GenericArg: Copy, - I::TraitPredicate: Copy, - I::ProjectionPredicate: Copy, - I::TypeOutlivesPredicate: Copy, - I::RegionOutlivesPredicate: Copy, -{ -} - impl PartialEq for ClauseKind { fn eq(&self, other: &Self) -> bool { match (self, other) { @@ -120,7 +108,13 @@ where } #[derive(derivative::Derivative)] -#[derivative(Clone(bound = ""), Hash(bound = ""), PartialEq(bound = ""), Eq(bound = ""))] +#[derivative( + Clone(bound = ""), + Copy(bound = ""), + Hash(bound = ""), + PartialEq(bound = ""), + Eq(bound = "") +)] #[cfg_attr(feature = "nightly", derive(TyEncodable, TyDecodable, HashStable_NoContext))] pub enum PredicateKind { /// Prove a clause @@ -169,19 +163,6 @@ pub enum PredicateKind { AliasRelate(I::Term, I::Term, AliasRelationDirection), } -impl Copy for PredicateKind -where - I::DefId: Copy, - I::Const: Copy, - I::GenericArgs: Copy, - I::Term: Copy, - I::CoercePredicate: Copy, - I::SubtypePredicate: Copy, - I::NormalizesTo: Copy, - ClauseKind: Copy, -{ -} - impl TypeFoldable for PredicateKind where I::DefId: TypeFoldable, diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 4157d49287c..3b5e41e8d85 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -115,6 +115,7 @@ use self::RegionKind::*; #[derive(derivative::Derivative)] #[derivative( Clone(bound = ""), + Copy(bound = ""), PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), @@ -189,18 +190,6 @@ const fn regionkind_discriminant(value: &RegionKind) -> usize { } } -// This is manually implemented because a derive would require `I: Copy` -impl Copy for RegionKind -where - I::EarlyParamRegion: Copy, - I::BoundRegion: Copy, - I::LateParamRegion: Copy, - I::InferRegion: Copy, - I::PlaceholderRegion: Copy, - I::ErrorGuaranteed: Copy, -{ -} - // This is manually implemented because a derive would require `I: PartialEq` impl PartialEq for RegionKind { #[inline] From f3218b2a707aaf8de8ce2798865d3df4a7a0484a Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 11 Dec 2023 21:08:05 +0000 Subject: [PATCH 2/2] Make ConstKind and TyKind Copy --- compiler/rustc_middle/src/arena.rs | 4 ---- compiler/rustc_middle/src/ty/consts.rs | 3 ++- compiler/rustc_type_ir/src/const_kind.rs | 1 + compiler/rustc_type_ir/src/ty_kind.rs | 1 + 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 9b41b77928e..52fd494a10d 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -92,10 +92,6 @@ macro_rules! arena_types { [] name_set: rustc_data_structures::unord::UnordSet, [] ordered_name_set: rustc_data_structures::fx::FxIndexSet, - // Interned types - [] tys: rustc_type_ir::WithCachedTypeInfo>, - [] consts: rustc_type_ir::WithCachedTypeInfo>, - // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena // (during lowering) and the `librustc_middle` arena (for decoding MIR) diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 293df4f691d..3c52c45f3a8 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -41,7 +41,8 @@ impl<'tcx> ConstTy> for Const<'tcx> { } /// Typed constant value. -#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)] +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(HashStable, TyEncodable, TyDecodable)] pub struct ConstData<'tcx> { pub ty: Ty<'tcx>, pub kind: ConstKind<'tcx>, diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 879de58f100..0aaaad5af05 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -10,6 +10,7 @@ use self::ConstKind::*; #[derive(derivative::Derivative)] #[derivative( Clone(bound = ""), + Copy(bound = ""), PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""), diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index a7a5cae254c..72ca9199a53 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -111,6 +111,7 @@ pub enum AliasKind { #[derive(derivative::Derivative)] #[derivative( Clone(bound = ""), + Copy(bound = ""), PartialOrd(bound = ""), PartialOrd = "feature_allow_slow_enum", Ord(bound = ""),