-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Use proc-macro to derive HashStable everywhere #66279
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
3e969e0
1de5fdb
640797f
bf7c9ba
3c5ddfd
0073d3b
31298b4
e85c195
8c86a79
edc5232
9efd320
ce30107
ea0c354
7e411e7
4d1674f
782cc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,21 @@ use std::mem; | |
use syntax::ast; | ||
use syntax::feature_gate; | ||
use syntax::token; | ||
use syntax::tokenstream; | ||
use syntax_pos::SourceFile; | ||
|
||
use crate::hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX}; | ||
|
||
use smallvec::SmallVec; | ||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; | ||
|
||
impl_stable_hash_for!(struct ::syntax::ast::Lit { | ||
kind, | ||
token, | ||
span | ||
}); | ||
impl<'ctx> rustc_target::StableHashingContextLike for StableHashingContext<'ctx> {} | ||
|
||
impl_stable_hash_for_spanned!(::syntax::ast::LitKind); | ||
|
||
impl_stable_hash_for!(struct ::syntax::ast::Lifetime { id, ident }); | ||
impl<'a> HashStable<StableHashingContext<'a>> for ast::Lifetime { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It requires hashing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, ok. You can leave that for a later PR. |
||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
self.id.hash_stable(hcx, hasher); | ||
self.ident.hash_stable(hcx, hasher); | ||
} | ||
} | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
|
@@ -50,20 +48,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for [ast::Attribute] { | |
} | ||
} | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> for ast::Path { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
self.segments.len().hash_stable(hcx, hasher); | ||
for segment in &self.segments { | ||
segment.ident.name.hash_stable(hcx, hasher); | ||
} | ||
} | ||
} | ||
|
||
impl_stable_hash_for!(struct ::syntax::ast::AttrItem { | ||
path, | ||
tokens, | ||
}); | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
// Make sure that these have been filtered out. | ||
|
@@ -81,38 +65,10 @@ impl<'a> HashStable<StableHashingContext<'a>> for ast::Attribute { | |
} | ||
} | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> | ||
for tokenstream::TokenTree { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
mem::discriminant(self).hash_stable(hcx, hasher); | ||
match *self { | ||
tokenstream::TokenTree::Token(ref token) => { | ||
token.hash_stable(hcx, hasher); | ||
} | ||
tokenstream::TokenTree::Delimited(span, delim, ref tts) => { | ||
span.hash_stable(hcx, hasher); | ||
std_hash::Hash::hash(&delim, hasher); | ||
for sub_tt in tts.trees() { | ||
sub_tt.hash_stable(hcx, hasher); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> | ||
for tokenstream::TokenStream { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
for sub_tt in self.trees() { | ||
sub_tt.hash_stable(hcx, hasher); | ||
} | ||
} | ||
} | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
mem::discriminant(self).hash_stable(hcx, hasher); | ||
match *self { | ||
impl<'ctx> syntax::StableHashingContextLike for StableHashingContext<'ctx> { | ||
fn hash_stable_tokenkind(&mut self, tokenkind: &token::TokenKind, hasher: &mut StableHasher) { | ||
mem::discriminant(tokenkind).hash_stable(self, hasher); | ||
match *tokenkind { | ||
token::Eq | | ||
token::Lt | | ||
token::Le | | ||
|
@@ -153,58 +109,25 @@ impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind { | |
token::CloseDelim(delim_token) => { | ||
std_hash::Hash::hash(&delim_token, hasher); | ||
} | ||
token::Literal(lit) => lit.hash_stable(hcx, hasher), | ||
token::Literal(lit) => lit.hash_stable(self, hasher), | ||
|
||
token::Ident(name, is_raw) => { | ||
name.hash_stable(hcx, hasher); | ||
is_raw.hash_stable(hcx, hasher); | ||
name.hash_stable(self, hasher); | ||
is_raw.hash_stable(self, hasher); | ||
} | ||
token::Lifetime(name) => name.hash_stable(hcx, hasher), | ||
token::Lifetime(name) => name.hash_stable(self, hasher), | ||
|
||
token::Interpolated(_) => { | ||
bug!("interpolated tokens should not be present in the HIR") | ||
Zoxc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
token::DocComment(val) | | ||
token::Shebang(val) | | ||
token::Unknown(val) => val.hash_stable(hcx, hasher), | ||
token::Unknown(val) => val.hash_stable(self, hasher), | ||
} | ||
} | ||
} | ||
|
||
impl_stable_hash_for!(struct token::Token { | ||
kind, | ||
span | ||
}); | ||
|
||
impl_stable_hash_for!(enum ::syntax::ast::NestedMetaItem { | ||
MetaItem(meta_item), | ||
Literal(lit) | ||
}); | ||
|
||
impl_stable_hash_for!(struct ::syntax::ast::MetaItem { | ||
path, | ||
kind, | ||
span | ||
}); | ||
|
||
impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind { | ||
Word, | ||
List(nested_items), | ||
NameValue(lit) | ||
}); | ||
|
||
impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData { | ||
kind, | ||
parent -> _, | ||
call_site, | ||
def_site, | ||
allow_internal_unstable, | ||
allow_internal_unsafe, | ||
local_inner_macros, | ||
edition | ||
}); | ||
|
||
impl<'a> HashStable<StableHashingContext<'a>> for SourceFile { | ||
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) { | ||
let SourceFile { | ||
|
Uh oh!
There was an error while loading. Please reload this page.