Skip to content

Commit d1dddd8

Browse files
RMPRclaude
andcommitted
halide-cache: return Found::Hit/Miss from restore_outputs
retrieve_both returned a bool, so `if retrieve_both(..)?` read like a condition on retrieving both rather than "was it a hit". Rename it and return a named result, matching Lookup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TVxsuu7ZCt2cdfn99fuXaA
1 parent 9e9fb8d commit d1dddd8

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

‎halide-cache/src/main.rs‎

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ fn lookup(
320320
remote: Option<&remote::Remote>,
321321
outputs: &Outputs,
322322
) -> anyhow::Result<Lookup> {
323-
if retrieve_both(lager, outputs)? {
323+
if let Found::Hit = restore_outputs(lager, outputs)? {
324324
return Ok(Lookup::LocalHit);
325325
}
326326
let Some(remote) = remote else {
@@ -329,12 +329,12 @@ fn lookup(
329329
if !fetch_from_remote(remote, lager, outputs) {
330330
return Ok(Lookup::Miss);
331331
}
332-
match retrieve_both(lager, outputs) {
333-
Ok(true) => {
332+
match restore_outputs(lager, outputs) {
333+
Ok(Found::Hit) => {
334334
println!("Remote cache hits for Halide target {}", outputs.target());
335335
Ok(Lookup::RemoteHit)
336336
}
337-
Ok(false) => Ok(Lookup::Miss),
337+
Ok(Found::Miss) => Ok(Lookup::Miss),
338338
Err(e) => {
339339
// The server handed us something that does not extract.
340340
warn(format!("discarding corrupt remote entries: {e:#}"));
@@ -450,18 +450,24 @@ fn collect_zivid_env() -> Vec<String> {
450450
v
451451
}
452452

453-
/// Extracts both outputs from the local cache. `Ok(false)` when neither is
454-
/// there; a lone entry or a broken one is an error, since the two are always
455-
/// stored together.
456-
fn retrieve_both(lager: &Lager, outputs: &Outputs) -> anyhow::Result<bool> {
453+
/// Whether the outputs were in the local cache.
454+
enum Found {
455+
Hit,
456+
Miss,
457+
}
458+
459+
/// Extracts the object and the header from the local cache. `Found::Miss`
460+
/// when neither is there; a lone entry or a broken one is an error, since the
461+
/// two are always stored together.
462+
fn restore_outputs(lager: &Lager, outputs: &Outputs) -> anyhow::Result<Found> {
457463
let object = lager.retrieve(&outputs.object.address, &outputs.object.path);
458464
let header = lager.retrieve(&outputs.header.address, &outputs.header.path);
459465
match (object, header) {
460466
(Ok(()), Ok(())) => {
461467
println!("Cache hits for Halide target {}", outputs.target());
462-
Ok(true)
468+
Ok(Found::Hit)
463469
}
464-
(Err(lager::Error::NotFound { .. }), Err(lager::Error::NotFound { .. })) => Ok(false),
470+
(Err(lager::Error::NotFound { .. }), Err(lager::Error::NotFound { .. })) => Ok(Found::Miss),
465471
(Err(oe), Err(he)) => Err(anyhow::anyhow!(oe).context(he)),
466472
(Ok(()), Err(e)) => Err(anyhow::anyhow!(e).context("Retrieving the object was successful")),
467473
(Err(e), Ok(())) => Err(anyhow::anyhow!(e).context("Retrieving the header was successful")),

0 commit comments

Comments
 (0)