From 19c77268c0ad5f69d7e12126e0cfacfbba466481 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 | 20 ++++++++++++++++++++ src/internal/partial_solution.rs | 2 +- src/solver.rs | 10 +--------- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/internal/core.rs b/src/internal/core.rs index ac6d7757..c098d8b1 100644 --- a/src/internal/core.rs +++ b/src/internal/core.rs @@ -66,6 +66,26 @@ impl State { } } + /// Add the dependencies for the current version of the current package as incompatibilities. + pub fn add_package_version_dependencies( + &mut self, + package: DP::P, + version: DP::V, + dependencies: impl IntoIterator, + ) { + let dep_incompats = self.add_incompatibility_from_dependencies( + package.clone(), + 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 e4f3b742..ef2cb17e 100644 --- a/src/internal/partial_solution.rs +++ b/src/internal/partial_solution.rs @@ -365,7 +365,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: DP::P, version: DP::V, diff --git a/src/solver.rs b/src/solver.rs index 53cb524a..d2bc097e 100644 --- a/src/solver.rs +++ b/src/solver.rs @@ -157,15 +157,7 @@ pub fn resolve( }; // Add that package and version if the dependencies are not problematic. - let dep_incompats = - state.add_incompatibility_from_dependencies(p.clone(), v.clone(), dependencies); - - state.partial_solution.add_version( - p.clone(), - v.clone(), - 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.