MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / compute_cache_key

Function compute_cache_key

cranelift/codegen/src/incremental_cache.rs:165–187  ·  view source on GitHub ↗

Compute a cache key, and hash it on your behalf. Since computing the `CacheKey` is a bit expensive, it should be done as least as possible.

(isa: &dyn TargetIsa, func: &Function)

Source from the content-addressed store, hash-verified

163///
164/// Since computing the `CacheKey` is a bit expensive, it should be done as least as possible.
165pub fn compute_cache_key(isa: &dyn TargetIsa, func: &Function) -> CacheKeyHash {
166 use core::hash::{Hash as _, Hasher};
167 use sha2::Digest as _;
168
169 struct Sha256Hasher(sha2::Sha256);
170
171 impl Hasher for Sha256Hasher {
172 fn finish(&self) -> u64 {
173 panic!("Sha256Hasher doesn't support finish!");
174 }
175 fn write(&mut self, bytes: &[u8]) {
176 self.0.update(bytes);
177 }
178 }
179
180 let cache_key = CacheKey::new(isa, func);
181
182 let mut hasher = Sha256Hasher(sha2::Sha256::new());
183 cache_key.hash(&mut hasher);
184 let hash: [u8; 32] = hasher.0.finalize().into();
185
186 CacheKeyHash(hash)
187}
188
189/// Given a function that's been successfully compiled, serialize it to a blob that the caller may
190/// store somewhere for future use by `try_finish_recompile`.

Callers 1

compile_with_cacheMethod · 0.85

Calls 5

CacheKeyHashClass · 0.85
Sha256HasherClass · 0.70
newFunction · 0.50
hashMethod · 0.45
finalizeMethod · 0.45

Tested by

no test coverage detected