Skip to content

Commit

Permalink
Fix incremental compilation hashing.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Nov 21, 2016
1 parent cc74068 commit c9935e4
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/librustc_incremental/calculate_svh/svh_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit c9935e4

Please sign in to comment.