Fix incremental compilation hashing.

This commit is contained in:
Jeffrey Seyfried 2016-11-20 00:32:54 +00:00
parent cc74068642
commit c9935e4a37

View File

@ -18,7 +18,7 @@ use syntax::abi::Abi;
use syntax::ast::{self, Name, NodeId};
use syntax::attr;
use syntax::parse::token;
use syntax::symbol::InternedString;
use syntax::symbol::{Symbol, InternedString};
use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
use syntax::tokenstream;
use rustc::hir;
@ -247,6 +247,8 @@ enum SawExprComponent<'a> {
SawExprBinary(hir::BinOp_),
SawExprUnary(hir::UnOp),
SawExprLit(ast::LitKind),
SawExprLitStr(InternedString, ast::StrStyle),
SawExprLitFloat(InternedString, Option<ast::FloatTy>),
SawExprCast,
SawExprType,
SawExprIf,
@ -315,7 +317,7 @@ fn saw_expr<'a>(node: &'a Expr_,
ExprUnary(op, _) => {
(SawExprUnary(op), unop_can_panic_at_runtime(op))
}
ExprLit(ref lit) => (SawExprLit(lit.node.clone()), false),
ExprLit(ref lit) => (saw_lit(lit), false),
ExprCast(..) => (SawExprCast, false),
ExprType(..) => (SawExprType, false),
ExprIf(..) => (SawExprIf, false),
@ -342,6 +344,15 @@ fn saw_expr<'a>(node: &'a Expr_,
}
}
fn saw_lit(lit: &ast::Lit) -> SawExprComponent<'static> {
match lit.node {
ast::LitKind::Str(s, style) => SawExprLitStr(s.as_str(), style),
ast::LitKind::Float(s, ty) => SawExprLitFloat(s.as_str(), Some(ty)),
ast::LitKind::FloatUnsuffixed(s) => SawExprLitFloat(s.as_str(), None),
ref node @ _ => SawExprLit(node.clone()),
}
}
#[derive(Hash)]
enum SawItemComponent {
SawItemExternCrate,
@ -875,23 +886,16 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
// ignoring span information, it doesn't matter here
self.hash_discriminant(&meta_item.node);
let name = &*meta_item.name.as_str();
meta_item.name.as_str().len().hash(self.st);
meta_item.name.as_str().hash(self.st);
match meta_item.node {
ast::MetaItemKind::Word => {
name.len().hash(self.st);
name.hash(self.st);
}
ast::MetaItemKind::NameValue(ref lit) => {
name.len().hash(self.st);
name.hash(self.st);
lit.node.hash(self.st);
}
ast::MetaItemKind::Word => {}
ast::MetaItemKind::NameValue(ref lit) => saw_lit(lit).hash(self.st),
ast::MetaItemKind::List(ref items) => {
name.len().hash(self.st);
name.hash(self.st);
// Sort subitems so the hash does not depend on their order
let indices = self.indices_sorted_by(&items, |p| {
(p.name(), fnv::hash(&p.literal().map(|i| &i.node)))
(p.name().map(Symbol::as_str), fnv::hash(&p.literal().map(saw_lit)))
});
items.len().hash(self.st);
for (index, &item_index) in indices.iter().enumerate() {
@ -903,7 +907,7 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
self.hash_meta_item(meta_item);
}
ast::NestedMetaItemKind::Literal(ref lit) => {
lit.node.hash(self.st);
saw_lit(lit).hash(self.st);
}
}
}