Skip to content

Commit

Permalink
add version match options
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv committed Jan 11, 2024
1 parent 49e7411 commit a8e9b75
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ pub trait VersionSet: Debug + Display + Clone + Eq + Hash {
/// The element type that is included in the set.
type V: Display + Ord;

/// Options for matching versions.
type O;

/// Evaluate membership of a version in this set.
fn contains(&self, v: &Self::V) -> bool;
fn contains(&self, v: &Self::V, options: &Self::O) -> bool;
}

/// Defines implementation specific behavior for the solver and a way for the solver to access the
Expand All @@ -75,6 +78,9 @@ pub trait DependencyProvider<VS: VersionSet, N: PackageName = String>: Sized {

/// Returns the dependencies for the specified solvable.
fn get_dependencies(&self, solvable: SolvableId) -> Dependencies;

/// Returns the options that should be used when matching versions.
fn version_match_options(&self) -> &VS::O;
}

/// A list of candidate solvables for a specific package. This is returned from
Expand Down
3 changes: 2 additions & 1 deletion src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,9 @@ impl<V: Ord + Clone> Range<V> {

impl<T: Debug + Display + Clone + Eq + Ord + Hash> VersionSet for Range<T> {
type V = T;
type O = ();

fn contains(&self, v: &Self::V) -> bool {
fn contains(&self, v: &Self::V, _o: &Self::O) -> bool {
Range::contains(self, v)
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/solver/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ impl<VS: VersionSet, N: PackageName, D: DependencyProvider<VS, N>> SolverCache<V
pub fn new(provider: D) -> Self {
Self {
provider,

candidates: Default::default(),
package_name_to_candidates: Default::default(),
version_set_candidates: Default::default(),
Expand Down Expand Up @@ -123,7 +122,7 @@ impl<VS: VersionSet, N: PackageName, D: DependencyProvider<VS, N>> SolverCache<V
.copied()
.filter(|&p| {
let version = self.pool().resolve_internal_solvable(p).solvable().inner();
version_set.contains(version)
version_set.contains(version, self.provider.version_match_options())
})
.collect();

Expand Down Expand Up @@ -151,7 +150,7 @@ impl<VS: VersionSet, N: PackageName, D: DependencyProvider<VS, N>> SolverCache<V
.copied()
.filter(|&p| {
let version = self.pool().resolve_internal_solvable(p).solvable().inner();
!version_set.contains(version)
!version_set.contains(version, self.provider.version_match_options())
})
.collect();

Expand All @@ -165,7 +164,7 @@ impl<VS: VersionSet, N: PackageName, D: DependencyProvider<VS, N>> SolverCache<V
/// [`Self::get_or_cache_candidates`] sorted from highest to lowest.
pub fn get_or_cache_sorted_candidates(&self, version_set_id: VersionSetId) -> &[SolvableId] {
match self.version_set_to_sorted_candidates.get(&version_set_id) {
Some(canidates) => canidates,
Some(candidates) => candidates,
None => {
let package_name = self.pool().resolve_version_set_package_name(version_set_id);
let matching_candidates = self.get_or_cache_matching_candidates(version_set_id);
Expand Down
4 changes: 4 additions & 0 deletions tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ impl DependencyProvider<Range<Pack>> for BundleBoxProvider {

result
}

fn version_match_options(&self) -> &<Range<Pack> as VersionSet>::O {
&()
}
}

/// Create a string from a [`Transaction`]
Expand Down

0 comments on commit a8e9b75

Please sign in to comment.