Skip to content

Commit

Permalink
Add a provider method to register a conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
x-hgg-x committed Nov 28, 2024
1 parent a1d4f52 commit cc26e4b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/internal/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<DP: DependencyProvider> State<DP> {
&mut self,
package_id: PackageId,
package_store: &PackageArena<DP::P>,
dependency_provider: &DP,
dependency_provider: &mut DP,
) -> Result<(), DerivationTree<DP::M>> {
self.unit_propagation_buffer.clear();
self.unit_propagation_buffer.push(package_id);
Expand Down Expand Up @@ -147,6 +147,12 @@ impl<DP: DependencyProvider> State<DP> {
}
}
if let Some(incompat_id) = conflict_id {
dependency_provider.register_conflict(
self.incompatibility_store[incompat_id]
.iter()
.map(|(pid, _)| pid),
package_store,
);
let (package_almost, root_cause) = self
.conflict_resolution(incompat_id, package_store, dependency_provider)
.map_err(|terminal_incompat_id| {
Expand Down
33 changes: 31 additions & 2 deletions src/provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl<V: Debug + Display + Clone + Ord> VersionRanges for Ranges<V> {
pub struct OfflineDependencyProvider<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> {
#[allow(clippy::type_complexity)]
dependencies: Map<P, Vec<(R::V, Map<P, R>)>>,
conflicts: Map<P, u64>,
}

#[cfg(feature = "serde")]
Expand Down Expand Up @@ -112,6 +113,7 @@ where
.into_iter()
.map(|(p, versions)| (p, versions.into_iter().collect()))
.collect(),
conflicts: Map::default(),
})
}
}
Expand All @@ -121,6 +123,7 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> OfflineDependency
pub fn new() -> Self {
Self {
dependencies: Map::default(),
conflicts: Map::default(),
}
}

Expand Down Expand Up @@ -255,9 +258,20 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> DependencyProvide
&mut self,
package_id: PackageId,
set: VersionSet,
_: &PackageArena<Self::P>,
package_store: &PackageArena<Self::P>,
) -> Self::Priority {
Reverse(((set.count() as u64) << 32) + package_id.get() as u64)
let version_count = set.count();
if version_count == 0 {
return Reverse(0);
}
let pkg = match package_store.pkg(package_id).unwrap() {
PackageVersionWrapper::Pkg(p) => p.pkg(),
PackageVersionWrapper::VirtualPkg(p) => p.pkg(),
PackageVersionWrapper::VirtualDep(p) => p.pkg(),
};
let conflict_count = self.conflicts.get(pkg).copied().unwrap_or_default();

Reverse(((u32::MAX as u64).saturating_sub(conflict_count) << 6) + version_count as u64)
}

fn get_dependencies(
Expand Down Expand Up @@ -398,4 +412,19 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> DependencyProvide
}
}
}

fn register_conflict(
&mut self,
package_ids: impl Iterator<Item = PackageId>,
package_store: &PackageArena<Self::P>,
) {
for package_id in package_ids {
let pkg = match package_store.pkg(package_id).unwrap() {
PackageVersionWrapper::Pkg(p) => p.pkg(),
PackageVersionWrapper::VirtualPkg(p) => p.pkg(),
PackageVersionWrapper::VirtualDep(p) => p.pkg(),
};
*self.conflicts.entry(pkg.clone()).or_default() += 1;
}
}
}
10 changes: 10 additions & 0 deletions src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,14 @@ pub trait DependencyProvider {
package: &'a Self::P,
version_set: VersionSet,
) -> impl Display + 'a;

/// Register a conflict for the given packages.
fn register_conflict(
&mut self,
package_ids: impl Iterator<Item = PackageId>,
package_store: &PackageArena<Self::P>,
) {
let _ = package_ids;
let _ = package_store;
}
}

0 comments on commit cc26e4b

Please sign in to comment.