1
Fork 0

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::ast::{self, Name, NodeId};
use syntax::attr; use syntax::attr;
use syntax::parse::token; 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_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
use syntax::tokenstream; use syntax::tokenstream;
use rustc::hir; use rustc::hir;
@ -247,6 +247,8 @@ enum SawExprComponent<'a> {
SawExprBinary(hir::BinOp_), SawExprBinary(hir::BinOp_),
SawExprUnary(hir::UnOp), SawExprUnary(hir::UnOp),
SawExprLit(ast::LitKind), SawExprLit(ast::LitKind),
SawExprLitStr(InternedString, ast::StrStyle),
SawExprLitFloat(InternedString, Option<ast::FloatTy>),
SawExprCast, SawExprCast,
SawExprType, SawExprType,
SawExprIf, SawExprIf,
@ -315,7 +317,7 @@ fn saw_expr<'a>(node: &'a Expr_,
ExprUnary(op, _) => { ExprUnary(op, _) => {
(SawExprUnary(op), unop_can_panic_at_runtime(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), ExprCast(..) => (SawExprCast, false),
ExprType(..) => (SawExprType, false), ExprType(..) => (SawExprType, false),
ExprIf(..) => (SawExprIf, 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)] #[derive(Hash)]
enum SawItemComponent { enum SawItemComponent {
SawItemExternCrate, SawItemExternCrate,
@ -875,23 +886,16 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
// ignoring span information, it doesn't matter here // ignoring span information, it doesn't matter here
self.hash_discriminant(&meta_item.node); 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 { match meta_item.node {
ast::MetaItemKind::Word => { ast::MetaItemKind::Word => {}
name.len().hash(self.st); ast::MetaItemKind::NameValue(ref lit) => saw_lit(lit).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::List(ref items) => { 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 // Sort subitems so the hash does not depend on their order
let indices = self.indices_sorted_by(&items, |p| { 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); items.len().hash(self.st);
for (index, &item_index) in indices.iter().enumerate() { 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); self.hash_meta_item(meta_item);
} }
ast::NestedMetaItemKind::Literal(ref lit) => { ast::NestedMetaItemKind::Literal(ref lit) => {
lit.node.hash(self.st); saw_lit(lit).hash(self.st);
} }
} }
} }