Skip to content

Commit cc26e4b

Browse files
committed
Add a provider method to register a conflict
1 parent a1d4f52 commit cc26e4b

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

src/internal/core.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<DP: DependencyProvider> State<DP> {
9797
&mut self,
9898
package_id: PackageId,
9999
package_store: &PackageArena<DP::P>,
100-
dependency_provider: &DP,
100+
dependency_provider: &mut DP,
101101
) -> Result<(), DerivationTree<DP::M>> {
102102
self.unit_propagation_buffer.clear();
103103
self.unit_propagation_buffer.push(package_id);
@@ -147,6 +147,12 @@ impl<DP: DependencyProvider> State<DP> {
147147
}
148148
}
149149
if let Some(incompat_id) = conflict_id {
150+
dependency_provider.register_conflict(
151+
self.incompatibility_store[incompat_id]
152+
.iter()
153+
.map(|(pid, _)| pid),
154+
package_store,
155+
);
150156
let (package_almost, root_cause) = self
151157
.conflict_resolution(incompat_id, package_store, dependency_provider)
152158
.map_err(|terminal_incompat_id| {

src/provider.rs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<V: Debug + Display + Clone + Ord> VersionRanges for Ranges<V> {
6969
pub struct OfflineDependencyProvider<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> {
7070
#[allow(clippy::type_complexity)]
7171
dependencies: Map<P, Vec<(R::V, Map<P, R>)>>,
72+
conflicts: Map<P, u64>,
7273
}
7374

7475
#[cfg(feature = "serde")]
@@ -112,6 +113,7 @@ where
112113
.into_iter()
113114
.map(|(p, versions)| (p, versions.into_iter().collect()))
114115
.collect(),
116+
conflicts: Map::default(),
115117
})
116118
}
117119
}
@@ -121,6 +123,7 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> OfflineDependency
121123
pub fn new() -> Self {
122124
Self {
123125
dependencies: Map::default(),
126+
conflicts: Map::default(),
124127
}
125128
}
126129

@@ -255,9 +258,20 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> DependencyProvide
255258
&mut self,
256259
package_id: PackageId,
257260
set: VersionSet,
258-
_: &PackageArena<Self::P>,
261+
package_store: &PackageArena<Self::P>,
259262
) -> Self::Priority {
260-
Reverse(((set.count() as u64) << 32) + package_id.get() as u64)
263+
let version_count = set.count();
264+
if version_count == 0 {
265+
return Reverse(0);
266+
}
267+
let pkg = match package_store.pkg(package_id).unwrap() {
268+
PackageVersionWrapper::Pkg(p) => p.pkg(),
269+
PackageVersionWrapper::VirtualPkg(p) => p.pkg(),
270+
PackageVersionWrapper::VirtualDep(p) => p.pkg(),
271+
};
272+
let conflict_count = self.conflicts.get(pkg).copied().unwrap_or_default();
273+
274+
Reverse(((u32::MAX as u64).saturating_sub(conflict_count) << 6) + version_count as u64)
261275
}
262276

263277
fn get_dependencies(
@@ -398,4 +412,19 @@ impl<P: Debug + Display + Clone + Eq + Hash, R: VersionRanges> DependencyProvide
398412
}
399413
}
400414
}
415+
416+
fn register_conflict(
417+
&mut self,
418+
package_ids: impl Iterator<Item = PackageId>,
419+
package_store: &PackageArena<Self::P>,
420+
) {
421+
for package_id in package_ids {
422+
let pkg = match package_store.pkg(package_id).unwrap() {
423+
PackageVersionWrapper::Pkg(p) => p.pkg(),
424+
PackageVersionWrapper::VirtualPkg(p) => p.pkg(),
425+
PackageVersionWrapper::VirtualDep(p) => p.pkg(),
426+
};
427+
*self.conflicts.entry(pkg.clone()).or_default() += 1;
428+
}
429+
}
401430
}

src/solver.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,14 @@ pub trait DependencyProvider {
312312
package: &'a Self::P,
313313
version_set: VersionSet,
314314
) -> impl Display + 'a;
315+
316+
/// Register a conflict for the given packages.
317+
fn register_conflict(
318+
&mut self,
319+
package_ids: impl Iterator<Item = PackageId>,
320+
package_store: &PackageArena<Self::P>,
321+
) {
322+
let _ = package_ids;
323+
let _ = package_store;
324+
}
315325
}

0 commit comments

Comments
 (0)