Skip to content

Commit

Permalink
Layer on our changes
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 9, 2023
1 parent c4e1081 commit 6bb6923
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 19 deletions.
9 changes: 4 additions & 5 deletions crates/puffin-resolver/src/pubgrub/dependencies.rs
@@ -1,6 +1,6 @@
use fxhash::FxHashMap;
use itertools::Itertools;
use pubgrub::range::Range;
use pubgrub::type_aliases::DependencyConstraints;
use tracing::warn;

use pep508_rs::{MarkerEnvironment, Requirement, VersionOrUrl};
Expand All @@ -12,7 +12,7 @@ use crate::pubgrub::{PubGrubPackage, PubGrubVersion};
use crate::ResolveError;

#[derive(Debug)]
pub struct PubGrubDependencies(DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>>);
pub struct PubGrubDependencies(FxHashMap<PubGrubPackage, Range<PubGrubVersion>>);

impl PubGrubDependencies {
/// Generate a set of `PubGrub` dependencies from a set of requirements.
Expand All @@ -23,8 +23,7 @@ impl PubGrubDependencies {
source: Option<&'a PackageName>,
env: &'a MarkerEnvironment,
) -> Result<Self, ResolveError> {
let mut dependencies =
DependencyConstraints::<PubGrubPackage, Range<PubGrubVersion>>::default();
let mut dependencies = FxHashMap::<PubGrubPackage, Range<PubGrubVersion>>::default();

// Iterate over all declared requirements.
for requirement in requirements {
Expand Down Expand Up @@ -138,7 +137,7 @@ impl PubGrubDependencies {
}

/// Convert a [`PubGrubDependencies`] to a [`DependencyConstraints`].
impl From<PubGrubDependencies> for DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>> {
impl From<PubGrubDependencies> for FxHashMap<PubGrubPackage, Range<PubGrubVersion>> {
fn from(dependencies: PubGrubDependencies) -> Self {
dependencies.0
}
Expand Down
12 changes: 8 additions & 4 deletions crates/puffin-resolver/src/resolver.rs
Expand Up @@ -11,7 +11,6 @@ use fxhash::{FxHashMap, FxHashSet};
use pubgrub::error::PubGrubError;
use pubgrub::range::Range;
use pubgrub::solver::{Incompatibility, State};
use pubgrub::type_aliases::DependencyConstraints;
use tokio::select;
use tokio::sync::Mutex;
use tracing::{debug, error, trace};
Expand Down Expand Up @@ -236,7 +235,12 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
));
continue;
}
Dependencies::Known(constraints) if constraints.contains_key(package) => {
Dependencies::Known(constraints)
if constraints
.clone()
.into_iter()
.any(|(dependency, _)| &dependency == package) =>
{
return Err(PubGrubError::SelfDependency {
package: package.clone(),
version: version.clone(),
Expand All @@ -250,7 +254,7 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> {
let dep_incompats = state.add_incompatibility_from_dependencies(
package.clone(),
version.clone(),
&dependencies,
dependencies,
);

state.partial_solution.add_version(
Expand Down Expand Up @@ -977,5 +981,5 @@ enum Dependencies {
/// Package dependencies are unavailable.
Unknown,
/// Container for all available package versions.
Known(DependencyConstraints<PubGrubPackage, Range<PubGrubVersion>>),
Known(FxHashMap<PubGrubPackage, Range<PubGrubVersion>>),
}
2 changes: 1 addition & 1 deletion rust-toolchain.toml
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.73"
channel = "nightly"
2 changes: 1 addition & 1 deletion vendor/pubgrub/src/internal/core.rs
Expand Up @@ -24,7 +24,7 @@ pub struct State<P: Package, VS: VersionSet, Priority: Ord + Clone> {
root_package: P,
root_version: VS::V,

incompatibilities: Map<P, Vec<IncompId<P, VS>>>,
pub incompatibilities: Map<P, Vec<IncompId<P, VS>>>,

/// Store the ids of incompatibilities that are already contradicted
/// and will stay that way until the next conflict and backtrack is operated.
Expand Down
4 changes: 2 additions & 2 deletions vendor/pubgrub/src/internal/incompatibility.rs
Expand Up @@ -31,14 +31,14 @@ use crate::version_set::VersionSet;
#[derive(Debug, Clone)]
pub struct Incompatibility<P: Package, VS: VersionSet> {
package_terms: SmallMap<P, Term<VS>>,
kind: Kind<P, VS>,
pub kind: Kind<P, VS>,
}

/// Type alias of unique identifiers for incompatibilities.
pub type IncompId<P, VS> = Id<Incompatibility<P, VS>>;

#[derive(Debug, Clone)]
enum Kind<P: Package, VS: VersionSet> {
pub enum Kind<P: Package, VS: VersionSet> {
/// Initial incompatibility aiming at picking the root package for the first decision.
NotRoot(P, VS::V),
/// There are no versions in the given range for this package.
Expand Down
18 changes: 18 additions & 0 deletions vendor/pubgrub/src/internal/partial_solution.rs
Expand Up @@ -252,6 +252,24 @@ impl<P: Package, VS: VersionSet, Priority: Ord + Clone> PartialSolution<P, VS, P
}
}

pub fn prioritized_packages(&self) -> impl Iterator<Item = (&P, &VS)> {
let check_all = self.changed_this_decision_level
== self.current_decision_level.0.saturating_sub(1) as usize;
let current_decision_level = self.current_decision_level;
self.package_assignments
.get_range(self.changed_this_decision_level..)
.unwrap()
.iter()
.filter(move |(_, pa)| {
// We only actually need to update the package if its Been changed
// since the last time we called prioritize.
// Which means it's highest decision level is the current decision level,
// or if we backtracked in the mean time.
check_all || pa.highest_decision_level == current_decision_level
})
.filter_map(|(p, pa)| pa.assignments_intersection.potential_package_filter(p))
}

pub fn pick_highest_priority_pkg(
&mut self,
prioritizer: impl Fn(&P, &VS) -> Priority,
Expand Down
3 changes: 1 addition & 2 deletions vendor/pubgrub/src/lib.rs
Expand Up @@ -219,8 +219,7 @@
//! with a cache, you may want to know that some versions
//! do not exist in your cache.

#![allow(clippy::rc_buffer)]
#![warn(missing_docs)]
#![allow(clippy::all, unreachable_pub)]

pub mod error;
pub mod package;
Expand Down
2 changes: 1 addition & 1 deletion vendor/pubgrub/src/range.rs
Expand Up @@ -373,7 +373,7 @@ impl<V: Display + Eq> Display for Range<V> {
(Included(v), Unbounded) => write!(f, ">={v}")?,
(Included(v), Included(b)) => {
if v == b {
write!(f, "{v}")?
write!(f, "=={v}")?
} else {
write!(f, ">={v}, <={b}")?
}
Expand Down
4 changes: 2 additions & 2 deletions vendor/pubgrub/src/solver.rs
Expand Up @@ -73,8 +73,8 @@ use std::collections::{BTreeMap, BTreeSet as Set};
use std::error::Error;

use crate::error::PubGrubError;
use crate::internal::core::State;
use crate::internal::incompatibility::Incompatibility;
pub use crate::internal::core::State;
pub use crate::internal::incompatibility::{Incompatibility, Kind};
use crate::package::Package;
use crate::type_aliases::{Map, SelectedDependencies};
use crate::version_set::VersionSet;
Expand Down
2 changes: 1 addition & 1 deletion vendor/pubgrub/src/term.rs
Expand Up @@ -64,7 +64,7 @@ impl<VS: VersionSet> Term<VS> {

/// Unwrap the set contained in a positive term.
/// Will panic if used on a negative set.
pub(crate) fn unwrap_positive(&self) -> &VS {
pub fn unwrap_positive(&self) -> &VS {
match self {
Self::Positive(set) => set,
_ => panic!("Negative term cannot unwrap positive set"),
Expand Down

0 comments on commit 6bb6923

Please sign in to comment.