Skip to content

Commit 07dd760

Browse files
committed
refactor: make Kind even smaller
1 parent 7ed9435 commit 07dd760

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/internal/core.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ impl<P: Package, V: Version> State<P, V> {
212212

213213
fn build_derivation_tree(&self, incompat: IncompId<P, V>) -> DerivationTree<P, V> {
214214
let shared_ids = self.find_shared_ids(incompat);
215-
Incompatibility::build_derivation_tree(incompat, &shared_ids, &self.incompatibility_store)
215+
Incompatibility::build_derivation_tree(
216+
incompat,
217+
&shared_ids,
218+
&self.incompatibility_store,
219+
&self.root_package,
220+
&self.root_version,
221+
)
216222
}
217223

218224
fn find_shared_ids(&self, incompat: IncompId<P, V>) -> Set<IncompId<P, V>> {

src/internal/incompatibility.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub type IncompId<P, V> = Id<Incompatibility<P, V>>;
4141
#[derive(Debug, Clone)]
4242
enum Kind<P: Package, V: Version> {
4343
/// Initial incompatibility aiming at picking the root package for the first decision.
44-
NotRoot(P, V),
44+
NotRoot,
4545
/// There are no versions in the given range for this package.
4646
NoVersions,
4747
/// Dependencies of the package are unavailable for versions in that range.
@@ -76,11 +76,8 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
7676
/// Create the initial "not Root" incompatibility.
7777
pub fn not_root(package: P, version: V) -> Self {
7878
Self {
79-
package_terms: SmallMap::One([(
80-
package.clone(),
81-
Term::Negative(Range::exact(version.clone())),
82-
)]),
83-
kind: Kind::NotRoot(package, version),
79+
package_terms: SmallMap::One([(package, Term::Negative(Range::exact(version)))]),
80+
kind: Kind::NotRoot,
8481
}
8582
}
8683

@@ -238,11 +235,25 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
238235
self_id: Id<Self>,
239236
shared_ids: &Set<Id<Self>>,
240237
store: &Arena<Self>,
238+
root_package: &P,
239+
root_version: &V,
241240
) -> DerivationTree<P, V> {
242241
match &store[self_id].kind {
243242
Kind::DerivedFrom(id1, id2) => {
244-
let cause1 = Self::build_derivation_tree(*id1, shared_ids, store);
245-
let cause2 = Self::build_derivation_tree(*id2, shared_ids, store);
243+
let cause1 = Self::build_derivation_tree(
244+
*id1,
245+
shared_ids,
246+
store,
247+
root_package,
248+
root_version,
249+
);
250+
let cause2 = Self::build_derivation_tree(
251+
*id2,
252+
shared_ids,
253+
store,
254+
root_package,
255+
root_version,
256+
);
246257
let derived = Derived {
247258
terms: store[self_id].package_terms.as_map(),
248259
shared_id: shared_ids.get(&self_id).map(|id| id.into_raw()),
@@ -251,9 +262,10 @@ impl<P: Package, V: Version> Incompatibility<P, V> {
251262
};
252263
DerivationTree::Derived(derived)
253264
}
254-
Kind::NotRoot(package, version) => {
255-
DerivationTree::External(External::NotRoot(package.clone(), version.clone()))
256-
}
265+
Kind::NotRoot => DerivationTree::External(External::NotRoot(
266+
root_package.clone(),
267+
root_version.clone(),
268+
)),
257269
Kind::NoVersions => match &store[self_id].package_terms {
258270
SmallMap::One([(package, Term::Positive(range))]) => {
259271
DerivationTree::External(External::NoVersions(package.clone(), range.clone()))

0 commit comments

Comments
 (0)