kache 1.2.1

Compiler cache for Rust, C/C++ and CUDA, with S3, GCS, shared-filesystem and OCI remotes.
use super::{
    Config, EntryMeta, EventResult, FileHashStats, HitCompletion, KeyEventRecord, RustcArgs,
    RustcCompiler, Store, clean_incremental_dir, record_input_prediction,
    restore_from_cache_with_memo_store,
};
use anyhow::Result;
use std::time::Instant;

/// Invocation state shared by every Rust cache-hit path.
pub(super) struct RustcHitContext<'a> {
    pub config: &'a Config,
    pub compiler: &'a RustcCompiler,
    pub memo_store: &'a Store,
    pub args: &'a RustcArgs,
    pub crate_name: &'a str,
    pub event_root: &'a str,
    pub start: Instant,
    pub extra_inputs: Option<&'a crate::extra_inputs::ExtraInputsSnapshot>,
}

impl RustcHitContext<'_> {
    /// Report a hit only after all artifacts restore successfully. Prediction
    /// records belong to the store used for key computation, which can differ
    /// from the store that supplied the artifacts after a volume-shard miss.
    #[allow(clippy::too_many_arguments)]
    pub(super) fn restore_and_finish(
        &self,
        store: &Store,
        meta: &EntryMeta,
        result: EventResult,
        cache_key: &str,
        key_ms: u64,
        key_hash_stats: FileHashStats,
        lookup_ms: u64,
        prediction_store: Option<&Store>,
        key: &crate::cache_key::KeyOutputs,
        key_record: &KeyEventRecord,
    ) -> Result<()> {
        let restore_start = Instant::now();
        restore_from_cache_with_memo_store(
            self.config,
            self.compiler,
            store,
            self.memo_store,
            self.args,
            meta,
            self.extra_inputs,
        )?;
        let restore_ms = restore_start.elapsed().as_millis() as u64;
        HitCompletion {
            event_root: self.event_root,
            crate_name: self.crate_name,
            result,
            cache_key,
            start: self.start,
            key_ms,
            key_hash_stats,
            lookup_ms,
            restore_ms,
            key_record: key_record.clone(),
            object_output: String::new(),
        }
        .report(self.config, meta);
        record_input_prediction(self.config, prediction_store, self.args, true, key);
        clean_incremental_dir(self.config, self.args);
        Ok(())
    }
}