Skip to content

Commit 571c75b

Browse files
committed
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.
1 parent 139c412 commit 571c75b

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/internal/core.rs

+20
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ impl<DP: DependencyProvider> State<DP> {
6666
}
6767
}
6868

69+
/// Add the dependencies for the current version of the current package as incompatibilities.
70+
pub fn add_package_version_dependencies(
71+
&mut self,
72+
package: DP::P,
73+
version: DP::V,
74+
dependencies: impl IntoIterator<Item = (DP::P, DP::VS)>,
75+
) {
76+
let dep_incompats = self.add_incompatibility_from_dependencies(
77+
package.clone(),
78+
version.clone(),
79+
dependencies,
80+
);
81+
self.partial_solution.add_package_version_incompatibilities(
82+
package.clone(),
83+
version.clone(),
84+
dep_incompats,
85+
&self.incompatibility_store,
86+
)
87+
}
88+
6989
/// Add an incompatibility to the state.
7090
pub fn add_incompatibility(&mut self, incompat: Incompatibility<DP::P, DP::VS, DP::M>) {
7191
let id = self.incompatibility_store.alloc(incompat);

src/internal/partial_solution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
365365
/// In practice I think it can only produce a conflict if one of the dependencies
366366
/// (which are used to make the new incompatibilities)
367367
/// is already in the partial solution with an incompatible version.
368-
pub(crate) fn add_version(
368+
pub(crate) fn add_package_version_incompatibilities(
369369
&mut self,
370370
package: DP::P,
371371
version: DP::V,

src/solver.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,7 @@ pub fn resolve<DP: DependencyProvider>(
157157
};
158158

159159
// Add that package and version if the dependencies are not problematic.
160-
let dep_incompats =
161-
state.add_incompatibility_from_dependencies(p.clone(), v.clone(), dependencies);
162-
163-
state.partial_solution.add_version(
164-
p.clone(),
165-
v.clone(),
166-
dep_incompats,
167-
&state.incompatibility_store,
168-
);
160+
state.add_package_version_dependencies(p.clone(), v.clone(), dependencies);
169161
} else {
170162
// `dep_incompats` are already in `incompatibilities` so we know there are not satisfied
171163
// terms and can add the decision directly.

0 commit comments

Comments
 (0)