Skip to content

Smaller refactor svh #27461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 24 additions & 13 deletions src/librustc_back/svh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,6 @@ impl Svh {
visit::walk_crate(&mut visit, krate);
}

// FIXME (#14132): This hash is still sensitive to e.g. the
// spans of the crate Attributes and their underlying
// MetaItems; we should make ContentHashable impl for those
// types and then use hash_content. But, since all crate
// attributes should appear near beginning of the file, it is
// not such a big deal to be sensitive to their spans for now.
//
// We hash only the MetaItems instead of the entire Attribute
// to avoid hashing the AttrId
for attr in &krate.attrs {
attr.node.value.hash(&mut state);
}

let hash = state.finish();
return Svh {
hash: (0..64).step_by(4).map(|i| hex(hash >> i)).collect()
Expand Down Expand Up @@ -198,6 +185,9 @@ mod svh_visitor {
SawPat,
SawLocal,
SawArm,
SawAttrWord,
SawAttrList,
SawAttrNameValue,
SawExpr(SawExprComponent<'a>),
SawStmt(SawStmtComponent),
}
Expand Down Expand Up @@ -487,5 +477,26 @@ mod svh_visitor {
fn visit_arm(&mut self, a: &Arm) {
SawArm.hash(self.st); visit::walk_arm(self, a)
}

fn visit_attribute(&mut self, a: &Attribute) {
let ref val = a.node.value;

match val.node {
MetaItem_::MetaWord(ref s) => {
SawAttrWord.hash(self.st);
s.hash(self.st);
},
MetaItem_::MetaList(ref s, ref items) => {
SawAttrList.hash(self.st);
s.hash(self.st);
items.hash(self.st);
},
MetaItem_::MetaNameValue(ref s, ref lit) => {
SawAttrNameValue.hash(self.st);
s.hash(self.st);
lit.hash(self.st);
},
}
}
}
}