Skip to content

Commit 93db5bf

Browse files
committed
fix: use rustc-hash in the resolver
1 parent feaa75d commit 93db5bf

File tree

7 files changed

+31
-22
lines changed

7 files changed

+31
-22
lines changed

Cargo.lock

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ pulldown-cmark = { version = "0.11.0", default-features = false, features = ["ht
7979
rand = "0.8.5"
8080
regex = "1.10.5"
8181
rusqlite = { version = "0.32.0", features = ["bundled"] }
82+
rustc-hash = "2.0.0"
8283
rustfix = { version = "0.8.2", path = "crates/rustfix" }
8384
same-file = "1.0.6"
8485
security-framework = "2.11.1"
@@ -185,6 +186,7 @@ pathdiff.workspace = true
185186
rand.workspace = true
186187
regex.workspace = true
187188
rusqlite.workspace = true
189+
rustc-hash.workspace = true
188190
rustfix.workspace = true
189191
same-file.workspace = true
190192
semver.workspace = true

crates/resolver-tests/src/sat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ impl SatResolver {
352352

353353
let mut by_name: HashMap<InternedString, Vec<Summary>> = HashMap::new();
354354
for pkg in registry {
355-
by_name.entry(pkg.name()).or_default().push(pkg.clone())
355+
by_name.entry(pkg.name()).or_default().push(pkg.clone());
356356
}
357357

358358
let mut solver = varisat::Solver::new();

src/cargo/core/resolver/conflict_cache.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
use std::collections::{BTreeMap, HashMap, HashSet};
1+
use std::collections::{BTreeMap, HashMap};
22

3+
use rustc_hash::{FxHashMap, FxHashSet};
34
use tracing::trace;
45

56
use super::types::ConflictMap;
@@ -140,17 +141,17 @@ pub(super) struct ConflictCache {
140141
// as a global cache which we never delete from. Any entry in this map is
141142
// unconditionally true regardless of our resolution history of how we got
142143
// here.
143-
con_from_dep: HashMap<Dependency, ConflictStoreTrie>,
144+
con_from_dep: FxHashMap<Dependency, ConflictStoreTrie>,
144145
// `dep_from_pid` is an inverse-index of `con_from_dep`.
145146
// For every `PackageId` this lists the `Dependency`s that mention it in `dep_from_pid`.
146-
dep_from_pid: HashMap<PackageId, HashSet<Dependency>>,
147+
dep_from_pid: FxHashMap<PackageId, FxHashSet<Dependency>>,
147148
}
148149

149150
impl ConflictCache {
150151
pub fn new() -> ConflictCache {
151152
ConflictCache {
152-
con_from_dep: HashMap::new(),
153-
dep_from_pid: HashMap::new(),
153+
con_from_dep: HashMap::default(),
154+
dep_from_pid: HashMap::default(),
154155
}
155156
}
156157
pub fn find(
@@ -207,14 +208,11 @@ impl ConflictCache {
207208
);
208209

209210
for c in con.keys() {
210-
self.dep_from_pid
211-
.entry(*c)
212-
.or_insert_with(HashSet::new)
213-
.insert(dep.clone());
211+
self.dep_from_pid.entry(*c).or_default().insert(dep.clone());
214212
}
215213
}
216214

217-
pub fn dependencies_conflicting_with(&self, pid: PackageId) -> Option<&HashSet<Dependency>> {
215+
pub fn dependencies_conflicting_with(&self, pid: PackageId) -> Option<&FxHashSet<Dependency>> {
218216
self.dep_from_pid.get(&pid)
219217
}
220218
}

src/cargo/core/resolver/context.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ pub struct ResolverContext {
1919
pub age: ContextAge,
2020
pub activations: Activations,
2121
/// list the features that are activated for each package
22-
pub resolve_features: im_rc::HashMap<PackageId, FeaturesSet>,
22+
pub resolve_features: im_rc::HashMap<PackageId, FeaturesSet, rustc_hash::FxBuildHasher>,
2323
/// get the package that will be linking to a native library by its links attribute
24-
pub links: im_rc::HashMap<InternedString, PackageId>,
24+
pub links: im_rc::HashMap<InternedString, PackageId, rustc_hash::FxBuildHasher>,
2525

2626
/// a way to look up for a package in activations what packages required it
2727
/// and all of the exact deps that it fulfilled.
28-
pub parents: Graph<PackageId, im_rc::HashSet<Dependency>>,
28+
pub parents: Graph<PackageId, im_rc::HashSet<Dependency, rustc_hash::FxBuildHasher>>,
2929
}
3030

3131
/// When backtracking it can be useful to know how far back to go.
@@ -40,7 +40,9 @@ pub type ContextAge = usize;
4040
/// semver compatible version of each crate.
4141
/// This all so stores the `ContextAge`.
4242
pub type ActivationsKey = (InternedString, SourceId, SemverCompatibility);
43-
pub type Activations = im_rc::HashMap<ActivationsKey, (Summary, ContextAge)>;
43+
44+
pub type Activations =
45+
im_rc::HashMap<ActivationsKey, (Summary, ContextAge), rustc_hash::FxBuildHasher>;
4446

4547
/// A type that represents when cargo treats two Versions as compatible.
4648
/// Versions `a` and `b` are compatible if their left-most nonzero digit is the
@@ -74,10 +76,10 @@ impl ResolverContext {
7476
pub fn new() -> ResolverContext {
7577
ResolverContext {
7678
age: 0,
77-
resolve_features: im_rc::HashMap::new(),
78-
links: im_rc::HashMap::new(),
79+
resolve_features: im_rc::HashMap::default(),
80+
links: im_rc::HashMap::default(),
7981
parents: Graph::new(),
80-
activations: im_rc::HashMap::new(),
82+
activations: im_rc::HashMap::default(),
8183
}
8284
}
8385

src/cargo/core/resolver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ fn activate(
679679
Rc::make_mut(
680680
cx.resolve_features
681681
.entry(candidate.package_id())
682-
.or_insert_with(Rc::default),
682+
.or_default(),
683683
)
684684
.extend(used_features);
685685
}

src/cargo/util/graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
2222
.entry(node)
2323
.or_insert_with(im_rc::OrdMap::new)
2424
.entry(child)
25-
.or_insert_with(Default::default)
25+
.or_default()
2626
}
2727

2828
/// Returns the graph obtained by reversing all edges.

0 commit comments

Comments
 (0)