-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incr.comp.: Create Test Case for Incr. Comp. Hash for function interfaces #36812
Comments
@michaelwoerister I would like to take this one up, looks like a good way to start contributing to Rust. |
@MathieuBordere Excellent! I'd start by copying src/test/incremental/hashes/struct_defs.rs and adapting it. If you have any questions, just post them here. To execute the incremental compilation test suite, run |
@michaelwoerister I've got a couple of questions
|
Congratulations, your tests have discovered a hole in the incr. comp. logic! You can try to fix it (closing #36914 in the process) or comment the particular part of the test out and put a
You can add |
That means that you've discovered a bug there. I've opened #36914 with regard to this. I'd suggest that you comment out that particular case and caption it with something like:
You can activate those features with a |
@michaelwoerister @jonas-schievink There are actually 4 failing cases:
@michaelwoerister I would be interested in fixing the bugs myself |
OK, so the reason these tests fail is that the StrictVersionHashVisitor does not incorporate these things into the hash. The The implementation of the hashing visitor follows a specific pattern the workings of which might not be immediately obvious: Instead of hashing things directly, it copies the data that should be hashed into an aggregate value (the SawXXX types) and then hashes that. For example, it is: fn visit_name(&mut self, span: Span, name: Name) {
debug!("visit_name: st={:?}", self.st);
SawIdent(name.as_str()).hash(self.st);
hash_span!(self, span);
} instead of something like: fn visit_name(&mut self, span: Span, name: Name) {
debug!("visit_name: st={:?}", self.st);
"ident".hash(self.st)
name.as_str().hash(self.st);
hash_span!(self, span);
} Whether using this pattern is strictly better than not using it, I'm not sure, but it's been there for some time and I'd say we just keep following it. In general HIR visitors work like this:
Here's an example: // This gets called when the visitor encounters a struct field
fn visit_struct_field(&mut self, s: &'tcx StructField) {
// We record that we saw a struct field
SawStructField.hash(self.st);
// We hash the span of the field
hash_span!(self, s.span);
// We hash the attributes of the field
hash_attrs!(self, &s.attrs);
// Now we recurse further into the StructField structure
// where the visitor will encounter the name of the field
// (and hash it via visit_name()) and its type (and hash it
// via visit_ty())
visit::walk_struct_field(self, s)
} Now for the bugs we are trying to fix: The problem is that hashing simply skips those things. The information about I would suggest creating a new #[derive(Hash)]
enum SawItemComponent {
SawItemExternCrate,
SawItemUse,
SawItemStatic(Mutability),
SawItemConst,
SawItemFn(Unsafety, Constness, Abi),
...
}
// See saw_expr() for reference
fn saw_item(node: &Item_) -> SawItemComponent {
match *node {
ItemExternCrate(..) => SawItemExternCrate,
ItemUse(..) => SawItemUse,
ItemStatic(_, mutability, _) => SawItemStatic,
ItemConst(..) =>SawItemConst,
ItemFn(_, unsafety, constness, abi, _, _) => SawItemFn(unsafety, constness, abi),
...
}
}
fn visit_item(&mut self, i: &'tcx Item) {
debug!("visit_item: {:?} st={:?}", i, self.st);
SawItem(saw_item(&i.node)).hash(self.st);
hash_span!(self, i.span);
hash_attrs!(self, &i.attrs);
visit::walk_item(self, i)
} That would take care of the |
Thanks for the lengthy write-up, I'm looking into it, but will probably need some time to digest it |
No problem, it is a lot to digest and read up on in the code. |
Thanks, I'm almost there, tests are passing now. Last little question, I'm a bit confused by the difference between |
@MathieuBordere The traits/builtins you have chosen are OK. It's actually not that important since the compiler doesn't distinguish the two at the HIR level yet, but better to be on the safe side. |
make check is failing with |
It's unlikely that your changes have something to do with that. I wouldn't put too much time into debugging it. |
…Interfaces, r=michaelwoerister Mb/36812 ich function interfaces r? @michaelwoerister This PR contains fixes for rust-lang#36812 and rust-lang#36914
Fixed by #36974 |
This issue is part of a broader effort to implement comprehensive regression testing for incremental compilation. For the tracking issue go to #36350.
Background
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 calculate_svh 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.
Testing Methodology
The auto-tests in the
src/test/incremental
directory all follow the same pattern:--cfg
flag, allowing each version to differ via conditional compilation. Each of these versions we call a revision.#[rustc_clean]
/#[rustc_dirty]
).The ICH-specific tests use this framework by adhering to the following pattern:
#[cfg(cfail1)]
and the second marked with#[cfg(not(cfail1))]
. 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).#[rustc_dirty(label="Hir", cfg="cfail2")]
attribute attached. This attribute makes the test runner check that a change of theHir
dependency node of the definition has been detected between revisionscfail1
andcfail2
. This will effectively test that a different ICH value has been computed for the two versions of the definition.#[rustc_clean(label="Hir", cfg="cfail3")]
attribute. This makes sure that theHir
dependency node (and thus the ICH) of the definition has not changed between revisionscfail2
andcfail3
. That's what we expect, because both revisions use the same version of the definition.#[rustc_metadata_clean]
/#[rustc_metadata_dirty]
attributes and works analogous to theHir
case: We add#[rustc_metadata_dirty(cfg="cfail2")]
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#[rustc_metadata_dirty(cfg="cfail3")]
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 (
// must-compile-successfully
), 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 src/test/incremental/hashes/struct_defs.rs for a full example of such a ICH regression test.
Function Interface Specific ICH Testing
Each of the following things should be tested with its own definition pair:
extern
modifier to functionextern "C"
toextern "rust-intrinsic"
#[inline]
attribute to the function#[inline]
to#[inline(never)]
#[no_mangle]
attribute to the function#[linkage]
attribute to the function-> impl Trait
(if that works already)EDIT: Some more cases
use
statementuse
statementuse
statementuse
statementThe text was updated successfully, but these errors were encountered: