Support delegation in stable hashing macros

This commit is contained in:
Vadim Petrochenkov 2018-06-16 17:09:42 +03:00
parent f0622dfe5d
commit d5e9dffddf
4 changed files with 115 additions and 280 deletions

View file

@ -357,20 +357,11 @@ impl_stable_hash_for!(enum hir::FunctionRetTy {
Return(t)
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitRef {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::TraitRef {
ref path,
// Don't hash the ref_id. It is tracked via the thing it is used to access
ref_id: _,
} = *self;
path.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::TraitRef {
// Don't hash the ref_id. It is tracked via the thing it is used to access
ref_id -> _,
path,
});
impl_stable_hash_for!(struct hir::PolyTraitRef {
bound_generic_params,
@ -393,66 +384,32 @@ impl_stable_hash_for!(struct hir::MacroDef {
body
});
impl_stable_hash_for!(struct hir::Block {
stmts,
expr,
id -> _,
hir_id -> _,
rules,
span,
targeted_by_break,
recovered,
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::Block {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Block {
ref stmts,
ref expr,
id: _,
hir_id: _,
rules,
span,
targeted_by_break,
recovered,
} = *self;
stmts.hash_stable(hcx, hasher);
expr.hash_stable(hcx, hasher);
rules.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
recovered.hash_stable(hcx, hasher);
targeted_by_break.hash_stable(hcx, hasher);
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::Pat {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Pat {
id: _,
hir_id: _,
ref node,
ref span
} = *self;
node.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::Pat {
id -> _,
hir_id -> _,
node,
span,
});
impl_stable_hash_for_spanned!(hir::FieldPat);
impl<'a> HashStable<StableHashingContext<'a>> for hir::FieldPat {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::FieldPat {
id: _,
ident,
ref pat,
is_shorthand,
} = *self;
ident.hash_stable(hcx, hasher);
pat.hash_stable(hcx, hasher);
is_shorthand.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::FieldPat {
id -> _,
ident,
pat,
is_shorthand,
});
impl_stable_hash_for!(enum hir::BindingAnnotation {
Unannotated,
@ -535,24 +492,13 @@ impl_stable_hash_for!(struct hir::Arm {
body
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::Field {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Field {
id: _,
ident,
ref expr,
span,
is_shorthand,
} = *self;
ident.hash_stable(hcx, hasher);
expr.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
is_shorthand.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::Field {
id -> _,
ident,
expr,
span,
is_shorthand,
});
impl_stable_hash_for_spanned!(ast::Name);
@ -684,19 +630,10 @@ impl_stable_hash_for!(enum hir::LoopIdError {
UnresolvedLabel
});
impl<'a> HashStable<StableHashingContext<'a>> for ast::Ident {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ast::Ident {
name,
span,
} = *self;
name.hash_stable(hcx, hasher);
span.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct ast::Ident {
name,
span,
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitItem {
fn hash_stable<W: StableHasherResult>(&self,
@ -816,21 +753,13 @@ impl_stable_hash_for!(enum hir::ImplPolarity {
Negative
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::Mod {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::Mod {
inner,
// We are not hashing the IDs of the items contained in the module.
// This is harmless and matches the current behavior but it's not
// actually correct. See issue #40876.
item_ids: _,
} = *self;
inner.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::Mod {
inner,
// We are not hashing the IDs of the items contained in the module.
// This is harmless and matches the current behavior but it's not
// actually correct. See issue #40876.
item_ids -> _,
});
impl_stable_hash_for!(struct hir::ForeignMod {
abi,
@ -931,8 +860,7 @@ impl_stable_hash_for!(struct hir::ImplItemRef {
defaultness
});
impl<'a> HashStable<StableHashingContext<'a>>
for hir::AssociatedItemKind {
impl<'a> HashStable<StableHashingContext<'a>> for hir::AssociatedItemKind {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
@ -1012,45 +940,22 @@ impl_stable_hash_for!(struct hir::InlineAsmOutput {
is_indirect
});
impl<'a> HashStable<StableHashingContext<'a>> for hir::GlobalAsm {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::GlobalAsm {
asm,
ctxt: _
} = *self;
impl_stable_hash_for!(struct hir::GlobalAsm {
asm,
ctxt -> _, // This is used for error reporting
});
asm.hash_stable(hcx, hasher);
}
}
impl<'a> HashStable<StableHashingContext<'a>> for hir::InlineAsm {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let hir::InlineAsm {
asm,
asm_str_style,
ref outputs,
ref inputs,
ref clobbers,
volatile,
alignstack,
dialect,
ctxt: _, // This is used for error reporting
} = *self;
asm.hash_stable(hcx, hasher);
asm_str_style.hash_stable(hcx, hasher);
outputs.hash_stable(hcx, hasher);
inputs.hash_stable(hcx, hasher);
clobbers.hash_stable(hcx, hasher);
volatile.hash_stable(hcx, hasher);
alignstack.hash_stable(hcx, hasher);
dialect.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::InlineAsm {
asm,
asm_str_style,
outputs,
inputs,
clobbers,
volatile,
alignstack,
dialect,
ctxt -> _, // This is used for error reporting
});
impl_stable_hash_for!(enum hir::def::CtorKind {
Fn,
@ -1113,8 +1018,7 @@ impl_stable_hash_for!(enum hir::Constness {
NotConst
});
impl<'a> HashStable<StableHashingContext<'a>>
for hir::def_id::DefIndex {
impl<'a> HashStable<StableHashingContext<'a>> for hir::def_id::DefIndex {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
@ -1140,8 +1044,7 @@ impl_stable_hash_for!(struct hir::def::Export {
span
});
impl<'a> HashStable<StableHashingContext<'a>>
for ::middle::lang_items::LangItem {
impl<'a> HashStable<StableHashingContext<'a>> for ::middle::lang_items::LangItem {
fn hash_stable<W: StableHasherResult>(&self,
_: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
@ -1154,8 +1057,7 @@ impl_stable_hash_for!(struct ::middle::lang_items::LanguageItems {
missing
});
impl<'a> HashStable<StableHashingContext<'a>>
for hir::TraitCandidate {
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
@ -1189,26 +1091,13 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::TraitCandidate {
}
}
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrs
{
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'hir>,
hasher: &mut StableHasher<W>) {
let hir::CodegenFnAttrs {
flags,
inline,
export_name,
ref target_features,
linkage,
} = *self;
flags.hash_stable(hcx, hasher);
inline.hash_stable(hcx, hasher);
export_name.hash_stable(hcx, hasher);
target_features.hash_stable(hcx, hasher);
linkage.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct hir::CodegenFnAttrs {
flags,
inline,
export_name,
target_features,
linkage,
});
impl<'hir> HashStable<StableHashingContext<'hir>> for hir::CodegenFnAttrFlags
{

View file

@ -357,17 +357,11 @@ impl_stable_hash_for!(enum ty::VariantDiscr {
Relative(distance)
});
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::FieldDef {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::FieldDef { did, ident, vis } = *self;
did.hash_stable(hcx, hasher);
ident.name.hash_stable(hcx, hasher);
vis.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct ty::FieldDef {
did,
ident -> (ident.name),
vis,
});
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
for ::middle::const_val::ConstVal<'gcx> {
@ -545,15 +539,7 @@ impl_stable_hash_for!(struct ty::GenericPredicates<'tcx> {
predicates
});
impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
for ::mir::interpret::EvalError<'gcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
self.kind.hash_stable(hcx, hasher)
}
}
impl_stable_hash_for!(struct ::mir::interpret::EvalError<'tcx> { kind });
impl<'a, 'gcx, O: HashStable<StableHashingContext<'a>>> HashStable<StableHashingContext<'a>>
for ::mir::interpret::EvalErrorKind<'gcx, O> {
@ -726,28 +712,15 @@ impl_stable_hash_for!(enum ty::adjustment::CustomCoerceUnsized {
Struct(index)
});
impl<'a> HashStable<StableHashingContext<'a>> for ty::Generics {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::Generics {
parent,
ref parent_count,
ref params,
// Reverse map to each param's `index` field, from its `def_id`.
param_def_id_to_index: _, // Don't hash this
has_self,
has_late_bound_regions,
} = *self;
parent.hash_stable(hcx, hasher);
parent_count.hash_stable(hcx, hasher);
params.hash_stable(hcx, hasher);
has_self.hash_stable(hcx, hasher);
has_late_bound_regions.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct ty::Generics {
parent,
parent_count,
params,
// Reverse map to each param's `index` field, from its `def_id`.
param_def_id_to_index -> _, // Don't hash this
has_self,
has_late_bound_regions,
});
impl_stable_hash_for!(struct ty::GenericParamDef {
name,
@ -1079,57 +1052,30 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::InstanceDef<'gcx> {
}
}
impl<'a> HashStable<StableHashingContext<'a>> for ty::TraitDef {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::TraitDef {
// We already have the def_path_hash below, no need to hash it twice
def_id: _,
unsafety,
paren_sugar,
has_auto_impl,
def_path_hash,
} = *self;
unsafety.hash_stable(hcx, hasher);
paren_sugar.hash_stable(hcx, hasher);
has_auto_impl.hash_stable(hcx, hasher);
def_path_hash.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct ty::TraitDef {
// We already have the def_path_hash below, no need to hash it twice
def_id -> _,
unsafety,
paren_sugar,
has_auto_impl,
def_path_hash,
});
impl_stable_hash_for!(struct ty::Destructor {
did
});
impl<'a> HashStable<StableHashingContext<'a>> for ty::CrateVariancesMap {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::CrateVariancesMap {
ref variances,
// This is just an irrelevant helper value.
empty_variance: _,
} = *self;
impl_stable_hash_for!(struct ty::CrateVariancesMap {
variances,
// This is just an irrelevant helper value.
empty_variance -> _,
});
variances.hash_stable(hcx, hasher);
}
}
impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for ty::CratePredicatesMap<'gcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
let ty::CratePredicatesMap {
ref predicates,
// This is just an irrelevant helper value.
empty_predicate: _,
} = *self;
predicates.hash_stable(hcx, hasher);
}
}
impl_stable_hash_for!(struct ty::CratePredicatesMap<'tcx> {
predicates,
// This is just an irrelevant helper value.
empty_predicate -> _,
});
impl_stable_hash_for!(struct ty::AssociatedItem {
def_id,

View file

@ -64,15 +64,14 @@ macro_rules! span_bug {
#[macro_export]
macro_rules! __impl_stable_hash_field {
(DECL IGNORED) => (_);
(DECL $name:ident) => (ref $name);
(USE IGNORED $ctx:expr, $hasher:expr) => ({});
(USE $name:ident, $ctx:expr, $hasher:expr) => ($name.hash_stable($ctx, $hasher));
($field:ident, $ctx:expr, $hasher:expr) => ($field.hash_stable($ctx, $hasher));
($field:ident, $ctx:expr, $hasher:expr, _) => ({ let _ = $field; });
($field:ident, $ctx:expr, $hasher:expr, $delegate:expr) => ($delegate.hash_stable($ctx, $hasher));
}
#[macro_export]
macro_rules! impl_stable_hash_for {
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* $(,)* }) => {
(enum $enum_name:path { $( $variant:ident $( ( $($field:ident $(-> $delegate:tt)?),* ) )* ),* $(,)? }) => {
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $enum_name {
#[inline]
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
@ -83,15 +82,15 @@ macro_rules! impl_stable_hash_for {
match *self {
$(
$variant $( ( $( __impl_stable_hash_field!(DECL $arg) ),* ) )* => {
$($( __impl_stable_hash_field!(USE $arg, __ctx, __hasher) );*)*
$variant $( ( $(ref $field),* ) )* => {
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*)*
}
)*
}
}
}
};
(struct $struct_name:path { $($field:ident),* }) => {
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
#[inline]
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
@ -101,11 +100,11 @@ macro_rules! impl_stable_hash_for {
$(ref $field),*
} = *self;
$( $field.hash_stable(__ctx, __hasher));*
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
}
}
};
(tuple_struct $struct_name:path { $($field:ident),* }) => {
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name {
#[inline]
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
@ -115,7 +114,7 @@ macro_rules! impl_stable_hash_for {
$(ref $field),*
) = *self;
$( $field.hash_stable(__ctx, __hasher));*
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
}
}
};

View file

@ -15,6 +15,7 @@
#![feature(box_patterns)]
#![feature(fs_read_write)]
#![feature(libc)]
#![feature(macro_at_most_once_rep)]
#![cfg_attr(stage0, feature(macro_lifetime_matcher))]
#![feature(proc_macro_internals)]
#![feature(quote)]