Skip to content

Commit d800dfd

Browse files
committed
try ahash for interners
1 parent f8cb67c commit d800dfd

File tree

4 files changed

+34
-33
lines changed

4 files changed

+34
-33
lines changed

Diff for: Cargo.lock

+8-6
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ dependencies = [
3737

3838
[[package]]
3939
name = "ahash"
40-
version = "0.8.6"
40+
version = "0.8.7"
4141
source = "registry+https://github.com/rust-lang/crates.io-index"
42-
checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a"
42+
checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01"
4343
dependencies = [
4444
"cfg-if",
45+
"getrandom",
4546
"once_cell",
4647
"version_check",
4748
"zerocopy",
@@ -3663,6 +3664,7 @@ dependencies = [
36633664
name = "rustc_data_structures"
36643665
version = "0.0.0"
36653666
dependencies = [
3667+
"ahash",
36663668
"arrayvec",
36673669
"bitflags 2.4.1",
36683670
"elsa",
@@ -6373,18 +6375,18 @@ dependencies = [
63736375

63746376
[[package]]
63756377
name = "zerocopy"
6376-
version = "0.7.28"
6378+
version = "0.7.32"
63776379
source = "registry+https://github.com/rust-lang/crates.io-index"
6378-
checksum = "7d6f15f7ade05d2a4935e34a457b936c23dc70a05cc1d97133dc99e7a3fe0f0e"
6380+
checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be"
63796381
dependencies = [
63806382
"zerocopy-derive",
63816383
]
63826384

63836385
[[package]]
63846386
name = "zerocopy-derive"
6385-
version = "0.7.28"
6387+
version = "0.7.32"
63866388
source = "registry+https://github.com/rust-lang/crates.io-index"
6387-
checksum = "dbbad221e3f78500350ecbd7dfa4e63ef945c05f4c61cb7f4d3f84cd0bba649b"
6389+
checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6"
63886390
dependencies = [
63896391
"proc-macro2",
63906392
"quote",

Diff for: compiler/rustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.0.0"
44
edition = "2021"
55

66
[dependencies]
7+
ahash = "0.8.7"
78
# tidy-alphabetical-start
89
arrayvec = { version = "0.7", default-features = false }
910
bitflags = "2.4.1"

Diff for: compiler/rustc_data_structures/src/sharded.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn shards() -> usize {
158158
1
159159
}
160160

161-
pub type ShardedHashMap<K, V> = Sharded<FxHashMap<K, V>>;
161+
pub type ShardedHashMap<K, V> = Sharded<ahash::AHashMap<K, V>>;
162162

163163
impl<K: Eq, V> ShardedHashMap<K, V> {
164164
pub fn len(&self) -> usize {

Diff for: compiler/rustc_infer/src/infer/freshen.rs

+24-26
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@
3131
//! variable only once, and it does so as soon as it can, so it is reasonable to ask what the type
3232
//! inferencer knows "so far".
3333
use super::InferCtxt;
34+
use rustc_data_structures::fx::FxHashMap;
3435
use rustc_middle::infer::unify_key::ToType;
3536
use rustc_middle::ty::fold::TypeFolder;
3637
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitableExt};
38+
use std::collections::hash_map::Entry;
3739

3840
pub struct TypeFreshener<'a, 'tcx> {
3941
infcx: &'a InferCtxt<'tcx>,
4042
ty_freshen_count: u32,
4143
const_freshen_count: u32,
42-
ty_freshen_key_vec: Vec<ty::InferTy>,
43-
ty_freshen_value_vec: Vec<Ty<'tcx>>,
44-
const_freshen_key_vec: Vec<ty::InferConst>,
45-
const_freshen_value_vec: Vec<ty::Const<'tcx>>,
44+
ty_freshen_map: FxHashMap<ty::InferTy, Ty<'tcx>>,
45+
const_freshen_map: FxHashMap<ty::InferConst, ty::Const<'tcx>>,
4646
}
4747

4848
impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
@@ -51,10 +51,8 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
5151
infcx,
5252
ty_freshen_count: 0,
5353
const_freshen_count: 0,
54-
ty_freshen_key_vec: Vec::new(),
55-
ty_freshen_value_vec: Vec::new(),
56-
const_freshen_key_vec: Vec::new(),
57-
const_freshen_value_vec: Vec::new(),
54+
ty_freshen_map: Default::default(),
55+
const_freshen_map: Default::default(),
5856
}
5957
}
6058

@@ -66,15 +64,15 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
6664
return ty.fold_with(self);
6765
}
6866

69-
if let Some(idx) = self.ty_freshen_key_vec.iter().position(|infty| *infty == key) {
70-
unsafe { *self.ty_freshen_value_vec.get_unchecked(idx) }
71-
} else {
72-
let index = self.ty_freshen_count;
73-
self.ty_freshen_count += 1;
74-
let t = mk_fresh(index);
75-
self.ty_freshen_key_vec.push(key);
76-
self.ty_freshen_value_vec.push(t);
77-
t
67+
match self.ty_freshen_map.entry(key) {
68+
Entry::Occupied(entry) => *entry.get(),
69+
Entry::Vacant(entry) => {
70+
let index = self.ty_freshen_count;
71+
self.ty_freshen_count += 1;
72+
let t = mk_fresh(index);
73+
entry.insert(t);
74+
t
75+
}
7876
}
7977
}
8078

@@ -92,15 +90,15 @@ impl<'a, 'tcx> TypeFreshener<'a, 'tcx> {
9290
return ct.fold_with(self);
9391
}
9492

95-
if let Some(idx) = self.const_freshen_key_vec.iter().position(|infty| *infty == key) {
96-
unsafe { *self.const_freshen_value_vec.get_unchecked(idx) }
97-
} else {
98-
let index: u32 = self.const_freshen_count;
99-
self.const_freshen_count += 1;
100-
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index), ty);
101-
self.const_freshen_key_vec.push(key);
102-
self.const_freshen_value_vec.push(ct);
103-
ct
93+
match self.const_freshen_map.entry(key) {
94+
Entry::Occupied(entry) => *entry.get(),
95+
Entry::Vacant(entry) => {
96+
let index = self.const_freshen_count;
97+
self.const_freshen_count += 1;
98+
let ct = ty::Const::new_infer(self.infcx.tcx, freshener(index), ty);
99+
entry.insert(ct);
100+
ct
101+
}
104102
}
105103
}
106104
}

0 commit comments

Comments
 (0)