Skip to content

Commit

Permalink
ICH: Make InlineAsm hashes stable.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwoerister committed Dec 22, 2016
1 parent 94ae2a2 commit 2432f69
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Expand Up @@ -28,7 +28,7 @@ use rustc::hir::def_id::DefId;
use rustc::hir::intravisit as visit;
use rustc::ty::TyCtxt;
use rustc_data_structures::fnv;
use std::hash::Hash;
use std::hash::{Hash, Hasher};

use super::def_path_hash::DefPathHashes;
use super::caching_codemap_view::CachingCodemapView;
Expand Down Expand Up @@ -265,7 +265,7 @@ enum SawExprComponent<'a> {
SawExprPath,
SawExprAddrOf(hir::Mutability),
SawExprRet,
SawExprInlineAsm(&'a hir::InlineAsm),
SawExprInlineAsm(StableInlineAsm<'a>),
SawExprStruct,
SawExprRepeat,
}
Expand Down Expand Up @@ -341,7 +341,7 @@ fn saw_expr<'a>(node: &'a Expr_,
ExprBreak(label, _) => (SawExprBreak(label.map(|l| l.name.as_str())), false),
ExprAgain(label) => (SawExprAgain(label.map(|l| l.name.as_str())), false),
ExprRet(..) => (SawExprRet, false),
ExprInlineAsm(ref a,..) => (SawExprInlineAsm(a), false),
ExprInlineAsm(ref a,..) => (SawExprInlineAsm(StableInlineAsm(a)), false),
ExprStruct(..) => (SawExprStruct, false),
ExprRepeat(..) => (SawExprRepeat, false),
}
Expand Down Expand Up @@ -492,6 +492,46 @@ enum SawSpanExpnKind {
SomeExpansion,
}

/// A wrapper that provides a stable Hash implementation.
struct StableInlineAsm<'a>(&'a InlineAsm);

impl<'a> Hash for StableInlineAsm<'a> {
fn hash<H: Hasher>(&self, state: &mut H) {
let InlineAsm {
asm,
asm_str_style,
ref outputs,
ref inputs,
ref clobbers,
volatile,
alignstack,
dialect,
expn_id: _, // This is used for error reporting
} = *self.0;

asm.as_str().hash(state);
asm_str_style.hash(state);
outputs.len().hash(state);
for output in outputs {
let InlineAsmOutput { constraint, is_rw, is_indirect } = *output;
constraint.as_str().hash(state);
is_rw.hash(state);
is_indirect.hash(state);
}
inputs.len().hash(state);
for input in inputs {
input.as_str().hash(state);
}
clobbers.len().hash(state);
for clobber in clobbers {
clobber.as_str().hash(state);
}
volatile.hash(state);
alignstack.hash(state);
dialect.hash(state);
}
}

macro_rules! hash_attrs {
($visitor:expr, $attrs:expr) => ({
let attrs = $attrs;
Expand Down

0 comments on commit 2432f69

Please sign in to comment.