stop hashing nested items, and add a test

This commit is contained in:
Niko Matsakis 2016-07-27 14:42:58 -04:00
parent 775bd93d72
commit 5001c92c3e
2 changed files with 52 additions and 20 deletions

View File

@ -182,7 +182,6 @@ mod svh_visitor {
SawMod, SawMod,
SawForeignItem, SawForeignItem,
SawItem, SawItem,
SawDecl,
SawTy, SawTy,
SawGenerics, SawGenerics,
SawFn, SawFn,
@ -285,24 +284,13 @@ mod svh_visitor {
/// SawStmtComponent is analogous to SawExprComponent, but for statements. /// SawStmtComponent is analogous to SawExprComponent, but for statements.
#[derive(Hash)] #[derive(Hash)]
pub enum SawStmtComponent { pub enum SawStmtComponent {
SawStmtDecl,
SawStmtExpr, SawStmtExpr,
SawStmtSemi, SawStmtSemi,
} }
fn saw_stmt(node: &Stmt_) -> SawStmtComponent {
match *node {
StmtDecl(..) => SawStmtDecl,
StmtExpr(..) => SawStmtExpr,
StmtSemi(..) => SawStmtSemi,
}
}
impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> { impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> {
fn visit_nested_item(&mut self, item: ItemId) { fn visit_nested_item(&mut self, _: ItemId) {
let def_path = self.tcx.map.def_path_from_id(item.id).unwrap(); // Each item is hashed independently; ignore nested items.
debug!("visit_nested_item: def_path={:?} st={:?}", def_path, self.st);
self.hash_def_path(&def_path);
} }
fn visit_variant_data(&mut self, s: &'a VariantData, name: Name, fn visit_variant_data(&mut self, s: &'a VariantData, name: Name,
@ -362,7 +350,20 @@ mod svh_visitor {
fn visit_stmt(&mut self, s: &'a Stmt) { fn visit_stmt(&mut self, s: &'a Stmt) {
debug!("visit_stmt: st={:?}", self.st); debug!("visit_stmt: st={:?}", self.st);
SawStmt(saw_stmt(&s.node)).hash(self.st); visit::walk_stmt(self, s)
// We don't want to modify the hash for decls, because
// they might be item decls (if they are local decls,
// we'll hash that fact in visit_local); but we do want to
// remember if this was a StmtExpr or StmtSemi (the later
// had an explicit semi-colon; this affects the typing
// rules).
match s.node {
StmtDecl(..) => (),
StmtExpr(..) => SawStmt(SawStmtExpr).hash(self.st),
StmtSemi(..) => SawStmt(SawStmtSemi).hash(self.st),
}
visit::walk_stmt(self, s)
} }
fn visit_foreign_item(&mut self, i: &'a ForeignItem) { fn visit_foreign_item(&mut self, i: &'a ForeignItem) {
@ -390,11 +391,6 @@ mod svh_visitor {
SawMod.hash(self.st); visit::walk_mod(self, m, n) SawMod.hash(self.st); visit::walk_mod(self, m, n)
} }
fn visit_decl(&mut self, d: &'a Decl) {
debug!("visit_decl: st={:?}", self.st);
SawDecl.hash(self.st); visit::walk_decl(self, d)
}
fn visit_ty(&mut self, t: &'a Ty) { fn visit_ty(&mut self, t: &'a Ty) {
debug!("visit_ty: st={:?}", self.st); debug!("visit_ty: st={:?}", self.st);
SawTy.hash(self.st); visit::walk_ty(self, t) SawTy.hash(self.st); visit::walk_ty(self, t)

View File

@ -0,0 +1,36 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Check that the hash of `foo` doesn't change just because we ordered
// the nested items (or even added new ones).
// revisions: rpass1 rpass2
#![feature(rustc_attrs)]
#[cfg(rpass1)]
fn foo() {
fn bar() { }
fn baz() { }
}
#[cfg(rpass2)]
#[rustc_clean(label="Hir", cfg="rpass2")]
fn foo() {
#[rustc_clean(label="Hir", cfg="rpass2")]
fn baz() { } // order is different...
#[rustc_clean(label="Hir", cfg="rpass2")]
fn bar() { } // but that doesn't matter.
fn bap() { } // neither does adding a new item
}
fn main() { }