Skip to content

Commit

Permalink
Rollup merge of rust-lang#66460 - cjgillot:hashstable_generic, r=Zoxc
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Centril authored Nov 21, 2019
2 parents 6bd7e74 + 44a595f commit 3fcba01
Show file tree
Hide file tree
Showing 22 changed files with 164 additions and 424 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,7 @@ dependencies = [
"log",
"rustc_data_structures",
"rustc_index",
"rustc_macros",
"serialize",
"syntax_pos",
]
Expand Down Expand Up @@ -4404,6 +4405,7 @@ dependencies = [
"rustc_errors",
"rustc_index",
"rustc_lexer",
"rustc_macros",
"scoped-tls",
"serialize",
"smallvec 1.0.0",
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,6 @@ impl<'a> HashStable<StableHashingContext<'a>> for hir::ImplItem {
}
}

impl_stable_hash_for!(enum ast::CrateSugar {
JustCrate,
PubCrate,
});

impl<'a> HashStable<StableHashingContext<'a>> for hir::VisibilityKind {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
Expand Down
7 changes: 0 additions & 7 deletions src/librustc/ich/impls_misc.rs

This file was deleted.

210 changes: 1 addition & 209 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,168 +10,22 @@ use syntax::ast;
use syntax::feature_gate;
use syntax::token;
use syntax::tokenstream;
use syntax_pos::symbol::SymbolStr;
use syntax_pos::SourceFile;

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

use smallvec::SmallVec;
use rustc_data_structures::stable_hasher::{HashStable, ToStableHashKey, StableHasher};

impl<'a> HashStable<StableHashingContext<'a>> for SymbolStr {
#[inline]
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let str = self as &str;
str.hash_stable(hcx, hasher)
}
}

impl<'a> ToStableHashKey<StableHashingContext<'a>> for SymbolStr {
type KeyType = SymbolStr;

#[inline]
fn to_stable_hash_key(&self,
_: &StableHashingContext<'a>)
-> SymbolStr {
self.clone()
}
}

impl<'a> HashStable<StableHashingContext<'a>> for ast::Name {
#[inline]
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
self.as_str().hash_stable(hcx, hasher);
}
}

impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::Name {
type KeyType = SymbolStr;

#[inline]
fn to_stable_hash_key(&self,
_: &StableHashingContext<'a>)
-> SymbolStr {
self.as_str()
}
}

impl_stable_hash_for!(enum ::syntax::ast::AsmDialect {
Att,
Intel
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::MacroKind {
Bang,
Attr,
Derive,
});


impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
Cdecl,
Stdcall,
Fastcall,
Vectorcall,
Thiscall,
Aapcs,
Win64,
SysV64,
PtxKernel,
Msp430Interrupt,
X86Interrupt,
AmdGpuKernel,
EfiApi,
Rust,
C,
System,
RustIntrinsic,
RustCall,
PlatformIntrinsic,
Unadjusted
});

impl_stable_hash_for!(struct ::syntax::attr::Deprecation { since, note });
impl_stable_hash_for!(struct ::syntax::attr::Stability {
level,
feature,
rustc_depr,
promotable,
allow_const_fn_ptr,
const_stability
});

impl_stable_hash_for!(enum ::syntax::edition::Edition {
Edition2015,
Edition2018,
});

impl<'a> HashStable<StableHashingContext<'a>>
for ::syntax::attr::StabilityLevel {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
mem::discriminant(self).hash_stable(hcx, hasher);
match *self {
::syntax::attr::StabilityLevel::Unstable { ref reason, ref issue, ref is_soft } => {
reason.hash_stable(hcx, hasher);
issue.hash_stable(hcx, hasher);
is_soft.hash_stable(hcx, hasher);
}
::syntax::attr::StabilityLevel::Stable { ref since } => {
since.hash_stable(hcx, hasher);
}
}
}
}

impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion });

impl_stable_hash_for!(enum ::syntax::attr::IntType {
SignedInt(int_ty),
UnsignedInt(uint_ty)
});

impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
Signed(int_ty),
Unsigned(int_ty),
Unsuffixed
});

impl_stable_hash_for!(enum ::syntax::ast::LitFloatType {
Suffixed(float_ty),
Unsuffixed
});
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

impl_stable_hash_for!(struct ::syntax::ast::Lit {
kind,
token,
span
});

impl_stable_hash_for!(enum ::syntax::ast::LitKind {
Str(value, style),
ByteStr(value),
Byte(value),
Char(value),
Int(value, lit_int_type),
Float(value, lit_float_type),
Bool(value),
Err(value)
});

impl_stable_hash_for_spanned!(::syntax::ast::LitKind);

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

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

impl_stable_hash_for!(enum token::LitKind {
Bool,
Byte,
Char,
Integer,
Float,
Str,
ByteStr,
StrRaw(n),
ByteStrRaw(n),
Err
});

impl_stable_hash_for!(struct token::Lit {
kind,
symbol,
suffix
});

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);
Expand Down Expand Up @@ -359,12 +194,6 @@ impl_stable_hash_for!(enum ::syntax::ast::MetaItemKind {
NameValue(lit)
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::Transparency {
Transparent,
SemiTransparent,
Opaque,
});

impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
kind,
parent -> _,
Expand All @@ -376,43 +205,6 @@ impl_stable_hash_for!(struct ::syntax_pos::hygiene::ExpnData {
edition
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::ExpnKind {
Root,
Macro(kind, descr),
AstPass(kind),
Desugaring(kind)
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::AstPass {
StdImports,
TestHarness,
ProcMacroHarness,
PluginMacroDefs,
});

impl_stable_hash_for!(enum ::syntax_pos::hygiene::DesugaringKind {
CondTemporary,
Async,
Await,
QuestionMark,
OpaqueTy,
ForLoop,
TryBlock
});

impl_stable_hash_for!(enum ::syntax_pos::FileName {
Real(pb),
Macros(s),
QuoteExpansion(s),
Anon(s),
MacroExpansion(s),
ProcMacroSourceCode(s),
CliCrateAttr(s),
CfgSpec(s),
Custom(s),
DocTest(pb, line),
});

impl<'a> HashStable<StableHashingContext<'a>> for SourceFile {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
let SourceFile {
Expand Down
5 changes: 0 additions & 5 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ where
}
}

impl_stable_hash_for!(enum ::syntax::ast::Mutability {
Immutable,
Mutable
});

impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
type KeyType = region::Scope;

Expand Down
1 change: 0 additions & 1 deletion src/librustc/ich/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ mod caching_source_map_view;
mod hcx;

mod impls_hir;
mod impls_misc;
mod impls_ty;
mod impls_syntax;

Expand Down
Loading

0 comments on commit 3fcba01

Please sign in to comment.