Skip to content

Commit f16a729

Browse files
authored
Rollup merge of rust-lang#66460 - cjgillot:hashstable_generic, r=Zoxc
Add a proc-macro to derive HashStable in librustc dependencies A second proc-macro is added to derive HashStable for crates librustc depends on. This proc-macro HashStable_Generic (to bikeshed) allows to decouple code and some librustc's boilerplate. Not everything is migrated, because `Span` and `TokenKind` require to be placed inside librustc. Types using them stay there too. Split out of rust-lang#66279 r? @Zoxc
2 parents 360ddc3 + 44a595f commit f16a729

File tree

22 files changed

+164
-424
lines changed

22 files changed

+164
-424
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -3837,6 +3837,7 @@ dependencies = [
38373837
"log",
38383838
"rustc_data_structures",
38393839
"rustc_index",
3840+
"rustc_macros",
38403841
"serialize",
38413842
"syntax_pos",
38423843
]
@@ -4404,6 +4405,7 @@ dependencies = [
44044405
"rustc_errors",
44054406
"rustc_index",
44064407
"rustc_lexer",
4408+
"rustc_macros",
44074409
"scoped-tls",
44084410
"serialize",
44094411
"smallvec 1.0.0",

src/librustc/ich/impls_hir.rs

-5
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
213213
}
214214
}
215215

216-
impl_stable_hash_for!(enum ast::CrateSugar {
217-
JustCrate,
218-
PubCrate,
219-
});
220-
221216
impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
222217
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
223218
mem::discriminant(self).hash_stable(hcx, hasher);

src/librustc/ich/impls_misc.rs

-7
This file was deleted.

src/librustc/ich/impls_syntax.rs

+1-209
Original file line numberDiff line numberDiff line change
@@ -10,168 +10,22 @@ use syntax::ast;
1010
use syntax::feature_gate;
1111
use syntax::token;
1212
use syntax::tokenstream;
13-
use syntax_pos::symbol::SymbolStr;
1413
use syntax_pos::SourceFile;
1514

1615
use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
1716

1817
use smallvec::SmallVec;
19-
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};
20-
21-
impl<'a> HashStable<StableHashingContext<'a>> for SymbolStr {
22-
#[inline]
23-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
24-
let str = self as &str;
25-
str.hash_stable(hcx, hasher)
26-
}
27-
}
28-
29-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for SymbolStr {
30-
type KeyType = SymbolStr;
31-
32-
#[inline]
33-
fn to_stable_hash_key(&self,
34-
_: &StableHashingContext<'a>)
35-
-> SymbolStr {
36-
self.clone()
37-
}
38-
}
39-
40-
impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
41-
#[inline]
42-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
43-
self.as_str().hash_stable(hcx, hasher);
44-
}
45-
}
46-
47-
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
48-
type KeyType = SymbolStr;
49-
50-
#[inline]
51-
fn to_stable_hash_key(&self,
52-
_: &StableHashingContext<'a>)
53-
-> SymbolStr {
54-
self.as_str()
55-
}
56-
}
57-
58-
impl_stable_hash_for!(enum ::syntax::ast::AsmDialect {
59-
Att,
60-
Intel
61-
});
62-
63-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind {
64-
Bang,
65-
Attr,
66-
Derive,
67-
});
68-
69-
70-
impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
71-
Cdecl,
72-
Stdcall,
73-
Fastcall,
74-
Vectorcall,
75-
Thiscall,
76-
Aapcs,
77-
Win64,
78-
SysV64,
79-
PtxKernel,
80-
Msp430Interrupt,
81-
X86Interrupt,
82-
AmdGpuKernel,
83-
EfiApi,
84-
Rust,
85-
C,
86-
System,
87-
RustIntrinsic,
88-
RustCall,
89-
PlatformIntrinsic,
90-
Unadjusted
91-
});
92-
93-
impl_stable_hash_for!(struct ::syntax::attr::Deprecation { since, note });
94-
impl_stable_hash_for!(struct ::syntax::attr::Stability {
95-
level,
96-
feature,
97-
rustc_depr,
98-
promotable,
99-
allow_const_fn_ptr,
100-
const_stability
101-
});
102-
103-
impl_stable_hash_for!(enum ::syntax::edition::Edition {
104-
Edition2015,
105-
Edition2018,
106-
});
107-
108-
impl<'a> HashStable<StableHashingContext<'a>>
109-
for ::syntax::attr::StabilityLevel {
110-
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
111-
mem::discriminant(self).hash_stable(hcx, hasher);
112-
match *self {
113-
::syntax::attr::StabilityLevel::Unstable { ref reason, ref issue, ref is_soft } => {
114-
reason.hash_stable(hcx, hasher);
115-
issue.hash_stable(hcx, hasher);
116-
is_soft.hash_stable(hcx, hasher);
117-
}
118-
::syntax::attr::StabilityLevel::Stable { ref since } => {
119-
since.hash_stable(hcx, hasher);
120-
}
121-
}
122-
}
123-
}
124-
125-
impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion });
126-
127-
impl_stable_hash_for!(enum ::syntax::attr::IntType {
128-
SignedInt(int_ty),
129-
UnsignedInt(uint_ty)
130-
});
131-
132-
impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
133-
Signed(int_ty),
134-
Unsigned(int_ty),
135-
Unsuffixed
136-
});
137-
138-
impl_stable_hash_for!(enum ::syntax::ast::LitFloatType {
139-
Suffixed(float_ty),
140-
Unsuffixed
141-
});
18+
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
14219

14320
impl_stable_hash_for!(struct ::syntax::ast::Lit {
14421
kind,
14522
token,
14623
span
14724
});
14825

149-
impl_stable_hash_for!(enum ::syntax::ast::LitKind {
150-
Str(value, style),
151-
ByteStr(value),
152-
Byte(value),
153-
Char(value),
154-
Int(value, lit_int_type),
155-
Float(value, lit_float_type),
156-
Bool(value),
157-
Err(value)
158-
});
159-
16026
impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
16127

162-
impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 });
163-
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 });
164-
impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
165-
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
166-
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
167-
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });
16828
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident });
169-
impl_stable_hash_for!(enum ::syntax::ast::StrStyle { Cooked, Raw(pounds) });
170-
impl_stable_hash_for!(enum ::syntax::ast::AttrStyle { Outer, Inner });
171-
impl_stable_hash_for!(enum ::syntax::ast::Movability { Static, Movable });
172-
impl_stable_hash_for!(enum ::syntax::ast::CaptureBy { Value, Ref });
173-
impl_stable_hash_for!(enum ::syntax::ast::IsAuto { Yes, No });
174-
impl_stable_hash_for!(enum ::syntax::ast::ImplPolarity { Positive, Negative });
17529

17630
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] {
17731
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
@@ -255,25 +109,6 @@ for tokenstream::TokenStream {
255109
}
256110
}
257111

258-
impl_stable_hash_for!(enum token::LitKind {
259-
Bool,
260-
Byte,
261-
Char,
262-
Integer,
263-
Float,
264-
Str,
265-
ByteStr,
266-
StrRaw(n),
267-
ByteStrRaw(n),
268-
Err
269-
});
270-
271-
impl_stable_hash_for!(struct token::Lit {
272-
kind,
273-
symbol,
274-
suffix
275-
});
276-
277112
impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind {
278113
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
279114
mem::discriminant(self).hash_stable(hcx, hasher);
@@ -359,12 +194,6 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {
359194
NameValue(lit)
360195
});
361196

362-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
363-
Transparent,
364-
SemiTransparent,
365-
Opaque,
366-
});
367-
368197
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
369198
kind,
370199
parent -> _,
@@ -376,43 +205,6 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
376205
edition
377206
});
378207

379-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
380-
Root,
381-
Macro(kind, descr),
382-
AstPass(kind),
383-
Desugaring(kind)
384-
});
385-
386-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass {
387-
StdImports,
388-
TestHarness,
389-
ProcMacroHarness,
390-
PluginMacroDefs,
391-
});
392-
393-
impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
394-
CondTemporary,
395-
Async,
396-
Await,
397-
QuestionMark,
398-
OpaqueTy,
399-
ForLoop,
400-
TryBlock
401-
});
402-
403-
impl_stable_hash_for!(enum ::syntax_pos::FileName {
404-
Real(pb),
405-
Macros(s),
406-
QuoteExpansion(s),
407-
Anon(s),
408-
MacroExpansion(s),
409-
ProcMacroSourceCode(s),
410-
CliCrateAttr(s),
411-
CfgSpec(s),
412-
Custom(s),
413-
DocTest(pb, line),
414-
});
415-
416208
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
417209
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
418210
let SourceFile {

src/librustc/ich/impls_ty.rs

-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ where
159159
}
160160
}
161161

162-
impl_stable_hash_for!(enum ::syntax::ast::Mutability {
163-
Immutable,
164-
Mutable
165-
});
166-
167162
impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
168163
type KeyType = region::Scope;
169164

src/librustc/ich/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ mod caching_source_map_view;
1010
mod hcx;
1111

1212
mod impls_hir;
13-
mod impls_misc;
1413
mod impls_ty;
1514
mod impls_syntax;
1615

0 commit comments

Comments
 (0)