Skip to content

Commit

Permalink
Add State::add_incompatibility_from_dependencies (#27)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
konstin committed Dec 13, 2024
1 parent 0210a99 commit e4284dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
17 changes: 17 additions & 0 deletions src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ impl<DP: DependencyProvider> State<DP> {
}
}

/// Add the dependencies for the current version of the current package as incompatibilities.
pub fn add_package_version_dependencies(
&mut self,
package: Id<DP::P>,
version: DP::V,
dependencies: impl IntoIterator<Item = (DP::P, DP::VS)>,
) {
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<DP::P, DP::VS, DP::M>) {
let id = self.incompatibility_store.alloc(incompat);
Expand Down
2 changes: 1 addition & 1 deletion src/internal/partial_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl<DP: DependencyProvider> PartialSolution<DP> {
/// 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<DP::P>,
version: DP::V,
Expand Down
7 changes: 1 addition & 6 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,7 @@ pub fn resolve<DP: DependencyProvider>(
};

// 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.
Expand Down

0 comments on commit e4284dd

Please sign in to comment.