diff --git a/crates/uv-resolver/src/resolution/display.rs b/crates/uv-resolver/src/resolution/display.rs index 797bce00a..61821be2f 100644 --- a/crates/uv-resolver/src/resolution/display.rs +++ b/crates/uv-resolver/src/resolution/display.rs @@ -39,16 +39,16 @@ pub struct DisplayResolutionGraph<'a> { } #[derive(Debug)] -enum DisplayResolutionGraphNode { +enum DisplayResolutionGraphNode<'dist> { Root, - Dist(RequirementsTxtDist), + Dist(RequirementsTxtDist<'dist>), } -impl DisplayResolutionGraphNode { +impl DisplayResolutionGraphNode<'_> { fn markers(&self) -> &MarkerTree { match self { DisplayResolutionGraphNode::Root => &MarkerTree::TRUE, - DisplayResolutionGraphNode::Dist(dist) => &dist.markers, + DisplayResolutionGraphNode::Dist(dist) => dist.markers, } } } @@ -191,7 +191,7 @@ impl std::fmt::Display for DisplayResolutionGraph<'_> { // Display the distribution hashes, if any. let mut has_hashes = false; if self.show_hashes { - for hash in &node.hashes { + for hash in node.hashes { has_hashes = true; line.push_str(" \\\n"); line.push_str(" --hash="); @@ -313,10 +313,11 @@ pub enum AnnotationStyle { } /// We don't need the edge markers anymore since we switched to propagated markers. -type IntermediatePetGraph = - petgraph::graph::Graph; +type IntermediatePetGraph<'dist> = + petgraph::graph::Graph, (), petgraph::Directed>; -type RequirementsTxtGraph = petgraph::graph::Graph; +type RequirementsTxtGraph<'dist> = + petgraph::graph::Graph, (), petgraph::Directed>; /// Reduce the graph, such that all nodes for a single package are combined, regardless of /// the extras. @@ -325,7 +326,7 @@ type RequirementsTxtGraph = petgraph::graph::Graph RequirementsTxtGraph { +fn combine_extras<'dist>(graph: &IntermediatePetGraph<'dist>) -> RequirementsTxtGraph<'dist> { let mut next = RequirementsTxtGraph::with_capacity(graph.node_count(), graph.edge_count()); let mut inverse = FxHashMap::with_capacity_and_hasher(graph.node_count(), FxBuildHasher); @@ -346,9 +347,6 @@ fn combine_extras(graph: &IntermediatePetGraph) -> RequirementsTxtGraph { node.extras.extend(dist.extras.iter().cloned()); node.extras.sort_unstable(); node.extras.dedup(); - if dist.extras.is_empty() { - node.markers = dist.markers.clone(); - } } else { let version_id = dist.version_id(); let dist = dist.clone(); diff --git a/crates/uv-resolver/src/resolution/requirements_txt.rs b/crates/uv-resolver/src/resolution/requirements_txt.rs index ccb501cab..85c9c0cb4 100644 --- a/crates/uv-resolver/src/resolution/requirements_txt.rs +++ b/crates/uv-resolver/src/resolution/requirements_txt.rs @@ -17,17 +17,15 @@ use crate::{ #[derive(Debug, Clone)] /// A pinned package with its resolved distribution and all the extras that were pinned for it. -pub(crate) struct RequirementsTxtDist { - pub(crate) dist: ResolvedDist, - pub(crate) version: Version, +pub(crate) struct RequirementsTxtDist<'dist> { + pub(crate) dist: &'dist ResolvedDist, + pub(crate) version: &'dist Version, + pub(crate) hashes: &'dist [HashDigest], + pub(crate) markers: &'dist MarkerTree, pub(crate) extras: Vec, - pub(crate) hashes: Vec, - /// Propagated markers that determine whether this package should be installed on the current - /// platform, without looking at which packages depend on it. - pub(crate) markers: MarkerTree, } -impl RequirementsTxtDist { +impl<'dist> RequirementsTxtDist<'dist> { /// Convert the [`RequirementsTxtDist`] to a requirement that adheres to the `requirements.txt` /// format. /// @@ -153,29 +151,29 @@ impl RequirementsTxtDist { if let VersionOrUrlRef::Url(url) = self.version_or_url() { RequirementsTxtComparator::Name { name: self.name(), - version: &self.version, + version: self.version, url: Some(url.verbatim()), } } else { RequirementsTxtComparator::Name { name: self.name(), - version: &self.version, + version: self.version, url: None, } } } - pub(crate) fn from_annotated_dist(annotated: &AnnotatedDist) -> Self { + pub(crate) fn from_annotated_dist(annotated: &'dist AnnotatedDist) -> Self { Self { - dist: annotated.dist.clone(), - version: annotated.version.clone(), + dist: &annotated.dist, + version: &annotated.version, + hashes: &annotated.hashes, + markers: &annotated.marker, extras: if let Some(extra) = annotated.extra.clone() { vec![extra] } else { vec![] }, - hashes: annotated.hashes.clone(), - markers: annotated.marker.clone(), } } } @@ -192,19 +190,19 @@ pub(crate) enum RequirementsTxtComparator<'a> { }, } -impl Name for RequirementsTxtDist { +impl Name for RequirementsTxtDist<'_> { fn name(&self) -> &PackageName { self.dist.name() } } -impl DistributionMetadata for RequirementsTxtDist { +impl DistributionMetadata for RequirementsTxtDist<'_> { fn version_or_url(&self) -> VersionOrUrlRef { self.dist.version_or_url() } } -impl Display for RequirementsTxtDist { +impl Display for RequirementsTxtDist<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Display::fmt(&self.dist, f) }