Skip to content

Commit 959be73

Browse files
committed
Auto merge of #155018 - nnethercote:simplify-HashStable, r=<try>
Simplify `HashStable`
2 parents dd82fd2 + ce139ba commit 959be73

92 files changed

Lines changed: 1001 additions & 1088 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_abi/src/callconv/reg.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#[cfg(feature = "nightly")]
2-
use rustc_macros::HashStable_Generic;
2+
use rustc_macros::HashStable;
33

44
use crate::{Align, HasDataLayout, Size};
55

6-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
6+
#[cfg_attr(feature = "nightly", derive(HashStable))]
77
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
88
pub enum RegKind {
99
Integer,
1010
Float,
1111
Vector,
1212
}
1313

14-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
14+
#[cfg_attr(feature = "nightly", derive(HashStable))]
1515
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1616
pub struct Reg {
1717
pub kind: RegKind,

compiler/rustc_abi/src/canon_abi.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt;
22

33
#[cfg(feature = "nightly")]
4-
use rustc_macros::HashStable_Generic;
4+
use rustc_macros::HashStable;
55

66
use crate::ExternAbi;
77

@@ -18,7 +18,7 @@ use crate::ExternAbi;
1818
/// rather than picking the "actual" ABI.
1919
#[derive(Copy, Clone, Debug)]
2020
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
21-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
21+
#[cfg_attr(feature = "nightly", derive(HashStable))]
2222
pub enum CanonAbi {
2323
// NOTE: the use of nested variants for some ABIs is for many targets they don't matter,
2424
// and this pushes the complexity of their reasoning to target-specific code,
@@ -111,7 +111,7 @@ impl fmt::Display for CanonAbi {
111111
/// These only affect callee codegen. making their categorization as distinct ABIs a bit peculiar.
112112
#[derive(Copy, Clone, Debug)]
113113
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
114-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
114+
#[cfg_attr(feature = "nightly", derive(HashStable))]
115115
pub enum InterruptKind {
116116
Avr,
117117
AvrNonBlocking,
@@ -126,7 +126,7 @@ pub enum InterruptKind {
126126
/// One of SysV64 or Win64 may alias the C ABI, and arguably Win64 is cross-platform now?
127127
#[derive(Clone, Copy, Debug)]
128128
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
129-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
129+
#[cfg_attr(feature = "nightly", derive(HashStable))]
130130
pub enum X86Call {
131131
/// "fastcall" has both GNU and Windows variants
132132
Fastcall,
@@ -141,7 +141,7 @@ pub enum X86Call {
141141
/// ABIs defined for 32-bit Arm
142142
#[derive(Copy, Clone, Debug)]
143143
#[derive(PartialOrd, Ord, PartialEq, Eq, Hash)]
144-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
144+
#[cfg_attr(feature = "nightly", derive(HashStable))]
145145
pub enum ArmCall {
146146
Aapcs,
147147
CCmseNonSecureCall,

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ use std::fmt;
33
use std::hash::{Hash, Hasher};
44

55
#[cfg(feature = "nightly")]
6-
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd};
6+
use rustc_data_structures::stable_hasher::{
7+
HashStable, HashStableContext, StableHasher, StableOrd,
8+
};
79
#[cfg(feature = "nightly")]
810
use rustc_macros::{Decodable, Encodable};
911
#[cfg(feature = "nightly")]
@@ -217,9 +219,9 @@ impl Hash for ExternAbi {
217219
}
218220

219221
#[cfg(feature = "nightly")]
220-
impl<C> HashStable<C> for ExternAbi {
222+
impl HashStable for ExternAbi {
221223
#[inline]
222-
fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) {
224+
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
223225
Hash::hash(self, hasher);
224226
}
225227
}

compiler/rustc_abi/src/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ rustc_index::newtype_index! {
4545
/// `b` is `FieldIdx(1)` in `VariantIdx(0)`,
4646
/// `d` is `FieldIdx(1)` in `VariantIdx(1)`, and
4747
/// `f` is `FieldIdx(1)` in `VariantIdx(0)`.
48-
#[stable_hash_generic]
48+
#[stable_hash]
4949
#[encodable]
5050
#[orderable]
5151
#[gate_rustc_only]
@@ -70,7 +70,7 @@ rustc_index::newtype_index! {
7070
///
7171
/// `struct`s, `tuples`, and `unions`s are considered to have a single variant
7272
/// with variant index zero, aka [`FIRST_VARIANT`].
73-
#[stable_hash_generic]
73+
#[stable_hash]
7474
#[encodable]
7575
#[orderable]
7676
#[gate_rustc_only]

compiler/rustc_abi/src/layout/ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::fmt;
22
use std::ops::Deref;
33

44
use rustc_data_structures::intern::Interned;
5-
use rustc_macros::HashStable_Generic;
5+
use rustc_macros::HashStable;
66

77
use crate::layout::{FieldIdx, VariantIdx};
88
use crate::{
@@ -12,7 +12,7 @@ use crate::{
1212

1313
// Explicitly import `Float` to avoid ambiguity with `Primitive::Float`.
1414

15-
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
15+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
1616
#[rustc_pass_by_value]
1717
pub struct Layout<'a>(pub Interned<'a, LayoutData<FieldIdx, VariantIdx>>);
1818

@@ -71,7 +71,7 @@ impl<'a> Layout<'a> {
7171
/// to that obtained from `layout_of(ty)`, as we need to produce
7272
/// layouts for which Rust types do not exist, such as enum variants
7373
/// or synthetic fields of enums (i.e., discriminants) and wide pointers.
74-
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable_Generic)]
74+
#[derive(Copy, Clone, PartialEq, Eq, Hash, HashStable)]
7575
pub struct TyAndLayout<'a, Ty> {
7676
pub ty: Ty,
7777
pub layout: Layout<'a>,

compiler/rustc_abi/src/lib.rs

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ use rustc_data_structures::stable_hasher::StableOrd;
4949
use rustc_hashes::Hash64;
5050
use rustc_index::{Idx, IndexSlice, IndexVec};
5151
#[cfg(feature = "nightly")]
52-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
52+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
5353

5454
mod callconv;
5555
mod canon_abi;
@@ -68,10 +68,7 @@ pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorErro
6868
pub use layout::{Layout, TyAbiInterface, TyAndLayout};
6969

7070
#[derive(Clone, Copy, PartialEq, Eq, Default)]
71-
#[cfg_attr(
72-
feature = "nightly",
73-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
74-
)]
71+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
7572
pub struct ReprFlags(u8);
7673

7774
bitflags! {
@@ -108,10 +105,7 @@ impl std::fmt::Debug for ReprFlags {
108105
}
109106

110107
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
111-
#[cfg_attr(
112-
feature = "nightly",
113-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
114-
)]
108+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
115109
pub enum IntegerType {
116110
/// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g.
117111
/// `Pointer(true)` means `isize`.
@@ -131,10 +125,7 @@ impl IntegerType {
131125
}
132126

133127
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
134-
#[cfg_attr(
135-
feature = "nightly",
136-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
137-
)]
128+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
138129
pub enum ScalableElt {
139130
/// `N` in `rustc_scalable_vector(N)` - the element count of the scalable vector
140131
ElementCount(u16),
@@ -145,10 +136,7 @@ pub enum ScalableElt {
145136

146137
/// Represents the repr options provided by the user.
147138
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
148-
#[cfg_attr(
149-
feature = "nightly",
150-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
151-
)]
139+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
152140
pub struct ReprOptions {
153141
pub int: Option<IntegerType>,
154142
pub align: Option<Align>,
@@ -745,10 +733,7 @@ impl FromStr for Endian {
745733

746734
/// Size of a type in bytes.
747735
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
748-
#[cfg_attr(
749-
feature = "nightly",
750-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
751-
)]
736+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
752737
pub struct Size {
753738
raw: u64,
754739
}
@@ -973,10 +958,7 @@ impl Step for Size {
973958

974959
/// Alignment of a type in bytes (always a power of two).
975960
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
976-
#[cfg_attr(
977-
feature = "nightly",
978-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
979-
)]
961+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
980962
pub struct Align {
981963
pow2: u8,
982964
}
@@ -1109,7 +1091,7 @@ impl Align {
11091091
/// An example of a rare thing actually affected by preferred alignment is aligning of statics.
11101092
/// It is of effectively no consequence for layout in structs and on the stack.
11111093
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1112-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1094+
#[cfg_attr(feature = "nightly", derive(HashStable))]
11131095
pub struct AbiAlign {
11141096
pub abi: Align,
11151097
}
@@ -1141,10 +1123,7 @@ impl Deref for AbiAlign {
11411123

11421124
/// Integers, also used for enum discriminants.
11431125
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1144-
#[cfg_attr(
1145-
feature = "nightly",
1146-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
1147-
)]
1126+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
11481127
pub enum Integer {
11491128
I8,
11501129
I16,
@@ -1304,7 +1283,7 @@ impl Integer {
13041283

13051284
/// Floating-point types.
13061285
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1307-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1286+
#[cfg_attr(feature = "nightly", derive(HashStable))]
13081287
pub enum Float {
13091288
F16,
13101289
F32,
@@ -1339,7 +1318,7 @@ impl Float {
13391318

13401319
/// Fundamental unit of memory access and layout.
13411320
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1342-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1321+
#[cfg_attr(feature = "nightly", derive(HashStable))]
13431322
pub enum Primitive {
13441323
/// The `bool` is the signedness of the `Integer` type.
13451324
///
@@ -1387,7 +1366,7 @@ impl Primitive {
13871366
///
13881367
/// This is intended specifically to mirror LLVM’s `!range` metadata semantics.
13891368
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1390-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1369+
#[cfg_attr(feature = "nightly", derive(HashStable))]
13911370
pub struct WrappingRange {
13921371
pub start: u128,
13931372
pub end: u128,
@@ -1499,7 +1478,7 @@ impl fmt::Debug for WrappingRange {
14991478

15001479
/// Information about one scalar component of a Rust type.
15011480
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1502-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1481+
#[cfg_attr(feature = "nightly", derive(HashStable))]
15031482
pub enum Scalar {
15041483
Initialized {
15051484
value: Primitive,
@@ -1603,7 +1582,7 @@ impl Scalar {
16031582
// NOTE: This struct is generic over the FieldIdx for rust-analyzer usage.
16041583
/// Describes how the fields of a type are located in memory.
16051584
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1606-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1585+
#[cfg_attr(feature = "nightly", derive(HashStable))]
16071586
pub enum FieldsShape<FieldIdx: Idx> {
16081587
/// Scalar primitives and `!`, which never have fields.
16091588
Primitive,
@@ -1688,7 +1667,7 @@ impl<FieldIdx: Idx> FieldsShape<FieldIdx> {
16881667
/// should operate on. Special address spaces have an effect on code generation,
16891668
/// depending on the target and the address spaces it implements.
16901669
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1691-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1670+
#[cfg_attr(feature = "nightly", derive(HashStable))]
16921671
pub struct AddressSpace(pub u32);
16931672

16941673
impl AddressSpace {
@@ -1698,7 +1677,7 @@ impl AddressSpace {
16981677

16991678
/// How many scalable vectors are in a `BackendRepr::ScalableVector`?
17001679
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1701-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1680+
#[cfg_attr(feature = "nightly", derive(HashStable))]
17021681
pub struct NumScalableVectors(pub u8);
17031682

17041683
impl NumScalableVectors {
@@ -1729,7 +1708,7 @@ impl NumScalableVectors {
17291708
/// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector,
17301709
/// and larger values will usually prefer to be represented as memory.
17311710
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1732-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1711+
#[cfg_attr(feature = "nightly", derive(HashStable))]
17331712
pub enum BackendRepr {
17341713
Scalar(Scalar),
17351714
ScalarPair(Scalar, Scalar),
@@ -1873,7 +1852,7 @@ impl BackendRepr {
18731852

18741853
// NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage.
18751854
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1876-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1855+
#[cfg_attr(feature = "nightly", derive(HashStable))]
18771856
pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
18781857
/// A type with no valid variants. Must be uninhabited.
18791858
Empty,
@@ -1900,7 +1879,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
19001879

19011880
// NOTE: This struct is generic over the VariantIdx for rust-analyzer usage.
19021881
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1903-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1882+
#[cfg_attr(feature = "nightly", derive(HashStable))]
19041883
pub enum TagEncoding<VariantIdx: Idx> {
19051884
/// The tag directly stores the discriminant, but possibly with a smaller layout
19061885
/// (so converting the tag to the discriminant can require sign extension).
@@ -1941,7 +1920,7 @@ pub enum TagEncoding<VariantIdx: Idx> {
19411920
}
19421921

19431922
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1944-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1923+
#[cfg_attr(feature = "nightly", derive(HashStable))]
19451924
pub struct Niche {
19461925
pub offset: Size,
19471926
pub value: Primitive,
@@ -2028,7 +2007,7 @@ impl Niche {
20282007

20292008
// NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage.
20302009
#[derive(PartialEq, Eq, Hash, Clone)]
2031-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
2010+
#[cfg_attr(feature = "nightly", derive(HashStable))]
20322011
pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
20332012
/// Says where the fields are located within the layout.
20342013
pub fields: FieldsShape<FieldIdx>,

0 commit comments

Comments
 (0)