Skip to content

Commit 9c548bf

Browse files
committed
get rustc_hash from external crate
1 parent 6f425a9 commit 9c548bf

File tree

4 files changed

+34
-85
lines changed

4 files changed

+34
-85
lines changed

src/Cargo.lock

+28
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,23 @@ name = "cfg-if"
261261
version = "0.1.2"
262262
source = "registry+https://github.com/rust-lang/crates.io-index"
263263

264+
[[package]]
265+
name = "chalk-engine"
266+
version = "0.6.0"
267+
source = "registry+https://github.com/rust-lang/crates.io-index"
268+
dependencies = [
269+
"chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
270+
"rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
271+
]
272+
273+
[[package]]
274+
name = "chalk-macros"
275+
version = "0.1.0"
276+
source = "registry+https://github.com/rust-lang/crates.io-index"
277+
dependencies = [
278+
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
279+
]
280+
264281
[[package]]
265282
name = "chrono"
266283
version = "0.4.1"
@@ -1739,6 +1756,7 @@ dependencies = [
17391756
"backtrace 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
17401757
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
17411758
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
1759+
"chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
17421760
"flate2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
17431761
"fmt_macros 0.0.0",
17441762
"graphviz 0.0.0",
@@ -1840,6 +1858,11 @@ name = "rustc-demangle"
18401858
version = "0.1.7"
18411859
source = "registry+https://github.com/rust-lang/crates.io-index"
18421860

1861+
[[package]]
1862+
name = "rustc-hash"
1863+
version = "1.0.0"
1864+
source = "registry+https://github.com/rust-lang/crates.io-index"
1865+
18431866
[[package]]
18441867
name = "rustc-main"
18451868
version = "0.0.0"
@@ -1982,6 +2005,7 @@ dependencies = [
19822005
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
19832006
"parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
19842007
"parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)",
2008+
"rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
19852009
"rustc-rayon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
19862010
"rustc_cratesio_shim 0.0.0",
19872011
"serialize 0.0.0",
@@ -2216,6 +2240,7 @@ name = "rustc_traits"
22162240
version = "0.0.0"
22172241
dependencies = [
22182242
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
2243+
"chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
22192244
"graphviz 0.0.0",
22202245
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
22212246
"rustc 0.0.0",
@@ -2998,6 +3023,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
29983023
"checksum cargo_metadata 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ebd6272a2ca4fd39dbabbd6611eb03df45c2259b3b80b39a9ff8fbdcf42a4b3"
29993024
"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba"
30003025
"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de"
3026+
"checksum chalk-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a146c19172c7eea48ea55a7123ac95da786639bc665097f1e14034ee5f1d8699"
3027+
"checksum chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "295635afd6853aa9f20baeb7f0204862440c0fe994c5a253d5f479dac41d047e"
30013028
"checksum chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ba5f60682a4c264e7f8d77b82e7788938a76befdf949d4a98026d19099c9d873"
30023029
"checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536"
30033030
"checksum clippy_lints 0.0.200 (registry+https://github.com/rust-lang/crates.io-index)" = "d2432663f6bdb90255dcf9df5ca504f99b575bb471281591138f62f9d31f863b"
@@ -3142,6 +3169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
31423169
"checksum rustc-ap-syntax 128.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf9ca2901388714e9ccc7de7281ef06cec55d9f245252ba1d635bc86c730d9a"
31433170
"checksum rustc-ap-syntax_pos 128.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5217444369a36e98e11f4ac976f03878704893832e2e0b57d49f2f31438139f"
31443171
"checksum rustc-demangle 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11fb43a206a04116ffd7cfcf9bcb941f8eb6cc7ff667272246b0a1c74259a3cb"
3172+
"checksum rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e06ddba37baa245040f932b15403071a46681d7e0e4158e230741943c4718b84"
31453173
"checksum rustc-rayon 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b1aa5cd8c3a706edb19b6ec6aa7b056bdc635b6e99c5cf7014f9af9d92f15e99"
31463174
"checksum rustc-rayon-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d69983f8613a9c3ba1a3bbf5e8bdf2fd5c42317b1d8dd8623ca8030173bf8a6b"
31473175
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"

src/librustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cfg-if = "0.1.2"
1717
stable_deref_trait = "1.0.0"
1818
parking_lot_core = "0.2.8"
1919
rustc-rayon = "0.1.0"
20+
rustc-hash = "1.0.0"
2021

2122
[dependencies.parking_lot]
2223
version = "0.5"

src/librustc_data_structures/fx.rs

+4-85
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
use std::collections::{HashMap, HashSet};
1212
use std::default::Default;
13-
use std::hash::{Hasher, Hash, BuildHasherDefault};
14-
use std::ops::BitXor;
13+
use std::hash::Hash;
1514

16-
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
17-
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
15+
pub use rustc_hash::FxHashMap;
16+
pub use rustc_hash::FxHashSet;
17+
pub use rustc_hash::FxHasher;
1818

1919
#[allow(non_snake_case)]
2020
pub fn FxHashMap<K: Hash + Eq, V>() -> FxHashMap<K, V> {
@@ -26,84 +26,3 @@ pub fn FxHashSet<V: Hash + Eq>() -> FxHashSet<V> {
2626
HashSet::default()
2727
}
2828

29-
/// A speedy hash algorithm for use within rustc. The hashmap in liballoc
30-
/// by default uses SipHash which isn't quite as speedy as we want. In the
31-
/// compiler we're not really worried about DOS attempts, so we use a fast
32-
/// non-cryptographic hash.
33-
///
34-
/// This is the same as the algorithm used by Firefox -- which is a homespun
35-
/// one not based on any widely-known algorithm -- though modified to produce
36-
/// 64-bit hash values instead of 32-bit hash values. It consistently
37-
/// out-performs an FNV-based hash within rustc itself -- the collision rate is
38-
/// similar or slightly worse than FNV, but the speed of the hash function
39-
/// itself is much higher because it works on up to 8 bytes at a time.
40-
pub struct FxHasher {
41-
hash: usize
42-
}
43-
44-
#[cfg(target_pointer_width = "32")]
45-
const K: usize = 0x9e3779b9;
46-
#[cfg(target_pointer_width = "64")]
47-
const K: usize = 0x517cc1b727220a95;
48-
49-
impl Default for FxHasher {
50-
#[inline]
51-
fn default() -> FxHasher {
52-
FxHasher { hash: 0 }
53-
}
54-
}
55-
56-
impl FxHasher {
57-
#[inline]
58-
fn add_to_hash(&mut self, i: usize) {
59-
self.hash = self.hash.rotate_left(5).bitxor(i).wrapping_mul(K);
60-
}
61-
}
62-
63-
impl Hasher for FxHasher {
64-
#[inline]
65-
fn write(&mut self, bytes: &[u8]) {
66-
for byte in bytes {
67-
let i = *byte;
68-
self.add_to_hash(i as usize);
69-
}
70-
}
71-
72-
#[inline]
73-
fn write_u8(&mut self, i: u8) {
74-
self.add_to_hash(i as usize);
75-
}
76-
77-
#[inline]
78-
fn write_u16(&mut self, i: u16) {
79-
self.add_to_hash(i as usize);
80-
}
81-
82-
#[inline]
83-
fn write_u32(&mut self, i: u32) {
84-
self.add_to_hash(i as usize);
85-
}
86-
87-
#[cfg(target_pointer_width = "32")]
88-
#[inline]
89-
fn write_u64(&mut self, i: u64) {
90-
self.add_to_hash(i as usize);
91-
self.add_to_hash((i >> 32) as usize);
92-
}
93-
94-
#[cfg(target_pointer_width = "64")]
95-
#[inline]
96-
fn write_u64(&mut self, i: u64) {
97-
self.add_to_hash(i as usize);
98-
}
99-
100-
#[inline]
101-
fn write_usize(&mut self, i: usize) {
102-
self.add_to_hash(i);
103-
}
104-
105-
#[inline]
106-
fn finish(&self) -> u64 {
107-
self.hash as u64
108-
}
109-
}

src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ extern crate parking_lot;
4444
extern crate cfg_if;
4545
extern crate stable_deref_trait;
4646
extern crate rustc_rayon as rayon;
47+
extern crate rustc_hash;
4748

4849
// See librustc_cratesio_shim/Cargo.toml for a comment explaining this.
4950
#[allow(unused_extern_crates)]

0 commit comments

Comments
 (0)