From e4284dd6ccc6fc94e6c6644d5504ab5db4d6038c Mon Sep 17 00:00:00 2001 From: konsti Date: Wed, 19 Jun 2024 12:55:23 +0200 Subject: [PATCH] Add `State::add_incompatibility_from_dependencies` (#27) This wrapper avoids accessing the `incompatibility_store` directly in uv code. Before: ```rust let dep_incompats = self.pubgrub.add_version( package.clone(), version.clone(), dependencies, ); self.pubgrub.partial_solution.add_version( package.clone(), version.clone(), dep_incompats, &self.pubgrub.incompatibility_store, ); ``` After: ```rust self.pubgrub.add_incompatibility_from_dependencies(package.clone(), version.clone(), dependencies); ``` `add_incompatibility_from_dependencies` is one of the main methods for the custom interface to pubgrub. --- src/internal/core.rs | 17 +++++++++++++++++ src/internal/partial_solution.rs | 2 +- src/solver.rs | 7 +------ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index 79f6fa9c..a476ec16 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -73,6 +73,23 @@ impl State { } } + /// Add the dependencies for the current version of the current package as incompatibilities. + pub fn add_package_version_dependencies( + &mut self, + package: Id, + version: DP::V, + dependencies: impl IntoIterator, + ) { + let dep_incompats = + self.add_incompatibility_from_dependencies(package, version.clone(), dependencies); + self.partial_solution.add_package_version_incompatibilities( + package.clone(), + version.clone(), + dep_incompats, + &self.incompatibility_store, + ) + } + /// Add an incompatibility to the state. pub fn add_incompatibility(&mut self, incompat: Incompatibility) { let id = self.incompatibility_store.alloc(incompat); diff --git a/src/internal/partial_solution.rs b/src/internal/partial_solution.rs index f1b3dde5..2c36e256 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -375,7 +375,7 @@ impl PartialSolution { /// In practice I think it can only produce a conflict if one of the dependencies /// (which are used to make the new incompatibilities) /// is already in the partial solution with an incompatible version. - pub(crate) fn add_version( + pub(crate) fn add_package_version_incompatibilities( &mut self, package: Id, version: DP::V, diff --git a/src/solver.rs b/src/solver.rs index a8aff4bf..29d475d2 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -171,12 +171,7 @@ pub fn resolve( }; // Add that package and version if the dependencies are not problematic. - let dep_incompats = - state.add_incompatibility_from_dependencies(p, v.clone(), dependencies); - - state - .partial_solution - .add_version(p, v, dep_incompats, &state.incompatibility_store); + state.add_package_version_dependencies(p.clone(), v.clone(), dependencies); } else { // `dep_incompats` are already in `incompatibilities` so we know there are not satisfied // terms and can add the decision directly.