Skip to content

Commit 2432f69

Browse files
ICH: Make InlineAsm hashes stable.
1 parent 94ae2a2 commit 2432f69

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

src/librustc_incremental/calculate_svh/svh_visitor.rs

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc::hir::def_id::DefId;
2828
use rustc::hir::intravisit as visit;
2929
use rustc::ty::TyCtxt;
3030
use rustc_data_structures::fnv;
31-
use std::hash::Hash;
31+
use std::hash::{Hash, Hasher};
3232

3333
use super::def_path_hash::DefPathHashes;
3434
use super::caching_codemap_view::CachingCodemapView;
@@ -265,7 +265,7 @@ enum SawExprComponent<'a> {
265265
SawExprPath,
266266
SawExprAddrOf(hir::Mutability),
267267
SawExprRet,
268-
SawExprInlineAsm(&'a hir::InlineAsm),
268+
SawExprInlineAsm(StableInlineAsm<'a>),
269269
SawExprStruct,
270270
SawExprRepeat,
271271
}
@@ -341,7 +341,7 @@ fn saw_expr<'a>(node: &'a Expr_,
341341
ExprBreak(label, _) => (SawExprBreak(label.map(|l| l.name.as_str())), false),
342342
ExprAgain(label) => (SawExprAgain(label.map(|l| l.name.as_str())), false),
343343
ExprRet(..) => (SawExprRet, false),
344-
ExprInlineAsm(ref a,..) => (SawExprInlineAsm(a), false),
344+
ExprInlineAsm(ref a,..) => (SawExprInlineAsm(StableInlineAsm(a)), false),
345345
ExprStruct(..) => (SawExprStruct, false),
346346
ExprRepeat(..) => (SawExprRepeat, false),
347347
}
@@ -492,6 +492,46 @@ enum SawSpanExpnKind {
492492
SomeExpansion,
493493
}
494494

495+
/// A wrapper that provides a stable Hash implementation.
496+
struct StableInlineAsm<'a>(&'a InlineAsm);
497+
498+
impl<'a> Hash for StableInlineAsm<'a> {
499+
fn hash<H: Hasher>(&self, state: &mut H) {
500+
let InlineAsm {
501+
asm,
502+
asm_str_style,
503+
ref outputs,
504+
ref inputs,
505+
ref clobbers,
506+
volatile,
507+
alignstack,
508+
dialect,
509+
expn_id: _, // This is used for error reporting
510+
} = *self.0;
511+
512+
asm.as_str().hash(state);
513+
asm_str_style.hash(state);
514+
outputs.len().hash(state);
515+
for output in outputs {
516+
let InlineAsmOutput { constraint, is_rw, is_indirect } = *output;
517+
constraint.as_str().hash(state);
518+
is_rw.hash(state);
519+
is_indirect.hash(state);
520+
}
521+
inputs.len().hash(state);
522+
for input in inputs {
523+
input.as_str().hash(state);
524+
}
525+
clobbers.len().hash(state);
526+
for clobber in clobbers {
527+
clobber.as_str().hash(state);
528+
}
529+
volatile.hash(state);
530+
alignstack.hash(state);
531+
dialect.hash(state);
532+
}
533+
}
534+
495535
macro_rules! hash_attrs {
496536
($visitor:expr, $attrs:expr) => ({
497537
let attrs = $attrs;

0 commit comments

Comments
 (0)