]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #40878 - michaelwoerister:dmh, r=nikomatsakis
authorCorey Farwell <coreyf@rwell.org>
Thu, 6 Apr 2017 18:55:02 +0000 (14:55 -0400)
committerGitHub <noreply@github.com>
Thu, 6 Apr 2017 18:55:02 +0000 (14:55 -0400)
Introduce HashStable trait and base ICH implementations on it.

This PR introduces the `HashStable` trait which marks that a type can be hashed in a way that is stable across multiple compilation sessions. The PR also moves HIR incr. comp. hashing over to implementations of this trait instead of doing this via a HIR visitor. It also provides many `HashStable` implementations that are not used yet (e.g. for MIR types) but soon will be used when we directly hash crate metadata for incr. comp.

I've only done superficial performance measurements but it looks like the new implementation is a bit faster than the current one (due, I suppose, to some bugs I fixed and some unnecessary inefficiencies I removed). Here is the time in seconds for the `compute_incremental_hashes_map` pass for various crates:

|                 |  OLD  |  NEW  |
|:---------------:|:-----:|:-----:|
| libcore         | 0.507 | 0.409 |
| libsyntax       | 0.320 | 0.260 |
| librustc        | 0.730 | 0.611 |
| librustc_driver | 0.024 | 0.015 |

Some notes regarding the implementation:
* Most `HashStable` implementations are provided via the `impl_hash_stable_for!` macro (as suggested by @nikomatsakis). This works out quite well. A custom_derive would have been better but Macros 1.1 are not available in the compiler.
* The trait implementation take care to exhaustively destructure everything they hash so that fields added in the future don't fall through the cracks. This is a bit verbose but I think it's well worth the trouble since we've had quite a few issues with missing fields or visitor callbacks in this area in the past. Most of it is behind the macro anyway.

cc @rust-lang/compiler
r? @nikomatsakis


Trivial merge