Change:
This issue is part of a broader effort to implement comprehensive regression testing for incremental compilation. For the tracking issue go to . For incremental compilation we need to determine if a given HIR node has changed in between two versions of a program. This is implemented in the module. We compute a hash value for each HIR node that corresponds to a node in the dependency graph and then compare those hash values. We call this hash value the Incremental Compilation Hash (ICH) of the HIR node. It is supposed to be sensitive to any change that might make a semantic difference to the thing being hashed. The auto-tests in the directory all follow the same pattern: Each source file defines one test case The source file is compiled multiple times with incremental compilation turned on, each time with a different flag, allowing each version to differ via conditional compilation. Each of these versions we call a revision. During each revision, the test runner will make sure that some assertions about the dependency graph of the program hold. These assertions are specified in the source code of the test file as attributes attached to the items being tested (e.g. /). The ICH-specific tests use this framework by adhering to the following pattern: There are two versions of the definition under test, one marked with and the second marked with . As a consequence, the first revision will be compiled with the first version of the definition, and all other revisions will be compiled with the second version. The two versions are supposed to differ in exactly one aspect (e.g. the visibility of a field is different, or the return of a function has changed). The second definition has a attribute attached. This attribute makes the test runner check that a change of the dependency node of the definition has been detected between revisions and . This will effectively test that a different ICH value has been computed for the two versions of the definition. The second definition also has a attribute. This makes sure that the dependency node (and thus the ICH) of the definition has not changed between revisions and . That's what we expect, because both revisions use the same version of the definition. For definitions that are exported from the crate, we also want to check the ICH of the corresponding metadata. This is tested using the / attributes and works analogous to the case: We add to the second definition to make sure that the ICH of the exported metadata is not the same for the different versions of the definition, and we add to make sure that the ICH is the same for the two identical versions of the definition. Why are the revisions called "cfail"? That's because of reasons internal to how the test-runner works. Prefixing a revision with "cfail" tells the test runner to treat the test like a "compile-file" test, that is: compile the test case but don't actually run it (which would be the case for an "rpass" revision). For the ICH tests we need to compile "rlibs", so that we can test metadata ICHs. As a consequence we cannot declare them "rpass". In an additional directive (), we tell the test runner that we actually expect the file to not produce any errors. Each test case must contain the following test-runner directives and crate attributes at the top: See for a full example of such a ICH regression test. Each of the following things should be tested with its own definition pair: Change the visibility of a Change the mutability of a Add a attribute Add a attribute Add a attribute Change the type of a from to Change the type of a from to Change the value of a from a simple literal to another one (e.g. to ) Change the value of a from to Change the value of a from to Change the value of a from =- Change the type of a by modifying a use statement
Hi, I'd like to do this (and probably also consts), and am currently working on it.

Discussion:
<ins> // Copyright 2016 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. // This test case tests the incremental compilation hash (ICH) implementation // for consts. // The general pattern followed here is: Change one thing between rev1 and rev2 // and make sure that the hash has changed, then change nothing between rev2 and // rev3 and make sure that the hash has not changed. // must-compile-successfully // revisions: cfail1 cfail2 cfail3 // compile-flags: -Z query-dep-graph #![allow(warnings)] #![feature(rustc_attrs)] #![crate_type="rlib"] // Change const visibility --------------------------------------------------- #[cfg(cfail1)] const CONST_VISIBILITY: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] pub const CONST_VISIBILITY: u8 = 0; // Change type from i32 to u32 ------------------------------------------------ #[cfg(cfail1)] const CONST_CHANGE_TYPE_1: i32 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_1: u32 = 0; // Change type from Option<u32> to Option<u64> -------------------------------- #[cfg(cfail1)] const CONST_CHANGE_TYPE_2: Option<u32> = None; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_2: Option<u64> = None; // Change value between simple literals --------------------------------------- #[cfg(cfail1)] const CONST_CHANGE_VALUE_1: i16 = 1; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_VALUE_1: i16 = 2; // Change value between expressions ------------------------------------------- #[cfg(cfail1)] const CONST_CHANGE_VALUE_2: i16 = 1 + 1; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_VALUE_2: i16 = 1 + 2; #[cfg(cfail1)] const CONST_CHANGE_VALUE_3: i16 = 2 + 3; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_VALUE_3: i16 = 2 * 3; #[cfg(cfail1)] const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 3; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_VALUE_4: i16 = 1 + 2 * 4; // Change type indirectly ----------------------------------------------------- struct ReferencedType1; struct ReferencedType2; mod const_change_type_indirectly { #[cfg(cfail1)] use super::ReferencedType1 as Type; #[cfg(not(cfail1))] use super::ReferencedType2 as Type; #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_1: Type = Type; #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] const CONST_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None; } </ins>

<ins> // Copyright 2016 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. // This test case tests the incremental compilation hash (ICH) implementation // for statics. // The general pattern followed here is: Change one thing between rev1 and rev2 // and make sure that the hash has changed, then change nothing between rev2 and // rev3 and make sure that the hash has not changed. // must-compile-successfully // revisions: cfail1 cfail2 cfail3 // compile-flags: -Z query-dep-graph #![allow(warnings)] #![feature(rustc_attrs)] #![feature(linkage)] #![feature(thread_local)] #![crate_type="rlib"] // Change static visibility --------------------------------------------------- #[cfg(cfail1)] static STATIC_VISIBILITY: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] pub static STATIC_VISIBILITY: u8 = 0; // Change static mutability --------------------------------------------------- #[cfg(cfail1)] static STATIC_MUTABILITY: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static mut STATIC_MUTABILITY: u8 = 0; // Add linkage attribute ------------------------------------------------------ #[cfg(cfail1)] static STATIC_LINKAGE: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] #[linkage="weak_odr"] static STATIC_LINKAGE: u8 = 0; // Add no_mangle attribute ---------------------------------------------------- #[cfg(cfail1)] static STATIC_NO_MANGLE: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] #[no_mangle] static STATIC_NO_MANGLE: u8 = 0; // Add thread_local attribute ------------------------------------------------- #[cfg(cfail1)] static STATIC_THREAD_LOCAL: u8 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] #[thread_local] static STATIC_THREAD_LOCAL: u8 = 0; // Change type from i16 to u64 ------------------------------------------------ #[cfg(cfail1)] static STATIC_CHANGE_TYPE_1: i16 = 0; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_1: u64 = 0; // Change type from Option<i8> to Option<u16> --------------------------------- #[cfg(cfail1)] static STATIC_CHANGE_TYPE_2: Option<i8> = None; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_2: Option<u16> = None; // Change value between simple literals --------------------------------------- #[cfg(cfail1)] static STATIC_CHANGE_VALUE_1: i16 = 1; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_VALUE_1: i16 = 2; // Change value between expressions ------------------------------------------- #[cfg(cfail1)] static STATIC_CHANGE_VALUE_2: i16 = 1 + 1; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_VALUE_2: i16 = 1 + 2; #[cfg(cfail1)] static STATIC_CHANGE_VALUE_3: i16 = 2 + 3; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_VALUE_3: i16 = 2 * 3; #[cfg(cfail1)] static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 3; #[cfg(not(cfail1))] #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_VALUE_4: i16 = 1 + 2 * 4; // Change type indirectly ----------------------------------------------------- struct ReferencedType1; struct ReferencedType2; mod static_change_type_indirectly { #[cfg(cfail1)] use super::ReferencedType1 as Type; #[cfg(not(cfail1))] use super::ReferencedType2 as Type; #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_1: Type = Type; #[rustc_dirty(label="Hir", cfg="cfail2")] #[rustc_clean(label="Hir", cfg="cfail3")] #[rustc_metadata_dirty(cfg="cfail2")] #[rustc_metadata_clean(cfg="cfail3")] static STATIC_CHANGE_TYPE_INDIRECTLY_2: Option<Type> = None; } </ins>