From 1e4259a608f11a22b55a38061f73ad803a423d36 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 29 Oct 2023 11:42:25 -0700 Subject: [PATCH] Make the resolver deterministic (#218) At a minor performance cost... Closes https://github.com/astral-sh/puffin/issues/204. --- crates/puffin-resolver/src/resolver.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/puffin-resolver/src/resolver.rs b/crates/puffin-resolver/src/resolver.rs index b30afe161..f8148a1a4 100644 --- a/crates/puffin-resolver/src/resolver.rs +++ b/crates/puffin-resolver/src/resolver.rs @@ -259,8 +259,6 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> { in_flight: &mut FxHashSet, request_sink: &futures::channel::mpsc::UnboundedSender, ) -> Result<(T, Option), ResolveError> { - let mut selection = 0usize; - // Iterate over the potential packages, and fetch file metadata for any of them. These // represent our current best guesses for the versions that we _might_ select. for (index, (package, range)) in potential_packages.iter().enumerate() { @@ -302,14 +300,12 @@ impl<'a, Context: BuildContext + Sync> Resolver<'a, Context> { } } } - - selection = index; } - // TODO(charlie): This is really ugly, but we need to return `T`, not `&T` (and yet - // we also need to iterate over `potential_packages` multiple times, so we can't - // use `into_iter()`.) - let (package, range) = potential_packages.swap_remove(selection); + // Always choose the first package. + // TODO(charlie): Devise a better strategy here (for example: always choose the package with + // the fewest versions). + let (package, range) = potential_packages.swap_remove(0); return match package.borrow() { PubGrubPackage::Root => Ok((package, Some(MIN_VERSION.clone()))),