Skip to content

Commit 7310a8f

Browse files
committedSep 1, 2016
ICH: Adapt to changes in the MetaItem AST representation.
1 parent 8cbd6fe commit 7310a8f

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed
 

‎src/librustc_data_structures/fnv.rs

+6
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,9 @@ impl Hasher for FnvHasher {
5757
self.0
5858
}
5959
}
60+
61+
pub fn hash<T: Hash>(v: &T) -> u64 {
62+
let mut state = FnvHasher::default();
63+
v.hash(&mut state);
64+
state.finish()
65+
}

‎src/librustc_incremental/calculate_svh/svh_visitor.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
use self::SawExprComponent::*;
1717
use self::SawAbiComponent::*;
18-
use syntax::ast::{self, Name, NodeId, Attribute};
18+
use syntax::ast::{self, Name, NodeId};
1919
use syntax::parse::token;
2020
use syntax_pos::{Span, NO_EXPANSION, COMMAND_LINE_EXPN, BytePos};
2121
use rustc::hir;
@@ -24,6 +24,7 @@ use rustc::hir::def::{Def, PathResolution};
2424
use rustc::hir::def_id::DefId;
2525
use rustc::hir::intravisit as visit;
2626
use rustc::ty::TyCtxt;
27+
use rustc_data_structures::fnv;
2728
use std::hash::{Hash, SipHasher};
2829

2930
use super::def_path_hash::DefPathHashes;
@@ -526,7 +527,7 @@ impl<'a, 'hash, 'tcx> visit::Visitor<'tcx> for StrictVersionHashVisitor<'a, 'has
526527
visit::walk_assoc_type_binding(self, type_binding)
527528
}
528529

529-
fn visit_attribute(&mut self, _: &Attribute) {
530+
fn visit_attribute(&mut self, _: &ast::Attribute) {
530531
// We explicitly do not use this method, since doing that would
531532
// implicitly impose an order on the attributes being hashed, while we
532533
// explicitly don't want their order to matter
@@ -658,28 +659,34 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
658659
s.hash(self.st);
659660
// Sort subitems so the hash does not depend on their order
660661
let indices = self.indices_sorted_by(&items, |p| {
661-
meta_item_sort_key(&*p)
662+
(p.name(), fnv::hash(&p.literal().map(|i| &i.node)))
662663
});
663664
items.len().hash(self.st);
664665
for (index, &item_index) in indices.iter().enumerate() {
665666
index.hash(self.st);
666-
self.hash_meta_item(&items[item_index]);
667+
let nested_meta_item: &ast::NestedMetaItemKind = &items[item_index].node;
668+
self.hash_discriminant(nested_meta_item);
669+
match *nested_meta_item {
670+
ast::NestedMetaItemKind::MetaItem(ref meta_item) => {
671+
self.hash_meta_item(meta_item);
672+
}
673+
ast::NestedMetaItemKind::Literal(ref lit) => {
674+
lit.node.hash(self.st);
675+
}
676+
}
667677
}
668678
}
669679
}
670680
}
671681

672-
pub fn hash_attributes(&mut self, attributes: &[Attribute]) {
682+
pub fn hash_attributes(&mut self, attributes: &[ast::Attribute]) {
673683
debug!("hash_attributes: st={:?}", self.st);
674-
let indices = self.indices_sorted_by(attributes, |attr| {
675-
meta_item_sort_key(&attr.node.value)
676-
});
684+
let indices = self.indices_sorted_by(attributes, |attr| attr.name());
677685

678686
for i in indices {
679687
let attr = &attributes[i].node;
680-
681688
if !attr.is_sugared_doc &&
682-
!IGNORED_ATTRIBUTES.contains(&&*meta_item_sort_key(&attr.value)) {
689+
!IGNORED_ATTRIBUTES.contains(&&*attr.value.name()) {
683690
SawAttribute(attr.style).hash(self.st);
684691
self.hash_meta_item(&*attr.value);
685692
}
@@ -696,11 +703,3 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
696703
indices
697704
}
698705
}
699-
700-
fn meta_item_sort_key(item: &ast::MetaItem) -> token::InternedString {
701-
match item.node {
702-
ast::MetaItemKind::Word(ref s) |
703-
ast::MetaItemKind::NameValue(ref s, _) |
704-
ast::MetaItemKind::List(ref s, _) => s.clone()
705-
}
706-
}

0 commit comments

Comments
 (0)
Please sign in to comment.