use std::fmt;
use std::hash::{Hash, SipHasher, Hasher};
-use syntax::ast;
-use syntax::visit;
+use rustc_front::hir;
+use rustc_front::visit;
#[derive(Clone, PartialEq, Debug)]
pub struct Svh {
&self.hash
}
- pub fn calculate(metadata: &Vec<String>, krate: &ast::Crate) -> Svh {
+ pub fn calculate(metadata: &Vec<String>, krate: &hir::Crate) -> Svh {
// FIXME (#14132): This is better than it used to be, but it still not
// ideal. We now attempt to hash only the relevant portions of the
// Crate AST as well as the top-level crate attributes. (However,
pub use self::SawExprComponent::*;
pub use self::SawStmtComponent::*;
use self::SawAbiComponent::*;
- use syntax::ast;
- use syntax::ast::*;
+ use syntax::ast::{self, Name, NodeId};
use syntax::codemap::Span;
use syntax::parse::token;
- use syntax::print::pprust;
- use syntax::visit;
- use syntax::visit::{Visitor, FnKind};
+ use rustc_front::visit;
+ use rustc_front::visit::{Visitor, FnKind};
+ use rustc_front::hir::*;
+ use rustc_front::hir;
use std::hash::{Hash, SipHasher};
SawIdent(token::InternedString),
SawStructDef(token::InternedString),
- SawLifetimeRef(token::InternedString),
+ SawLifetime(token::InternedString),
SawLifetimeDef(token::InternedString),
SawMod,
SawVariant,
SawExplicitSelf,
SawPath,
- SawOptLifetimeRef,
SawBlock,
SawPat,
SawLocal,
SawExprCall,
SawExprMethodCall,
SawExprTup,
- SawExprBinary(ast::BinOp_),
- SawExprUnary(ast::UnOp),
+ SawExprBinary(hir::BinOp_),
+ SawExprUnary(hir::UnOp),
SawExprLit(ast::Lit_),
SawExprCast,
SawExprIf,
SawExprClosure,
SawExprBlock,
SawExprAssign,
- SawExprAssignOp(ast::BinOp_),
+ SawExprAssignOp(hir::BinOp_),
SawExprIndex,
SawExprRange,
SawExprPath(Option<usize>),
- SawExprAddrOf(ast::Mutability),
+ SawExprAddrOf(hir::Mutability),
SawExprRet,
- SawExprInlineAsm(&'a ast::InlineAsm),
+ SawExprInlineAsm(&'a hir::InlineAsm),
SawExprStruct,
SawExprRepeat,
- SawExprParen,
}
fn saw_expr<'a>(node: &'a Expr_) -> SawExprComponent<'a> {
ExprBlock(..) => SawExprBlock,
ExprAssign(..) => SawExprAssign,
ExprAssignOp(op, _, _) => SawExprAssignOp(op.node),
- ExprField(_, id) => SawExprField(id.node.name.as_str()),
+ ExprField(_, name) => SawExprField(name.node.as_str()),
ExprTupField(_, id) => SawExprTupField(id.node),
ExprIndex(..) => SawExprIndex,
ExprRange(..) => SawExprRange,
ExprPath(ref qself, _) => SawExprPath(qself.as_ref().map(|q| q.position)),
ExprAddrOf(m, _) => SawExprAddrOf(m),
- ExprBreak(id) => SawExprBreak(id.map(|id| id.name.as_str())),
- ExprAgain(id) => SawExprAgain(id.map(|id| id.name.as_str())),
+ ExprBreak(id) => SawExprBreak(id.map(|id| id.node.name.as_str())),
+ ExprAgain(id) => SawExprAgain(id.map(|id| id.node.name.as_str())),
ExprRet(..) => SawExprRet,
ExprInlineAsm(ref asm) => SawExprInlineAsm(asm),
ExprStruct(..) => SawExprStruct,
ExprRepeat(..) => SawExprRepeat,
- ExprParen(..) => SawExprParen,
-
- // just syntactic artifacts, expanded away by time of SVH.
- ExprForLoop(..) => unreachable!(),
- ExprIfLet(..) => unreachable!(),
- ExprWhileLet(..) => unreachable!(),
- ExprMac(..) => unreachable!(),
}
}
StmtDecl(..) => SawStmtDecl,
StmtExpr(..) => SawStmtExpr,
StmtSemi(..) => SawStmtSemi,
- StmtMac(..) => unreachable!(),
}
}
impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> {
-
- fn visit_mac(&mut self, mac: &Mac) {
- // macro invocations, namely macro_rules definitions,
- // *can* appear as items, even in the expanded crate AST.
-
- if ¯o_name(mac)[..] == "macro_rules" {
- // Pretty-printing definition to a string strips out
- // surface artifacts (currently), such as the span
- // information, yielding a content-based hash.
-
- // FIXME (#14132): building temporary string is
- // expensive; a direct content-based hash on token
- // trees might be faster. Implementing this is far
- // easier in short term.
- let macro_defn_as_string = pprust::to_string(|pp_state| {
- pp_state.print_mac(mac, token::Paren)
- });
- macro_defn_as_string.hash(self.st);
- } else {
- // It is not possible to observe any kind of macro
- // invocation at this stage except `macro_rules!`.
- panic!("reached macro somehow: {}",
- pprust::to_string(|pp_state| {
- pp_state.print_mac(mac, token::Paren)
- }));
- }
-
- visit::walk_mac(self, mac);
-
- fn macro_name(mac: &Mac) -> token::InternedString {
- match &mac.node {
- &MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => {
- let s = &path.segments;
- assert_eq!(s.len(), 1);
- s[0].identifier.name.as_str()
- }
- }
- }
- }
-
- fn visit_struct_def(&mut self, s: &StructDef, ident: Ident,
+ fn visit_struct_def(&mut self, s: &StructDef, name: Name,
g: &Generics, _: NodeId) {
- SawStructDef(ident.name.as_str()).hash(self.st);
+ SawStructDef(name.as_str()).hash(self.st);
visit::walk_generics(self, g);
visit::walk_struct_def(self, s)
}
visit::walk_variant(self, v, g)
}
- fn visit_opt_lifetime_ref(&mut self, _: Span, l: &Option<Lifetime>) {
- SawOptLifetimeRef.hash(self.st);
- // (This is a strange method in the visitor trait, in that
- // it does not expose a walk function to do the subroutine
- // calls.)
- match *l {
- Some(ref l) => self.visit_lifetime_ref(l),
- None => ()
- }
- }
-
// All of the remaining methods just record (in the hash
// SipHasher) that the visitor saw that particular variant
// (with its payload), and continue walking as the default
// (If you edit a method such that it deviates from the
// pattern, please move that method up above this comment.)
- fn visit_ident(&mut self, _: Span, ident: Ident) {
- SawIdent(ident.name.as_str()).hash(self.st);
+ fn visit_name(&mut self, _: Span, name: Name) {
+ SawIdent(name.as_str()).hash(self.st);
}
- fn visit_lifetime_ref(&mut self, l: &Lifetime) {
- SawLifetimeRef(l.name.as_str()).hash(self.st);
+ fn visit_lifetime(&mut self, l: &Lifetime) {
+ SawLifetime(l.name.as_str()).hash(self.st);
}
fn visit_lifetime_def(&mut self, l: &LifetimeDef) {
SawPath.hash(self.st); visit::walk_path(self, path)
}
+ fn visit_path_list_item(&mut self, prefix: &Path, item: &'v PathListItem) {
+ SawPath.hash(self.st); visit::walk_path_list_item(self, prefix, item)
+ }
+
fn visit_block(&mut self, b: &Block) {
SawBlock.hash(self.st); visit::walk_block(self, b)
}