Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: constraint formatting #80

Merged
merged 1 commit into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -39,11 +39,12 @@ event-listener = "5.3"
indexmap = "2"
tokio = { version = "1.37", features = ["rt"], optional = true }
async-std = { version = "1.12", default-features = false, features = ["alloc", "default"], optional = true }
version-ranges = { version = "0.1.0", optional = true }

[dev-dependencies]
insta = "1.39.0"
proptest = "1.2"
tracing-test = { version = "0.2.4", features = ["no-env-filter"] }
tokio = { version = "1.35.1", features = ["time", "rt"] }
resolvo = { path = ".", features = ["tokio"] }
resolvo = { path = ".", features = ["tokio", "version-ranges"] }
serde_json = "1.0"
13 changes: 9 additions & 4 deletions src/conflict.rs
Original file line number Diff line number Diff line change
@@ -11,9 +11,11 @@ use petgraph::{
Direction,
};

use crate::internal::arena::ArenaId;
use crate::{
internal::id::{ClauseId, InternalSolvableId, SolvableId, StringId, VersionSetId},
internal::{
arena::ArenaId,
id::{ClauseId, InternalSolvableId, SolvableId, StringId, VersionSetId},
},
runtime::AsyncRuntime,
solver::{clause::Clause, Solver},
DependencyProvider, Interner, Requirement,
@@ -908,7 +910,7 @@ impl<'i, I: Interner> DisplayUnsat<'i, I> {
let indent = indenter.get_indent();
writeln!(
f,
"{indent}{name} {version_set} , which conflicts with any installable versions previously reported",
"{indent}{name} {version_set}, which conflicts with any installable versions previously reported",
)?;
}
} else {
@@ -985,7 +987,10 @@ impl<'i, I: Interner> fmt::Display for DisplayUnsat<'i, I> {
&ConflictCause::Constrains(version_set_id) => {
writeln!(
f,
"{indent}constraint '{version_set}' cannot be fulfilled",
"{indent}the constraint {name} {version_set} cannot be fulfilled",
name = self
.interner
.display_name(self.interner.version_set_name(version_set_id)),
version_set = self.interner.display_version_set(version_set_id),
)?;
}
6 changes: 1 addition & 5 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
@@ -370,11 +370,7 @@ impl<'s> SnapshotProvider<'s> {

self.additional_version_sets.push(VersionSet {
name,
display: if matcher == "*" {
"*".to_string()
} else {
format!("{} {}", package.name, matcher)
},
display: matcher.to_string(),
matching_candidates,
});

5 changes: 3 additions & 2 deletions src/solver/cache.rs
Original file line number Diff line number Diff line change
@@ -242,8 +242,9 @@ impl<D: DependencyProvider> SolverCache<D> {
}
}

/// Returns the candidates fulfilling the [`Requirement`] sorted from highest to lowest
/// within each version set comprising the [`Requirement`].
/// Returns the candidates fulfilling the [`Requirement`] sorted from
/// highest to lowest within each version set comprising the
/// [`Requirement`].
///
/// If the provider has requested the solving process to be cancelled, the
/// cancellation value will be returned as an `Err(...)`.
8 changes: 4 additions & 4 deletions src/solver/mod.rs
Original file line number Diff line number Diff line change
@@ -958,10 +958,6 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
self.negative_assertions
.append(&mut output.negative_assertions);

if let Some(&clause_id) = output.conflicting_clauses.first() {
return Err(clause_id);
}

if let Some(max_name_idx) = output
.new_names
.into_iter()
@@ -973,6 +969,10 @@ impl<D: DependencyProvider, RT: AsyncRuntime> Solver<D, RT> {
}
}

if let Some(&clause_id) = output.conflicting_clauses.first() {
return Err(clause_id);
}

Ok(())
}

2 changes: 0 additions & 2 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,5 @@
//! implement a custom dependency provider.

mod pool;
mod range;

pub use pool::{PackageName, Pool, VersionSet};
pub use range::Range;
12 changes: 9 additions & 3 deletions src/utils/pool.rs
Original file line number Diff line number Diff line change
@@ -187,10 +187,11 @@ impl<VS: VersionSet, N: PackageName> Pool<VS, N> {
self.version_sets[id].0
}

/// Interns a union of two or more version sets and returns its [`VersionSetUnionId`].
/// Interns a union of two or more version sets and returns its
/// [`VersionSetUnionId`].
///
/// Version set unions are *not* deduplicated, and a unique id is returned on every
/// invocation.
/// Version set unions are *not* deduplicated, and a unique id is returned
/// on every invocation.
pub fn intern_version_set_union(
&self,
first: VersionSetId,
@@ -261,3 +262,8 @@ pub trait VersionSet: Clone + Eq + Hash {
/// The element type that is included in the set.
type V: Display;
}

#[cfg(feature = "version-ranges")]
impl<R: Clone + Eq + Hash + Display> VersionSet for version_ranges::Ranges<R> {
type V = R;
}
522 changes: 0 additions & 522 deletions src/utils/range.rs

This file was deleted.

4 changes: 2 additions & 2 deletions tests/snapshots/solver__root_constraints.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
source: tests/solver.rs
expression: "solve_for_snapshot(snapshot_provider, &[union_req], &[icons_req])"
expression: "solve_for_snapshot(snapshot_provider, &[union_req], &[union_constraint])"
---
The following packages are incompatible
└─ union * can be installed with any of the following options:
└─ union union=1
├─ constraint 'union 5' cannot be fulfilled
├─ the constraint union 5 cannot be fulfilled
3 changes: 1 addition & 2 deletions tests/snapshots/solver__unsat_constrains.snap
Original file line number Diff line number Diff line change
@@ -9,5 +9,4 @@ The following packages are incompatible
│ └─ b 50
└─ c * cannot be installed because there are no viable options:
└─ c 8 | 10 would constrain
└─ b >=0, <50 , which conflicts with any installable versions previously reported

└─ b >=0, <50, which conflicts with any installable versions previously reported
5 changes: 2 additions & 3 deletions tests/snapshots/solver__unsat_constrains_2.snap
Original file line number Diff line number Diff line change
@@ -9,9 +9,8 @@ The following packages are incompatible
├─ b 2 would require
│ └─ c >=2, <3, which cannot be installed because there are no viable options:
│ └─ c 2 would constrain
│ └─ a >=3, <4 , which conflicts with any installable versions previously reported
│ └─ a >=3, <4, which conflicts with any installable versions previously reported
└─ b 1 would require
└─ c >=1, <2, which cannot be installed because there are no viable options:
└─ c 1 would constrain
└─ a >=3, <4 , which conflicts with any installable versions previously reported

└─ a >=3, <4, which conflicts with any installable versions previously reported
17 changes: 9 additions & 8 deletions tests/solver.rs
Original file line number Diff line number Diff line change
@@ -21,12 +21,13 @@ use insta::assert_snapshot;
use itertools::Itertools;
use resolvo::{
snapshot::{DependencySnapshot, SnapshotProvider},
utils::{Pool, Range},
utils::Pool,
Candidates, Dependencies, DependencyProvider, Interner, KnownDependencies, NameId, Problem,
Requirement, SolvableId, Solver, SolverCache, StringId, UnsolvableOrCancelled, VersionSetId,
VersionSetUnionId,
};
use tracing_test::traced_test;
use version_ranges::Ranges;

// Let's define our own packaging version system and dependency specification.
// This is a very simple version system, where a package is identified by a name
@@ -39,7 +40,7 @@ use tracing_test::traced_test;
// means the range from 0..1 (excluding the end)
//
// Lets call the tuples of (Name, Version) a `Pack` and the tuples of (Name,
// Range<u32>) a `Spec`
// Ranges<u32>) a `Spec`
//
// We also need to create a custom provider that tells us how to sort the
// candidates. This is unique to each packaging ecosystem. Let's call our
@@ -111,11 +112,11 @@ impl FromStr for Pack {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
struct Spec {
name: String,
versions: Range<Pack>,
versions: Ranges<Pack>,
}

impl Spec {
pub fn new(name: String, versions: Range<Pack>) -> Self {
pub fn new(name: String, versions: Ranges<Pack>) -> Self {
Self { name, versions }
}

@@ -138,7 +139,7 @@ impl FromStr for Spec {
.expect("spec does not have a name")
.to_string();

fn version_range(s: Option<&&str>) -> Range<Pack> {
fn version_range(s: Option<&&str>) -> Ranges<Pack> {
if let Some(s) = s {
let (start, end) = s
.split_once("..")
@@ -149,9 +150,9 @@ impl FromStr for Spec {
.transpose()
.unwrap()
.unwrap_or(start.offset(1));
Range::between(start, end)
Ranges::between(start, end)
} else {
Range::full()
Ranges::full()
}
}

@@ -164,7 +165,7 @@ impl FromStr for Spec {
/// This provides sorting functionality for our `BundleBox` packaging system
#[derive(Default)]
struct BundleBoxProvider {
pool: Pool<Range<Pack>>,
pool: Pool<Ranges<Pack>>,
packages: IndexMap<String, IndexMap<Pack, BundleBoxPackageDependencies>>,
favored: HashMap<String, Pack>,
locked: HashMap<String, Pack>,