]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_back/svh.rs
Fill in some missing parts in the default HIR visitor
[rust.git] / src / librustc_back / svh.rs
index db0a291efbd07dda19fd817335cd2541991990ab..25b4cfad01ce0e3a43cd2f80c97f7e99b2e39af3 100644 (file)
@@ -48,8 +48,8 @@
 
 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 {
@@ -66,7 +66,7 @@ pub fn as_str<'a>(&'a self) -> &'a str {
         &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,
@@ -131,13 +131,13 @@ mod svh_visitor {
     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};
 
@@ -177,7 +177,7 @@ enum SawAbiComponent<'a> {
         SawIdent(token::InternedString),
         SawStructDef(token::InternedString),
 
-        SawLifetimeRef(token::InternedString),
+        SawLifetime(token::InternedString),
         SawLifetimeDef(token::InternedString),
 
         SawMod,
@@ -193,7 +193,6 @@ enum SawAbiComponent<'a> {
         SawVariant,
         SawExplicitSelf,
         SawPath,
-        SawOptLifetimeRef,
         SawBlock,
         SawPat,
         SawLocal,
@@ -230,8 +229,8 @@ pub enum SawExprComponent<'a> {
         SawExprCall,
         SawExprMethodCall,
         SawExprTup,
-        SawExprBinary(ast::BinOp_),
-        SawExprUnary(ast::UnOp),
+        SawExprBinary(hir::BinOp_),
+        SawExprUnary(hir::UnOp),
         SawExprLit(ast::Lit_),
         SawExprCast,
         SawExprIf,
@@ -240,16 +239,15 @@ pub enum SawExprComponent<'a> {
         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> {
@@ -271,25 +269,18 @@ 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!(),
         }
     }
 
@@ -306,54 +297,13 @@ fn saw_stmt(node: &Stmt_) -> SawStmtComponent {
             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 &macro_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)
         }
@@ -365,17 +315,6 @@ fn visit_variant(&mut self, v: &Variant, g: &Generics) {
             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
@@ -390,12 +329,12 @@ fn visit_opt_lifetime_ref(&mut self, _: Span, l: &Option<Lifetime>) {
         // (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) {
@@ -472,6 +411,10 @@ fn visit_path(&mut self, path: &Path, _: ast::NodeId) {
             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)
         }