rust/compiler/rustc_data_structures/src
bors b3f1379509 Auto merge of #110083 - saethlin:encode-hashes-as-bytes, r=cjgillot
Encode hashes as bytes, not varint

In a few places, we store hashes as `u64` or `u128` and then apply `derive(Decodable, Encodable)` to the enclosing struct/enum. It is more efficient to encode hashes directly than try to apply some varint encoding. This PR adds two new types `Hash64` and `Hash128` which are produced by `StableHasher` and replace every use of storing a `u64` or `u128` that represents a hash.

Distribution of the byte lengths of leb128 encodings, from `x build --stage 2` with `incremental = true`

Before:
```
(  1) 373418203 (53.7%, 53.7%): 1
(  2) 196240113 (28.2%, 81.9%): 3
(  3) 108157958 (15.6%, 97.5%): 2
(  4)  17213120 ( 2.5%, 99.9%): 4
(  5)    223614 ( 0.0%,100.0%): 9
(  6)    216262 ( 0.0%,100.0%): 10
(  7)     15447 ( 0.0%,100.0%): 5
(  8)      3633 ( 0.0%,100.0%): 19
(  9)      3030 ( 0.0%,100.0%): 8
( 10)      1167 ( 0.0%,100.0%): 18
( 11)      1032 ( 0.0%,100.0%): 7
( 12)      1003 ( 0.0%,100.0%): 6
( 13)        10 ( 0.0%,100.0%): 16
( 14)        10 ( 0.0%,100.0%): 17
( 15)         5 ( 0.0%,100.0%): 12
( 16)         4 ( 0.0%,100.0%): 14
```

After:
```
(  1) 372939136 (53.7%, 53.7%): 1
(  2) 196240140 (28.3%, 82.0%): 3
(  3) 108014969 (15.6%, 97.5%): 2
(  4)  17192375 ( 2.5%,100.0%): 4
(  5)       435 ( 0.0%,100.0%): 5
(  6)        83 ( 0.0%,100.0%): 18
(  7)        79 ( 0.0%,100.0%): 10
(  8)        50 ( 0.0%,100.0%): 9
(  9)         6 ( 0.0%,100.0%): 19
```

The remaining 9 or 10 and 18 or 19 are `u64` and `u128` respectively that have the high bits set. As far as I can tell these are coming primarily from `SwitchTargets`.
2023-04-18 22:27:15 +00:00
..
base_n Adapt rustc_data_structures tests to run in strict miri 2022-06-04 17:46:29 +02:00
binary_search_util Adopt let else in more places 2022-02-19 17:27:43 +01:00
fingerprint Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
flock migrate compiler, bootstrap, and compiletest to windows-rs 2023-03-20 13:19:35 -04:00
graph Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
intern Rename PtrKey as Interned and improve it. 2022-02-15 15:50:29 +11:00
obligation_forest Fast path that skips over unchanged obligations in process_obligations 2023-03-17 19:56:03 +01:00
owned_slice Support multithreaded mode in OwnedSlice tests 2023-04-06 18:13:07 +00:00
profiling Don't use serde_json to serialize a simple JSON object 2023-04-16 15:00:06 +02:00
sip128 Use SipHash-1-3 instead of SipHash-2-4 for StableHasher 2023-04-05 15:48:37 +00:00
small_c_str mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
small_str Add SmallStr 2022-03-04 16:57:34 +01:00
snapshot_map Call the method fork instead of clone and add proper comments 2022-02-14 12:57:20 -03:00
sorted_map Add contains_key to SortedIndexMultiMap 2023-02-28 17:15:00 +01:00
sso fix clippy::toplevel_ref_arg and ::manual_map 2023-04-16 13:28:13 +02:00
stable_hasher Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
sync Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
tagged_ptr Use ptr::Alignment for extra coolness points 2023-04-14 12:31:49 +00:00
tiny_list rustc_data_structures: remove ref patterns and other artifacts of the past 2023-01-17 07:48:19 +00:00
transitive_relation get rid of RefCell in TransitiveRelation 2022-08-22 18:08:46 +08:00
aligned.rs fix broken intradoclinks 2023-04-14 13:04:58 +00:00
atomic_ref.rs mv compiler to compiler/ 2020-08-30 18:45:07 +03:00
base_n.rs minor code cleanups 2022-12-12 19:49:53 +01:00
captures.rs Remove #[allow(unused_lifetimes)] which is now unnecessary 2021-06-17 08:56:54 +09:00
fingerprint.rs Add #[inline] to some new functions 2023-04-18 14:13:19 -04:00
flat_map_in_place.rs Rename MapInPlace as FlatMapInPlace. 2023-03-08 15:53:56 +11:00
flock.rs migrate compiler, bootstrap, and compiletest to windows-rs 2023-03-20 13:19:35 -04:00
frozen.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
functor.rs Refactor refcounted structural_impls via functors 2023-02-14 12:14:58 +00:00
fx.rs Use UnordMap instead of FxHashMap in define_id_collections!(). 2023-01-19 10:40:47 +01:00
hashes.rs Add #[inline] to some new functions 2023-04-18 14:13:19 -04:00
intern.rs Rollup merge of #104898 - oli-obk:group_all_the_things, r=wesleywiser 2022-12-06 16:54:52 +01:00
jobserver.rs Move/rename lazy::Sync{OnceCell,Lazy} to sync::{Once,Lazy}Lock 2022-06-16 19:54:42 +04:00
lib.rs Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
macros.rs Introduce ChunkedBitSet and use it for some dataflow analyses. 2022-02-23 10:18:49 +11:00
memmap.rs Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
owned_slice.rs Mark OwnedSlice::{deref, borrow} as #[inline] 2023-04-07 10:14:50 +00:00
profiling.rs Rollup merge of #110417 - jsoref:spelling-compiler, r=Nilstrieb 2023-04-18 14:50:51 +02:00
sharded.rs Allow modulo_one on function using cfg consts 2023-04-09 22:30:24 +02:00
sip128.rs Use SipHash-1-3 instead of SipHash-2-4 for StableHasher 2023-04-05 15:48:37 +00:00
small_c_str.rs Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
small_str.rs Add SmallStr 2022-03-04 16:57:34 +01:00
sorted_map.rs rustc_data_structures: remove ref patterns and other artifacts of the past 2023-01-17 07:48:19 +00:00
stable_hasher.rs Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
stack.rs Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
steal.rs Harden the pre-tyctxt query system against accidental recomputation 2023-01-12 09:26:28 +00:00
svh.rs Store hashes in special types so they aren't accidentally encoded as numbers 2023-04-18 10:52:47 -04:00
sync.rs Auto merge of #109971 - WaffleLapkin:yeet_ownership, r=Nilstrieb 2023-04-08 01:08:26 +00:00
tagged_ptr.rs Use ptr::Alignment for extra coolness points 2023-04-14 12:31:49 +00:00
temp_dir.rs Capitalize safety comments 2020-09-08 22:37:18 -04:00
tiny_list.rs rustc_data_structures: remove ref patterns and other artifacts of the past 2023-01-17 07:48:19 +00:00
transitive_relation.rs Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
unhash.rs Avoid rehashing Fingerprint as a map key 2020-09-01 18:27:02 -07:00
unord.rs Fix some clippy::complexity 2023-04-09 23:22:14 +02:00
vec_linked_list.rs Stop enabling in_band_lifetimes in rustc_data_structures 2021-12-05 20:17:35 -08:00
work_queue.rs Remove (lots of) dead code 2021-03-27 22:16:33 -04:00