diff --git a/crates/install-wheel-rs/src/linker.rs b/crates/install-wheel-rs/src/linker.rs index c3eed6ee3c83..645fc11ef65c 100644 --- a/crates/install-wheel-rs/src/linker.rs +++ b/crates/install-wheel-rs/src/linker.rs @@ -388,9 +388,7 @@ fn hardlink_wheel_files( } // Hardlink the file, unless it's the `RECORD` file, which we modify during installation. - if entry.path().ends_with("RECORD") { - fs::copy(entry.path(), &out_path)?; - } else if use_copy_fallback { + if entry.path().ends_with("RECORD") || use_copy_fallback { fs::copy(entry.path(), &out_path)?; } else { let hard_link_result = fs::hard_link(entry.path(), &out_path); diff --git a/crates/puffin-dev/src/main.rs b/crates/puffin-dev/src/main.rs index dafe745e842b..f36f841da12c 100644 --- a/crates/puffin-dev/src/main.rs +++ b/crates/puffin-dev/src/main.rs @@ -23,6 +23,7 @@ mod resolve_cli; mod resolve_many; mod wheel_metadata; +#[allow(clippy::enum_variant_names)] #[derive(Parser)] enum Cli { /// Build a source distribution into a wheel diff --git a/crates/puffin-resolver/src/pubgrub/dependencies.rs b/crates/puffin-resolver/src/pubgrub/dependencies.rs index f59247384958..25b2e7f329d6 100644 --- a/crates/puffin-resolver/src/pubgrub/dependencies.rs +++ b/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}; @@ -12,7 +12,7 @@ use crate::pubgrub::{PubGrubPackage, PubGrubVersion}; use crate::ResolveError; #[derive(Debug)] -pub struct PubGrubDependencies(DependencyConstraints>); +pub struct PubGrubDependencies(FxHashMap>); impl PubGrubDependencies { /// Generate a set of `PubGrub` dependencies from a set of requirements. @@ -23,8 +23,7 @@ impl PubGrubDependencies { source: Option<&'a PackageName>, env: &'a MarkerEnvironment, ) -> Result { - let mut dependencies = - DependencyConstraints::>::default(); + let mut dependencies = FxHashMap::>::default(); // Iterate over all declared requirements. for requirement in requirements { @@ -138,7 +137,7 @@ impl PubGrubDependencies { } /// Convert a [`PubGrubDependencies`] to a [`DependencyConstraints`]. -impl From for DependencyConstraints> { +impl From for FxHashMap> { fn from(dependencies: PubGrubDependencies) -> Self { dependencies.0 } diff --git a/crates/puffin-resolver/src/resolver.rs b/crates/puffin-resolver/src/resolver.rs index d1af6e55a43d..89fbb60268eb 100644 --- a/crates/puffin-resolver/src/resolver.rs +++ b/crates/puffin-resolver/src/resolver.rs @@ -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}; @@ -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(), @@ -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( @@ -977,5 +981,5 @@ enum Dependencies { /// Package dependencies are unavailable. Unknown, /// Container for all available package versions. - Known(DependencyConstraints>), + Known(FxHashMap>), } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 50fa4928b96f..5d56faf9ae08 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.73" +channel = "nightly" diff --git a/vendor/pubgrub/examples/caching_dependency_provider.rs b/vendor/pubgrub/examples/caching_dependency_provider.rs deleted file mode 100644 index 6ef8e893fd77..000000000000 --- a/vendor/pubgrub/examples/caching_dependency_provider.rs +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: MPL-2.0 - -use std::cell::RefCell; -use std::error::Error; - -use pubgrub::package::Package; -use pubgrub::range::Range; -use pubgrub::solver::{resolve, Dependencies, DependencyProvider, OfflineDependencyProvider}; -use pubgrub::version::NumberVersion; -use pubgrub::version_set::VersionSet; - -type NumVS = Range; - -// An example implementing caching dependency provider that will -// store queried dependencies in memory and check them before querying more from remote. -struct CachingDependencyProvider> { - remote_dependencies: DP, - cached_dependencies: RefCell>, -} - -impl> - CachingDependencyProvider -{ - pub fn new(remote_dependencies_provider: DP) -> Self { - CachingDependencyProvider { - remote_dependencies: remote_dependencies_provider, - cached_dependencies: RefCell::new(OfflineDependencyProvider::new()), - } - } -} - -impl> DependencyProvider - for CachingDependencyProvider -{ - // Caches dependencies if they were already queried - fn get_dependencies( - &self, - package: &P, - version: &VS::V, - ) -> Result, Box> { - let mut cache = self.cached_dependencies.borrow_mut(); - match cache.get_dependencies(package, version) { - Ok(Dependencies::Unknown) => { - let dependencies = self.remote_dependencies.get_dependencies(package, version); - match dependencies { - Ok(Dependencies::Known(dependencies)) => { - cache.add_dependencies( - package.clone(), - version.clone(), - dependencies.clone(), - ); - Ok(Dependencies::Known(dependencies)) - } - Ok(Dependencies::Unknown) => Ok(Dependencies::Unknown), - error @ Err(_) => error, - } - } - dependencies @ Ok(_) => dependencies, - error @ Err(_) => error, - } - } - - fn choose_version( - &self, - package: &P, - range: &VS, - ) -> Result, Box> { - self.remote_dependencies.choose_version(package, range) - } - - type Priority = DP::Priority; - - fn prioritize(&self, package: &P, range: &VS) -> Self::Priority { - self.remote_dependencies.prioritize(package, range) - } -} - -fn main() { - // Simulating remote provider locally. - let mut remote_dependencies_provider = OfflineDependencyProvider::<&str, NumVS>::new(); - - // Add dependencies as needed. Here only root package is added. - remote_dependencies_provider.add_dependencies("root", 1, Vec::new()); - - let caching_dependencies_provider = - CachingDependencyProvider::new(remote_dependencies_provider); - - let solution = resolve(&caching_dependencies_provider, "root", 1); - println!("Solution: {:?}", solution); -} diff --git a/vendor/pubgrub/src/internal/core.rs b/vendor/pubgrub/src/internal/core.rs index a4a23b341c1d..d768482b61f5 100644 --- a/vendor/pubgrub/src/internal/core.rs +++ b/vendor/pubgrub/src/internal/core.rs @@ -15,7 +15,7 @@ use crate::internal::partial_solution::{DecisionLevel, PartialSolution}; use crate::internal::small_vec::SmallVec; use crate::package::Package; use crate::report::DerivationTree; -use crate::type_aliases::{DependencyConstraints, Map}; +use crate::type_aliases::Map; use crate::version_set::VersionSet; /// Current state of the PubGrub algorithm. @@ -75,12 +75,12 @@ impl State { &mut self, package: P, version: VS::V, - deps: &DependencyConstraints, + deps: impl IntoIterator, ) -> std::ops::Range> { // Create incompatibilities and allocate them in the store. let new_incompats_id_range = self .incompatibility_store - .alloc_iter(deps.iter().map(|dep| { + .alloc_iter(deps.into_iter().map(|dep| { Incompatibility::from_dependency(package.clone(), version.clone(), dep) })); // Merge the newly created incompatibilities with the older ones. diff --git a/vendor/pubgrub/src/internal/incompatibility.rs b/vendor/pubgrub/src/internal/incompatibility.rs index 168c5218c1ab..03a4cf3ba988 100644 --- a/vendor/pubgrub/src/internal/incompatibility.rs +++ b/vendor/pubgrub/src/internal/incompatibility.rs @@ -105,11 +105,11 @@ impl Incompatibility { } /// Build an incompatibility from a given dependency. - pub fn from_dependency(package: P, version: VS::V, dep: (&P, &VS)) -> Self { + pub fn from_dependency(package: P, version: VS::V, dep: (P, VS)) -> Self { let set1 = VS::singleton(version); let (p2, set2) = dep; Self { - package_terms: if set2 == &VS::empty() { + package_terms: if set2 == VS::empty() { SmallMap::One([(package.clone(), Term::Positive(set1.clone()))]) } else { SmallMap::Two([ @@ -117,7 +117,7 @@ impl Incompatibility { (p2.clone(), Term::Negative(set2.clone())), ]) }, - kind: Kind::FromDependencyOf(package, set1, p2.clone(), set2.clone()), + kind: Kind::FromDependencyOf(package, set1, p2, set2), } } diff --git a/vendor/pubgrub/src/lib.rs b/vendor/pubgrub/src/lib.rs index 0150c52ab537..0a6c3369ac7e 100644 --- a/vendor/pubgrub/src/lib.rs +++ b/vendor/pubgrub/src/lib.rs @@ -102,8 +102,10 @@ //! &self, //! package: &String, //! version: &SemanticVersion, -//! ) -> Result, Box> { -//! unimplemented!() +//! ) -> Result + Clone>, Box> +//! { +//! unimplemented!(); +//! Ok(Dependencies::Known([])) //! } //! } //! ``` diff --git a/vendor/pubgrub/src/range.rs b/vendor/pubgrub/src/range.rs index 47e76e44f52b..a62413244c10 100644 --- a/vendor/pubgrub/src/range.rs +++ b/vendor/pubgrub/src/range.rs @@ -195,7 +195,7 @@ impl Range { .segments .last() .expect("if there is a first element, there must be a last element"); - (bound_as_ref(start), bound_as_ref(&end.1)) + (start.as_ref(), end.1.as_ref()) }) } @@ -264,15 +264,6 @@ impl Range { } } -/// Implementation of [`Bound::as_ref`] which is currently marked as unstable. -fn bound_as_ref(bound: &Bound) -> Bound<&V> { - match bound { - Included(v) => Included(v), - Excluded(v) => Excluded(v), - Unbounded => Unbounded, - } -} - fn valid_segment(start: &Bound, end: &Bound) -> bool { match (start, end) { (Included(s), Included(e)) => s <= e, @@ -307,7 +298,7 @@ impl Range { (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i <= e => Excluded(e), (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e < i => Included(i), - (s, Unbounded) | (Unbounded, s) => bound_as_ref(s), + (s, Unbounded) | (Unbounded, s) => s.as_ref(), _ => unreachable!(), } .cloned(); @@ -317,7 +308,7 @@ impl Range { (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if i >= e => Excluded(e), (Included(i), Excluded(e)) | (Excluded(e), Included(i)) if e > i => Included(i), - (s, Unbounded) | (Unbounded, s) => bound_as_ref(s), + (s, Unbounded) | (Unbounded, s) => s.as_ref(), _ => unreachable!(), } .cloned(); @@ -373,7 +364,7 @@ impl Display for Range { } else { for (idx, segment) in self.segments.iter().enumerate() { if idx > 0 { - write!(f, ", ")?; + write!(f, " | ")?; } match segment { (Unbounded, Unbounded) => write!(f, "*")?, @@ -384,7 +375,7 @@ impl Display for Range { if v == b { write!(f, "=={v}")? } else { - write!(f, ">={v},<={b}")? + write!(f, ">={v}, <={b}")? } } (Included(v), Excluded(b)) => write!(f, ">={v}, <{b}")?, diff --git a/vendor/pubgrub/src/solver.rs b/vendor/pubgrub/src/solver.rs index 1728d1fe0aeb..a908b4a5285b 100644 --- a/vendor/pubgrub/src/solver.rs +++ b/vendor/pubgrub/src/solver.rs @@ -76,7 +76,7 @@ use crate::error::PubGrubError; pub use crate::internal::core::State; pub use crate::internal::incompatibility::{Incompatibility, Kind}; use crate::package::Package; -use crate::type_aliases::{DependencyConstraints, Map, SelectedDependencies}; +use crate::type_aliases::{Map, SelectedDependencies}; use crate::version_set::VersionSet; use log::{debug, info}; @@ -162,10 +162,10 @@ pub fn resolve( )); continue; } - Dependencies::Known(x) if x.contains_key(p) => { + Dependencies::Known(x) if x.clone().into_iter().any(|(d, _)| &d == p) => { return Err(PubGrubError::SelfDependency { package: p.clone(), - version: v, + version: v.clone(), }); } Dependencies::Known(x) => x, @@ -175,12 +175,12 @@ pub fn resolve( let dep_incompats = state.add_incompatibility_from_dependencies( p.clone(), v.clone(), - &known_dependencies, + known_dependencies, ); state.partial_solution.add_version( p.clone(), - v, + v.clone(), dep_incompats, &state.incompatibility_store, ); @@ -196,11 +196,11 @@ pub fn resolve( /// An enum used by [DependencyProvider] that holds information about package dependencies. /// For each [Package] there is a set of versions allowed as a dependency. #[derive(Clone)] -pub enum Dependencies { +pub enum Dependencies { /// Package dependencies are unavailable. Unknown, /// Container for all available package versions. - Known(DependencyConstraints), + Known(T), } /// Trait that allows the algorithm to retrieve available packages and their dependencies. @@ -255,7 +255,7 @@ pub trait DependencyProvider { &self, package: &P, version: &VS::V, - ) -> Result, Box>; + ) -> Result + Clone>, Box>; /// This is called fairly regularly during the resolution, /// if it returns an Err then resolution will be terminated. @@ -279,7 +279,7 @@ pub trait DependencyProvider { )] #[cfg_attr(feature = "serde", serde(transparent))] pub struct OfflineDependencyProvider { - dependencies: Map>>, + dependencies: Map>>, } impl OfflineDependencyProvider { @@ -329,8 +329,8 @@ impl OfflineDependencyProvider { /// Lists dependencies of a given package and version. /// Returns [None] if no information is available regarding that package and version pair. - fn dependencies(&self, package: &P, version: &VS::V) -> Option> { - self.dependencies.get(package)?.get(version).cloned() + fn dependencies(&self, package: &P, version: &VS::V) -> Option<&Map> { + self.dependencies.get(package)?.get(version) } } @@ -364,11 +364,16 @@ impl DependencyProvider for OfflineDependency fn get_dependencies( &self, package: &P, - version: &VS::V, - ) -> Result, Box> { + version: &::V, + ) -> Result + Clone>, Box> + { Ok(match self.dependencies(package, version) { None => Dependencies::Unknown, - Some(dependencies) => Dependencies::Known(dependencies), + Some(dependencies) => Dependencies::Known( + dependencies + .into_iter() + .map(|(p, vs)| (p.clone(), vs.clone())), + ), }) } } diff --git a/vendor/pubgrub/src/type_aliases.rs b/vendor/pubgrub/src/type_aliases.rs index 11cc37c7509c..c0912659f3cb 100644 --- a/vendor/pubgrub/src/type_aliases.rs +++ b/vendor/pubgrub/src/type_aliases.rs @@ -8,10 +8,3 @@ pub type Map = rustc_hash::FxHashMap; /// Concrete dependencies picked by the library during [resolve](crate::solver::resolve) /// from [DependencyConstraints]. pub type SelectedDependencies = Map; - -/// Holds information about all possible versions a given package can accept. -/// There is a difference in semantics between an empty map -/// inside [DependencyConstraints] and [Dependencies::Unknown](crate::solver::Dependencies::Unknown): -/// the former means the package has no dependency and it is a known fact, -/// while the latter means they could not be fetched by the [DependencyProvider](crate::solver::DependencyProvider). -pub type DependencyConstraints = Map; diff --git a/vendor/pubgrub/tests/proptest.rs b/vendor/pubgrub/tests/proptest.rs index 017efed0ecd5..d5ac3f816200 100644 --- a/vendor/pubgrub/tests/proptest.rs +++ b/vendor/pubgrub/tests/proptest.rs @@ -34,7 +34,8 @@ impl DependencyProvider &self, p: &P, v: &VS::V, - ) -> Result, Box> { + ) -> Result + Clone>, Box> + { self.0.get_dependencies(p, v) } @@ -86,7 +87,8 @@ impl> DependencyProvid &self, p: &P, v: &VS::V, - ) -> Result, Box> { + ) -> Result + Clone>, Box> + { self.dp.get_dependencies(p, v) } @@ -345,8 +347,8 @@ fn retain_dependencies( smaller_dependency_provider.add_dependencies( n.clone(), v.clone(), - deps.iter().filter_map(|(dep, range)| { - if !retain(n, v, dep) { + deps.into_iter().filter_map(|(dep, range)| { + if !retain(n, v, &dep) { None } else { Some((dep.clone(), range.clone())) diff --git a/vendor/pubgrub/tests/sat_dependency_provider.rs b/vendor/pubgrub/tests/sat_dependency_provider.rs index 2bfb21e99978..fe03d9cbf4a3 100644 --- a/vendor/pubgrub/tests/sat_dependency_provider.rs +++ b/vendor/pubgrub/tests/sat_dependency_provider.rs @@ -69,10 +69,10 @@ impl SatResolve { Dependencies::Unknown => panic!(), Dependencies::Known(d) => d, }; - for (p1, range) in &deps { + for (p1, range) in deps { let empty_vec = vec![]; let mut matches: Vec = all_versions_by_p - .get(p1) + .get(&p1) .unwrap_or(&empty_vec) .iter() .filter(|(v1, _)| range.contains(v1))