Skip to content

Commit cc85fa2

Browse files
Borrow hash strategies in lock setup and the resolver provider (#21541)
We borrow the selected build hash strategy in `do_lock` and the caller's strategy in `DefaultResolverProvider`, avoiding unnecessary strategy clones and hash-map reference-count updates. The resolver thread, lookahead results, and cached version maps retain owned policy snapshots. Stacked on #21540. Follows up on #21223 (comment).
1 parent eead89b commit cc85fa2

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

‎crates/uv-resolver/src/resolver/provider.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct DefaultResolverProvider<'a, Context: BuildContext> {
121121
tags: Option<Tags>,
122122
requires_python: RequiresPython,
123123
allowed_yanks: AllowedYanks,
124-
hasher: HashStrategy,
124+
hasher: &'a HashStrategy,
125125
exclude_newer: ExcludeNewer,
126126
available_version_cutoff: Option<jiff::Timestamp>,
127127
index_locations: &'a IndexLocations,
@@ -149,7 +149,7 @@ impl<'a, Context: BuildContext> DefaultResolverProvider<'a, Context> {
149149
tags: tags.cloned(),
150150
requires_python: requires_python.clone(),
151151
allowed_yanks,
152-
hasher: hasher.clone(),
152+
hasher,
153153
exclude_newer,
154154
available_version_cutoff: std::env::var(EnvVars::UV_TEST_AVAILABLE_VERSION_CUTOFF)
155155
.ok()
@@ -200,7 +200,7 @@ impl<Context: BuildContext> ResolverProvider for DefaultResolverProvider<'_, Con
200200
FlatDistributions::from_entries(
201201
entries.iter().cloned(),
202202
self.tags.as_ref(),
203-
&self.hasher,
203+
self.hasher,
204204
self.build_options,
205205
)
206206
});
@@ -234,7 +234,7 @@ impl<Context: BuildContext> ResolverProvider for DefaultResolverProvider<'_, Con
234234
MetadataFormat::Flat(metadata) => VersionMap::from_flat_metadata(
235235
metadata,
236236
self.tags.as_ref(),
237-
&self.hasher,
237+
self.hasher,
238238
self.build_options,
239239
),
240240
}

‎crates/uv/src/commands/project/lock.rs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -841,10 +841,9 @@ async fn do_lock(
841841
// A fresh resolution retains those hashes under `--locked`, but an explicitly unlocked update
842842
// must be able to replace them. Build dependencies follow the same choice without generating
843843
// hashes for artifacts absent from the lockfile.
844-
let resolution_build_hasher = if matches!(mode, LockMode::Locked(..)) {
845-
locked_build_hasher.clone()
846-
} else {
847-
HashStrategy::default()
844+
let resolution_build_hasher = match mode {
845+
LockMode::Locked(..) => &locked_build_hasher,
846+
LockMode::Write(_) | LockMode::DryRun(_) | LockMode::Frozen(_) => &HashStrategy::default(),
848847
};
849848
let hasher = HashStrategy::generate(HashGeneration::Url)
850849
.with_verification(resolution_build_hasher.verification().clone());
@@ -912,7 +911,7 @@ async fn do_lock(
912911
extra_build_variables,
913912
*link_mode,
914913
build_options,
915-
&resolution_build_hasher,
914+
resolution_build_hasher,
916915
exclude_newer.clone(),
917916
sources.clone(),
918917
SourceTreeEditablePolicy::Project,

0 commit comments

Comments
 (0)