Skip to content

Commit 5001c92

Browse files
committed
stop hashing nested items, and add a test
1 parent 775bd93 commit 5001c92

File tree

2 files changed

+52
-20
lines changed

2 files changed

+52
-20
lines changed

src/librustc_incremental/calculate_svh.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ mod svh_visitor {
182182
SawMod,
183183
SawForeignItem,
184184
SawItem,
185-
SawDecl,
186185
SawTy,
187186
SawGenerics,
188187
SawFn,
@@ -285,24 +284,13 @@ mod svh_visitor {
285284
/// SawStmtComponent is analogous to SawExprComponent, but for statements.
286285
#[derive(Hash)]
287286
pub enum SawStmtComponent {
288-
SawStmtDecl,
289287
SawStmtExpr,
290288
SawStmtSemi,
291289
}
292290

293-
fn saw_stmt(node: &Stmt_) -> SawStmtComponent {
294-
match *node {
295-
StmtDecl(..) => SawStmtDecl,
296-
StmtExpr(..) => SawStmtExpr,
297-
StmtSemi(..) => SawStmtSemi,
298-
}
299-
}
300-
301291
impl<'a, 'tcx> Visitor<'a> for StrictVersionHashVisitor<'a, 'tcx> {
302-
fn visit_nested_item(&mut self, item: ItemId) {
303-
let def_path = self.tcx.map.def_path_from_id(item.id).unwrap();
304-
debug!("visit_nested_item: def_path={:?} st={:?}", def_path, self.st);
305-
self.hash_def_path(&def_path);
292+
fn visit_nested_item(&mut self, _: ItemId) {
293+
// Each item is hashed independently; ignore nested items.
306294
}
307295

308296
fn visit_variant_data(&mut self, s: &'a VariantData, name: Name,
@@ -362,7 +350,20 @@ mod svh_visitor {
362350

363351
fn visit_stmt(&mut self, s: &'a Stmt) {
364352
debug!("visit_stmt: st={:?}", self.st);
365-
SawStmt(saw_stmt(&s.node)).hash(self.st); visit::walk_stmt(self, s)
353+
354+
// We don't want to modify the hash for decls, because
355+
// they might be item decls (if they are local decls,
356+
// we'll hash that fact in visit_local); but we do want to
357+
// remember if this was a StmtExpr or StmtSemi (the later
358+
// had an explicit semi-colon; this affects the typing
359+
// rules).
360+
match s.node {
361+
StmtDecl(..) => (),
362+
StmtExpr(..) => SawStmt(SawStmtExpr).hash(self.st),
363+
StmtSemi(..) => SawStmt(SawStmtSemi).hash(self.st),
364+
}
365+
366+
visit::walk_stmt(self, s)
366367
}
367368

368369
fn visit_foreign_item(&mut self, i: &'a ForeignItem) {
@@ -390,11 +391,6 @@ mod svh_visitor {
390391
SawMod.hash(self.st); visit::walk_mod(self, m, n)
391392
}
392393

393-
fn visit_decl(&mut self, d: &'a Decl) {
394-
debug!("visit_decl: st={:?}", self.st);
395-
SawDecl.hash(self.st); visit::walk_decl(self, d)
396-
}
397-
398394
fn visit_ty(&mut self, t: &'a Ty) {
399395
debug!("visit_ty: st={:?}", self.st);
400396
SawTy.hash(self.st); visit::walk_ty(self, t)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Check that the hash of `foo` doesn't change just because we ordered
12+
// the nested items (or even added new ones).
13+
14+
// revisions: rpass1 rpass2
15+
16+
#![feature(rustc_attrs)]
17+
18+
#[cfg(rpass1)]
19+
fn foo() {
20+
fn bar() { }
21+
fn baz() { }
22+
}
23+
24+
#[cfg(rpass2)]
25+
#[rustc_clean(label="Hir", cfg="rpass2")]
26+
fn foo() {
27+
#[rustc_clean(label="Hir", cfg="rpass2")]
28+
fn baz() { } // order is different...
29+
30+
#[rustc_clean(label="Hir", cfg="rpass2")]
31+
fn bar() { } // but that doesn't matter.
32+
33+
fn bap() { } // neither does adding a new item
34+
}
35+
36+
fn main() { }

0 commit comments

Comments
 (0)