Skip to content

Commit f53b654

Browse files
committed
Auto merge of #155018 - nnethercote:simplify-HashStable, r=fee1-dead
Simplify `HashStable` This PR: - Simplifies the `HashStable` trait, by moving its generic parameter from the trait to its single method. - Eliminates the need for the non-obvious `derive(HashStable)`/`derive(HashStable_Generic)` distinction. - Reduces the need for, and clarifies, the non-obvious `derive(HashStable)`/`derive(HashStable_NoContext)` distinction. r? @fee1-dead
2 parents 57f772f + 20060c6 commit f53b654

92 files changed

Lines changed: 994 additions & 1045 deletions

File tree

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,9 +1,9 @@
11
#[cfg(feature = "nightly")]
2-
use rustc_macros::HashStable_Generic;
2+
use rustc_macros::HashStable;
33

44
use crate::{Align, HasDataLayout, Integer, Primitive, 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,
@@ -16,7 +16,7 @@ pub enum RegKind {
1616
},
1717
}
1818

19-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
19+
#[cfg_attr(feature = "nightly", derive(HashStable))]
2020
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
2121
pub struct Reg {
2222
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")]
@@ -240,9 +242,9 @@ impl Hash for ExternAbi {
240242
}
241243

242244
#[cfg(feature = "nightly")]
243-
impl<C> HashStable<C> for ExternAbi {
245+
impl HashStable for ExternAbi {
244246
#[inline]
245-
fn hash_stable(&self, _: &mut C, hasher: &mut StableHasher) {
247+
fn hash_stable<Hcx: HashStableContext>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
246248
Hash::hash(self, hasher);
247249
}
248250
}

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
@@ -53,7 +53,7 @@ use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, m
5353
use rustc_hashes::Hash64;
5454
use rustc_index::{Idx, IndexSlice, IndexVec};
5555
#[cfg(feature = "nightly")]
56-
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
56+
use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
5757
#[cfg(feature = "nightly")]
5858
use rustc_span::{Symbol, sym};
5959

@@ -74,10 +74,7 @@ pub use layout::{FIRST_VARIANT, FieldIdx, LayoutCalculator, LayoutCalculatorErro
7474
pub use layout::{Layout, TyAbiInterface, TyAndLayout};
7575

7676
#[derive(Clone, Copy, PartialEq, Eq, Default)]
77-
#[cfg_attr(
78-
feature = "nightly",
79-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
80-
)]
77+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
8178
pub struct ReprFlags(u8);
8279

8380
bitflags! {
@@ -114,10 +111,7 @@ impl std::fmt::Debug for ReprFlags {
114111
}
115112

116113
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
117-
#[cfg_attr(
118-
feature = "nightly",
119-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
120-
)]
114+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
121115
pub enum IntegerType {
122116
/// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g.
123117
/// `Pointer(true)` means `isize`.
@@ -137,10 +131,7 @@ impl IntegerType {
137131
}
138132

139133
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
140-
#[cfg_attr(
141-
feature = "nightly",
142-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
143-
)]
134+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
144135
pub enum ScalableElt {
145136
/// `N` in `rustc_scalable_vector(N)` - the element count of the scalable vector
146137
ElementCount(u16),
@@ -151,10 +142,7 @@ pub enum ScalableElt {
151142

152143
/// Represents the repr options provided by the user.
153144
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
154-
#[cfg_attr(
155-
feature = "nightly",
156-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
157-
)]
145+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
158146
pub struct ReprOptions {
159147
pub int: Option<IntegerType>,
160148
pub align: Option<Align>,
@@ -804,10 +792,7 @@ impl FromStr for Endian {
804792

805793
/// Size of a type in bytes.
806794
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
807-
#[cfg_attr(
808-
feature = "nightly",
809-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
810-
)]
795+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
811796
pub struct Size {
812797
raw: u64,
813798
}
@@ -1032,10 +1017,7 @@ impl Step for Size {
10321017

10331018
/// Alignment of a type in bytes (always a power of two).
10341019
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
1035-
#[cfg_attr(
1036-
feature = "nightly",
1037-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
1038-
)]
1020+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
10391021
pub struct Align {
10401022
pow2: u8,
10411023
}
@@ -1168,7 +1150,7 @@ impl Align {
11681150
/// An example of a rare thing actually affected by preferred alignment is aligning of statics.
11691151
/// It is of effectively no consequence for layout in structs and on the stack.
11701152
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1171-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1153+
#[cfg_attr(feature = "nightly", derive(HashStable))]
11721154
pub struct AbiAlign {
11731155
pub abi: Align,
11741156
}
@@ -1200,10 +1182,7 @@ impl Deref for AbiAlign {
12001182

12011183
/// Integers, also used for enum discriminants.
12021184
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1203-
#[cfg_attr(
1204-
feature = "nightly",
1205-
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
1206-
)]
1185+
#[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable))]
12071186
pub enum Integer {
12081187
I8,
12091188
I16,
@@ -1363,7 +1342,7 @@ impl Integer {
13631342

13641343
/// Floating-point types.
13651344
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
1366-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1345+
#[cfg_attr(feature = "nightly", derive(HashStable))]
13671346
pub enum Float {
13681347
F16,
13691348
F32,
@@ -1398,7 +1377,7 @@ impl Float {
13981377

13991378
/// Fundamental unit of memory access and layout.
14001379
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
1401-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1380+
#[cfg_attr(feature = "nightly", derive(HashStable))]
14021381
pub enum Primitive {
14031382
/// The `bool` is the signedness of the `Integer` type.
14041383
///
@@ -1446,7 +1425,7 @@ impl Primitive {
14461425
///
14471426
/// This is intended specifically to mirror LLVM’s `!range` metadata semantics.
14481427
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1449-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1428+
#[cfg_attr(feature = "nightly", derive(HashStable))]
14501429
pub struct WrappingRange {
14511430
pub start: u128,
14521431
pub end: u128,
@@ -1558,7 +1537,7 @@ impl fmt::Debug for WrappingRange {
15581537

15591538
/// Information about one scalar component of a Rust type.
15601539
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1561-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1540+
#[cfg_attr(feature = "nightly", derive(HashStable))]
15621541
pub enum Scalar {
15631542
Initialized {
15641543
value: Primitive,
@@ -1662,7 +1641,7 @@ impl Scalar {
16621641
// NOTE: This struct is generic over the FieldIdx for rust-analyzer usage.
16631642
/// Describes how the fields of a type are located in memory.
16641643
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1665-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1644+
#[cfg_attr(feature = "nightly", derive(HashStable))]
16661645
pub enum FieldsShape<FieldIdx: Idx> {
16671646
/// Scalar primitives and `!`, which never have fields.
16681647
Primitive,
@@ -1747,7 +1726,7 @@ impl<FieldIdx: Idx> FieldsShape<FieldIdx> {
17471726
/// should operate on. Special address spaces have an effect on code generation,
17481727
/// depending on the target and the address spaces it implements.
17491728
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1750-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1729+
#[cfg_attr(feature = "nightly", derive(HashStable))]
17511730
pub struct AddressSpace(pub u32);
17521731

17531732
impl AddressSpace {
@@ -1760,7 +1739,7 @@ impl AddressSpace {
17601739

17611740
/// How many scalable vectors are in a `BackendRepr::ScalableVector`?
17621741
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1763-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1742+
#[cfg_attr(feature = "nightly", derive(HashStable))]
17641743
pub struct NumScalableVectors(pub u8);
17651744

17661745
impl NumScalableVectors {
@@ -1809,7 +1788,7 @@ impl IntoDiagArg for NumScalableVectors {
18091788
/// Generally, a codegen backend will prefer to handle smaller values as a scalar or short vector,
18101789
/// and larger values will usually prefer to be represented as memory.
18111790
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1812-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1791+
#[cfg_attr(feature = "nightly", derive(HashStable))]
18131792
pub enum BackendRepr {
18141793
Scalar(Scalar),
18151794
ScalarPair(Scalar, Scalar),
@@ -1953,7 +1932,7 @@ impl BackendRepr {
19531932

19541933
// NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage.
19551934
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1956-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1935+
#[cfg_attr(feature = "nightly", derive(HashStable))]
19571936
pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
19581937
/// A type with no valid variants. Must be uninhabited.
19591938
Empty,
@@ -1980,7 +1959,7 @@ pub enum Variants<FieldIdx: Idx, VariantIdx: Idx> {
19801959

19811960
// NOTE: This struct is generic over the VariantIdx for rust-analyzer usage.
19821961
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
1983-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
1962+
#[cfg_attr(feature = "nightly", derive(HashStable))]
19841963
pub enum TagEncoding<VariantIdx: Idx> {
19851964
/// The tag directly stores the discriminant, but possibly with a smaller layout
19861965
/// (so converting the tag to the discriminant can require sign extension).
@@ -2021,7 +2000,7 @@ pub enum TagEncoding<VariantIdx: Idx> {
20212000
}
20222001

20232002
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
2024-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
2003+
#[cfg_attr(feature = "nightly", derive(HashStable))]
20252004
pub struct Niche {
20262005
pub offset: Size,
20272006
pub value: Primitive,
@@ -2118,7 +2097,7 @@ impl Niche {
21182097

21192098
// NOTE: This struct is generic over the FieldIdx and VariantIdx for rust-analyzer usage.
21202099
#[derive(PartialEq, Eq, Hash, Clone)]
2121-
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))]
2100+
#[cfg_attr(feature = "nightly", derive(HashStable))]
21222101
pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
21232102
/// Says where the fields are located within the layout.
21242103
pub fields: FieldsShape<FieldIdx>,

0 commit comments

Comments
 (0)