Skip to content

Commit

Permalink
Support delegation in stable hashing macros
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jun 28, 2018
1 parent f0622df commit d5e9dff
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 280 deletions.
253 changes: 71 additions & 182 deletions src/librustc/ich/impls_hir.rs
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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>) {
Expand Down Expand Up @@ -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;

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;
impl_stable_hash_for!(struct hir::GlobalAsm {
asm,
ctxt -> _, // This is used for error reporting
});

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,
Expand Down Expand Up @@ -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>,
Expand All @@ -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>) {
Expand All @@ -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>) {
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit d5e9dff

Please sign in to comment.