From 5001c92c3e39906042691b2ab36afc28c0e348c0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 27 Jul 2016 14:42:58 -0400 Subject: [PATCH] stop hashing nested items, and add a test --- src/librustc_incremental/calculate_svh.rs | 36 ++++++++++------------- src/test/incremental/ich_nested_items.rs | 36 +++++++++++++++++++++++ 2 files changed, 52 insertions(+), 20 deletions(-) create mode 100644 src/test/incremental/ich_nested_items.rs diff --git a/src/librustc_incremental/calculate_svh.rs b/src/librustc_incremental/calculate_svh.rs index 4b2d42ca889..de53da2fd36 100644 --- a/src/librustc_incremental/calculate_svh.rs +++ b/src/librustc_incremental/calculate_svh.rs @@ -182,7 +182,6 @@ mod svh_visitor { SawMod, SawForeignItem, SawItem, - SawDecl, SawTy, SawGenerics, SawFn, @@ -285,24 +284,13 @@ mod svh_visitor { /// SawStmtComponent is analogous to SawExprComponent, but for statements. #[derive(Hash)] pub enum SawStmtComponent { - SawStmtDecl, SawStmtExpr, SawStmtSemi, } - fn saw_stmt(node: &Stmt_) -> SawStmtComponent { - match *node { - StmtDecl(..) => SawStmtDecl, - StmtExpr(..) => SawStmtExpr, - StmtSemi(..) => SawStmtSemi, - } - } - impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> { - fn visit_nested_item(&mut self, item: ItemId) { - let def_path = self.tcx.map.def_path_from_id(item.id).unwrap(); - debug!("visit_nested_item: def_path={:?} st={:?}", def_path, self.st); - self.hash_def_path(&def_path); + fn visit_nested_item(&mut self, _: ItemId) { + // Each item is hashed independently; ignore nested items. } 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) { 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) { @@ -390,11 +391,6 @@ mod svh_visitor { 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) { debug!("visit_ty: st={:?}", self.st); SawTy.hash(self.st); visit::walk_ty(self, t) diff --git a/src/test/incremental/ich_nested_items.rs b/src/test/incremental/ich_nested_items.rs new file mode 100644 index 00000000000..4466cfb1317 --- /dev/null +++ b/src/test/incremental/ich_nested_items.rs @@ -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 or the MIT license +// , 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() { }