Skip to content

Commit

Permalink
fix: use rustc-hash in the resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
x-hgg-x committed Oct 10, 2024
1 parent feaa75d commit 93db5bf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 22 deletions.
11 changes: 9 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pulldown-cmark = { version = "0.11.0", default-features = false, features = ["ht
rand = "0.8.5"
regex = "1.10.5"
rusqlite = { version = "0.32.0", features = ["bundled"] }
rustc-hash = "2.0.0"
rustfix = { version = "0.8.2", path = "crates/rustfix" }
same-file = "1.0.6"
security-framework = "2.11.1"
Expand Down Expand Up @@ -185,6 +186,7 @@ pathdiff.workspace = true
rand.workspace = true
regex.workspace = true
rusqlite.workspace = true
rustc-hash.workspace = true
rustfix.workspace = true
same-file.workspace = true
semver.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/resolver-tests/src/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ impl SatResolver {

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

let mut solver = varisat::Solver::new();
Expand Down
18 changes: 8 additions & 10 deletions src/cargo/core/resolver/conflict_cache.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::{BTreeMap, HashMap, HashSet};
use std::collections::{BTreeMap, HashMap};

use rustc_hash::{FxHashMap, FxHashSet};
use tracing::trace;

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

impl ConflictCache {
pub fn new() -> ConflictCache {
ConflictCache {
con_from_dep: HashMap::new(),
dep_from_pid: HashMap::new(),
con_from_dep: HashMap::default(),
dep_from_pid: HashMap::default(),
}
}
pub fn find(
Expand Down Expand Up @@ -207,14 +208,11 @@ impl ConflictCache {
);

for c in con.keys() {
self.dep_from_pid
.entry(*c)
.or_insert_with(HashSet::new)
.insert(dep.clone());
self.dep_from_pid.entry(*c).or_default().insert(dep.clone());
}
}

pub fn dependencies_conflicting_with(&self, pid: PackageId) -> Option<&HashSet<Dependency>> {
pub fn dependencies_conflicting_with(&self, pid: PackageId) -> Option<&FxHashSet<Dependency>> {
self.dep_from_pid.get(&pid)
}
}
16 changes: 9 additions & 7 deletions src/cargo/core/resolver/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ pub struct ResolverContext {
pub age: ContextAge,
pub activations: Activations,
/// list the features that are activated for each package
pub resolve_features: im_rc::HashMap<PackageId, FeaturesSet>,
pub resolve_features: im_rc::HashMap<PackageId, FeaturesSet, rustc_hash::FxBuildHasher>,
/// get the package that will be linking to a native library by its links attribute
pub links: im_rc::HashMap<InternedString, PackageId>,
pub links: im_rc::HashMap<InternedString, PackageId, rustc_hash::FxBuildHasher>,

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

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

pub type Activations =
im_rc::HashMap<ActivationsKey, (Summary, ContextAge), rustc_hash::FxBuildHasher>;

/// A type that represents when cargo treats two Versions as compatible.
/// Versions `a` and `b` are compatible if their left-most nonzero digit is the
Expand Down Expand Up @@ -74,10 +76,10 @@ impl ResolverContext {
pub fn new() -> ResolverContext {
ResolverContext {
age: 0,
resolve_features: im_rc::HashMap::new(),
links: im_rc::HashMap::new(),
resolve_features: im_rc::HashMap::default(),
links: im_rc::HashMap::default(),
parents: Graph::new(),
activations: im_rc::HashMap::new(),
activations: im_rc::HashMap::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn activate(
Rc::make_mut(
cx.resolve_features
.entry(candidate.package_id())
.or_insert_with(Rc::default),
.or_default(),
)
.extend(used_features);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/util/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<N: Eq + Ord + Clone, E: Default + Clone> Graph<N, E> {
.entry(node)
.or_insert_with(im_rc::OrdMap::new)
.entry(child)
.or_insert_with(Default::default)
.or_default()
}

/// Returns the graph obtained by reversing all edges.
Expand Down

0 comments on commit 93db5bf

Please sign in to comment.