Commit 3ff54e5
committed
feat: use stable hash from rustc-stable-hash
This helps `-Ztrim-paths` build a stable cross-platform path for the
registry and git sources. Sources files then can be found from the same
path when debugging.
See #13171 (comment)
A few caveats:
* This will invalidate the current downloaded caches.
Need to put this in the Cargo CHANGELOG.
* As a consequence of changing how `SourceId` is hashed, the global cache
tracker is also affected because Cargo writes source identifiers (e.g.
`index.crates.io-6f17d22bba15001f`) to SQLite.
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/core/global_cache_tracker.rs#L388-L391
* The performance of rustc-stable-hash is slightly worse than the old
SipHasher in std on short things like `SourceId`, but for long stuff
like fingerprint. See appendix.
StableHasher is used in several places (some might not be needed?):
* Rebuild detection (fingerprints)
* Rustc version, including all the CLI args running `rustc -vV`.
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/util/rustc.rs#L326
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/util/rustc.rs#L381
* Build caches
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/core/compiler/fingerprint/mod.rs#L1456
* Compute rustc `-C metadata`
* stable hash for SourceId
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/core/package_id.rs#L207
* Also read and hash contents from custom target JSON file.
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/core/compiler/compile_kind.rs#L81-L91
* `UnitInner::dep_hash`
* This is to distinguish same units having different features set between normal and build dependencies.
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/ops/cargo_compile/mod.rs#L627
* Hash file contents for `cargo package` to verify if files were modified before and after the build.
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/ops/cargo_package.rs#L999
* Rusc diagnostics deduplication
* https://github.com/rust-lang/cargo/blob/6e236509b2331eef64df844b7bbc8ed352294107/src/cargo/core/compiler/job_queue/mod.rs#L311
* Places using `SourceId` identifier like `registry/src` path,
and `-Zscript` target directories.
Appendix
--------
Benchmark on x86_64-unknown-linux-gnu
```
bench_hasher/RustcStableHasher/URL
time: [33.843 ps 33.844 ps 33.845 ps]
change: [-0.0167% -0.0049% +0.0072%] (p = 0.44 > 0.05)
No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
5 (5.00%) low severe
3 (3.00%) high mild
2 (2.00%) high severe
bench_hasher/SipHasher/URL
time: [18.954 ns 18.954 ns 18.955 ns]
change: [-0.1281% -0.0951% -0.0644%] (p = 0.00 < 0.05)
Change within noise threshold.
Found 14 outliers among 100 measurements (14.00%)
3 (3.00%) low severe
4 (4.00%) low mild
3 (3.00%) high mild
4 (4.00%) high severe
bench_hasher/RustcStableHasher/lorem ipsum
time: [659.18 ns 659.20 ns 659.22 ns]
change: [-0.0192% -0.0062% +0.0068%] (p = 0.34 > 0.05)
No change in performance detected.
Found 12 outliers among 100 measurements (12.00%)
4 (4.00%) low severe
3 (3.00%) low mild
3 (3.00%) high mild
2 (2.00%) high severe
bench_hasher/SipHasher/lorem ipsum
time: [1.2006 µs 1.2008 µs 1.2010 µs]
change: [+0.0117% +0.0467% +0.0808%] (p = 0.01 < 0.05)
Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
1 (1.00%) high mild
```1 parent 6e23650 commit 3ff54e5
File tree
8 files changed
+73
-41
lines changed- src/cargo
- core
- compiler
- build_runner
- ops/cargo_compile
- util
8 files changed
+73
-41
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
| |||
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| 186 | + | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
786 | 786 | | |
787 | 787 | | |
788 | 788 | | |
789 | | - | |
790 | | - | |
791 | | - | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
792 | 794 | | |
793 | | - | |
794 | 795 | | |
795 | 796 | | |
796 | 797 | | |
797 | | - | |
| 798 | + | |
798 | 799 | | |
799 | 800 | | |
800 | 801 | | |
801 | 802 | | |
802 | 803 | | |
803 | 804 | | |
804 | | - | |
805 | 805 | | |
806 | | - | |
| 806 | + | |
807 | 807 | | |
808 | 808 | | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
809 | 814 | | |
810 | | - | |
811 | | - | |
| 815 | + | |
| 816 | + | |
812 | 817 | | |
813 | 818 | | |
814 | 819 | | |
815 | 820 | | |
816 | 821 | | |
817 | | - | |
818 | | - | |
| 822 | + | |
| 823 | + | |
819 | 824 | | |
820 | 825 | | |
821 | 826 | | |
822 | | - | |
823 | | - | |
| 827 | + | |
| 828 | + | |
824 | 829 | | |
825 | 830 | | |
826 | 831 | | |
827 | | - | |
828 | | - | |
| 832 | + | |
| 833 | + | |
829 | 834 | | |
830 | 835 | | |
831 | 836 | | |
832 | | - | |
833 | | - | |
| 837 | + | |
| 838 | + | |
834 | 839 | | |
835 | 840 | | |
836 | 841 | | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
| 842 | + | |
| 843 | + | |
841 | 844 | | |
| 845 | + | |
842 | 846 | | |
843 | | - | |
844 | | - | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
845 | 857 | | |
846 | 858 | | |
847 | | - | |
848 | | - | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
849 | 864 | | |
850 | 865 | | |
851 | | - | |
852 | | - | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
853 | 876 | | |
854 | 877 | | |
855 | 878 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
| 39 | + | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | | - | |
| 3 | + | |
6 | 4 | | |
7 | | - | |
8 | | - | |
9 | | - | |
| 5 | + | |
10 | 6 | | |
11 | 7 | | |
12 | 8 | | |
13 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments