mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-29 03:02:55 +00:00
Use lockfile to prefill resolver index (#4495)
## Summary Use the lockfile to prefill the `InMemoryIndex` used by the resolver. This enables us to resolve completely from the lockfile without making any network requests/builds if the requirements are unchanged. It also means that if new requirements are added we can still avoid most I/O during resolution, partially addressing https://github.com/astral-sh/uv/issues/3925. The main limitation of this PR is that resolution from the lockfile can fail if new versions are requested that are not present in the lockfile, in which case we have to perform a fresh resolution. Fixing this would likely require lazy version/metadata requests by `VersionMap` (this is different from the lazy parsing we do, the list of versions in a `VersionMap` is currently immutable). Resolves https://github.com/astral-sh/uv/issues/3892. ## Test Plan Added a `deterministic!` macro that ensures that a resolve from the lockfile and a clean resolve result in the same lockfile output for all our current tests.
This commit is contained in:
parent
df2ee8ad14
commit
ba217f1059
13 changed files with 2578 additions and 1798 deletions
|
|
@ -20,6 +20,13 @@ pub struct OnceMap<K, V, H = RandomState> {
|
|||
}
|
||||
|
||||
impl<K: Eq + Hash, V: Clone, H: BuildHasher + Clone> OnceMap<K, V, H> {
|
||||
// Create a [`OnceMap`] with the specified capacity and hasher.
|
||||
pub fn with_capacity_and_hasher(capacity: usize, hasher: H) -> OnceMap<K, V, H> {
|
||||
OnceMap {
|
||||
items: DashMap::with_capacity_and_hasher(capacity, hasher),
|
||||
}
|
||||
}
|
||||
|
||||
/// Register that you want to start a job.
|
||||
///
|
||||
/// If this method returns `true`, you need to start a job and call [`OnceMap::done`] eventually
|
||||
|
|
@ -101,6 +108,21 @@ impl<K: Eq + Hash + Clone, V, H: Default + BuildHasher + Clone> Default for Once
|
|||
}
|
||||
}
|
||||
|
||||
impl<K, V, H> FromIterator<(K, V)> for OnceMap<K, V, H>
|
||||
where
|
||||
K: Eq + Hash,
|
||||
H: Default + Clone + BuildHasher,
|
||||
{
|
||||
fn from_iter<T: IntoIterator<Item = (K, V)>>(iter: T) -> Self {
|
||||
OnceMap {
|
||||
items: iter
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, Value::Filled(v)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum Value<V> {
|
||||
Waiting(Arc<Notify>),
|
||||
Filled(V),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue