Skip to content

Commit fedffa7

Browse files
committed
auto merge of #14145 : pnkfelix/rust/fsk-better-svh-via-visitor, r=alexcrichton
Teach SVH computation to ignore more implementation artifacts. In particular, this version of strict version hash (SVH) works much like the deriving(Hash)-based implementation did, except that it deliberately: 1. skips over content known not affect the generated crates, and, 2. uses a content-based hash for names instead of using the value of the `Name` index itself, which can differ depending on the order in which strings are interned (which in turn is affected by e.g. the presence of `--cfg` options on the command line). Fix #14132.
2 parents 579e0a5 + 5236af8 commit fedffa7

32 files changed

+1331
-19
lines changed

src/librustc/back/svh.rs

+407-16
Large diffs are not rendered by default.

src/libsyntax/visit.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,17 @@ pub fn generics_of_fn(fk: &FnKind) -> Generics {
6161
}
6262
}
6363

64+
/// Each method of the Visitor trait is a hook to be potentially
65+
/// overriden. Each method's default implementation recursively visits
66+
/// the substructure of the input via the corresponding `walk` method;
67+
/// e.g. the `visit_mod` method by default calls `visit::walk_mod`.
68+
///
69+
/// If you want to ensure that your code handles every variant
70+
/// explicitly, you need to override each method. (And you also need
71+
/// to monitor future changes to `Visitor` in case a new method with a
72+
/// new default implementation gets introduced.)
6473
pub trait Visitor<E: Clone> {
74+
6575
fn visit_ident(&mut self, _sp: Span, _ident: Ident, _e: E) {
6676
/*! Visit the idents */
6777
}
@@ -179,9 +189,9 @@ pub fn walk_local<E: Clone, V: Visitor<E>>(visitor: &mut V, local: &Local, env:
179189
}
180190
}
181191

182-
fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
183-
explicit_self: &ExplicitSelf,
184-
env: E) {
192+
pub fn walk_explicit_self<E: Clone, V: Visitor<E>>(visitor: &mut V,
193+
explicit_self: &ExplicitSelf,
194+
env: E) {
185195
match explicit_self.node {
186196
SelfStatic | SelfValue | SelfUniq => {}
187197
SelfRegion(ref lifetime, _) => {

src/test/auxiliary/svh-a-base.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:U>(_: int) -> int {
32+
3
33+
}
34+
35+
pub fn an_unused_name() -> int {
36+
4
37+
}
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:U>(_: int) -> int {
32+
0
33+
}
34+
35+
pub fn an_unused_name() -> int {
36+
4
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
#[cfg(some_flag)]
32+
pub fn foo<T:U>(_: int) -> int {
33+
3
34+
}
35+
36+
#[cfg(not(some_flag))]
37+
pub fn an_unused_name() -> int {
38+
4
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:V>(_: int) -> int {
32+
3
33+
}
34+
35+
pub fn an_unused_name() -> int {
36+
4
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:U>(_: i32) -> int {
32+
3
33+
}
34+
35+
pub fn an_unused_name() -> int {
36+
4
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:U>(_: int) -> i64 {
32+
3
33+
}
34+
35+
pub fn an_unused_name() -> i32 {
36+
4
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : i32 = 2;
30+
31+
pub fn foo<T:U>(_: int) -> int {
32+
3
33+
}
34+
35+
pub fn an_unused_name() -> int {
36+
4
37+
}

src/test/auxiliary/svh-a-comment.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
pub fn foo<T:U>(_: int) -> int {
32+
// a comment does not affect the svh
33+
3
34+
}
35+
36+
pub fn an_unused_name() -> int {
37+
4
38+
}

src/test/auxiliary/svh-a-doc.rs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
//! The `svh-a-*.rs` files are all deviations from the base file
12+
//! svh-a-base.rs with some difference (usually in `fn foo`) that
13+
//! should not affect the strict version hash (SVH) computation
14+
//! (#14132).
15+
16+
#![feature(macro_rules)]
17+
18+
#![crate_id = "a"]
19+
20+
macro_rules! three {
21+
() => { 3 }
22+
}
23+
24+
pub trait U {}
25+
pub trait V {}
26+
impl U for () {}
27+
impl V for () {}
28+
29+
static A_CONSTANT : int = 2;
30+
31+
// Adding some documentation does not affect the svh.
32+
33+
/// foo always returns three.
34+
pub fn foo<T:U>(_: int) -> int {
35+
3
36+
}
37+
38+
pub fn an_unused_name() -> int {
39+
4
40+
}

0 commit comments

Comments
 (0)