From ca24e182517b60e1fea881d1a98709d08915ae62 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 29 May 2024 11:49:45 -0400 Subject: [PATCH 1/2] fix: allow seeding fast check cache with deno version --- src/fast_check/cache.rs | 6 ++++++ src/fast_check/mod.rs | 6 +++++- src/fast_check/range_finder.rs | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/fast_check/cache.rs b/src/fast_check/cache.rs index 0dc354193..eb0dc517a 100644 --- a/src/fast_check/cache.rs +++ b/src/fast_check/cache.rs @@ -17,12 +17,14 @@ pub struct FastCheckCacheKey(u64); impl FastCheckCacheKey { #[cfg(feature = "fast_check")] pub fn build( + hash_seed: &'static str, package_nv: &PackageNv, entrypoints: &BTreeSet, ) -> Self { use std::hash::Hash; use std::hash::Hasher; let mut hasher = twox_hash::XxHash64::default(); + hash_seed.hash(&mut hasher); package_nv.hash(&mut hasher); for value in entrypoints { value.hash(&mut hasher); @@ -86,6 +88,10 @@ pub struct FastCheckCacheModuleItemDiagnostic { /// /// Note: Implementors should bust their cache when their version changes. pub trait FastCheckCache { + fn hash_seed(&self) -> &'static str { + "" + } + fn get(&self, key: FastCheckCacheKey) -> Option; fn set(&self, key: FastCheckCacheKey, value: FastCheckCacheItem); } diff --git a/src/fast_check/mod.rs b/src/fast_check/mod.rs index 9b1cc3e1b..6d46e6ead 100644 --- a/src/fast_check/mod.rs +++ b/src/fast_check/mod.rs @@ -570,7 +570,11 @@ pub fn build_fast_check_type_graph<'a>( ), )); } - let cache_key = FastCheckCacheKey::build(&nv, &package.entrypoints); + let cache_key = FastCheckCacheKey::build( + fast_check_cache.hash_seed(), + &nv, + &package.entrypoints, + ); fast_check_cache.set( cache_key, FastCheckCacheItem { diff --git a/src/fast_check/range_finder.rs b/src/fast_check/range_finder.rs index 6120bc4cd..cbc7575b6 100644 --- a/src/fast_check/range_finder.rs +++ b/src/fast_check/range_finder.rs @@ -466,7 +466,8 @@ impl<'a> PublicRangeFinder<'a> { let Some(fast_check_cache) = &self.fast_check_cache else { return None; }; - let cache_key = FastCheckCacheKey::build(nv, entrypoints); + let cache_key = + FastCheckCacheKey::build(fast_check_cache.hash_seed(), nv, entrypoints); let Some(cache_item) = fast_check_cache.get(cache_key) else { return None; }; From 30924a5377117767653df92d92d58d65e5bf2517 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 29 May 2024 11:54:38 -0400 Subject: [PATCH 2/2] Update --- src/fast_check/cache.rs | 8 +++++--- tests/helpers/mod.rs | 4 ++++ tests/specs/graph/fast_check/cache__basic.txt | 2 +- tests/specs/graph/fast_check/cache__diagnostic.txt | 2 +- tests/specs/graph/fast_check/cache__diagnostic_deep.txt | 2 +- .../fast_check/cache__diagnostic_multiple_exports.txt | 2 +- .../fast_check/cache__diagnostic_then_nested_dep.txt | 8 ++++---- 7 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/fast_check/cache.rs b/src/fast_check/cache.rs index eb0dc517a..684cd4a60 100644 --- a/src/fast_check/cache.rs +++ b/src/fast_check/cache.rs @@ -85,11 +85,13 @@ pub struct FastCheckCacheModuleItemDiagnostic { } /// Cache for storing the results of fast checks based on a package. -/// -/// Note: Implementors should bust their cache when their version changes. pub trait FastCheckCache { + /// Seed that is provided to the hash in order to cache bust + /// it on version changes. + /// + /// This defaults to the current deno_graph version. fn hash_seed(&self) -> &'static str { - "" + env!("CARGO_PKG_VERSION") } fn get(&self, key: FastCheckCacheKey) -> Option; diff --git a/tests/helpers/mod.rs b/tests/helpers/mod.rs index 69192eedd..37c6dd379 100644 --- a/tests/helpers/mod.rs +++ b/tests/helpers/mod.rs @@ -142,6 +142,10 @@ pub struct TestFastCheckCache { } impl FastCheckCache for TestFastCheckCache { + fn hash_seed(&self) -> &'static str { + "stable-for-tests" + } + fn get( &self, key: deno_graph::FastCheckCacheKey, diff --git a/tests/specs/graph/fast_check/cache__basic.txt b/tests/specs/graph/fast_check/cache__basic.txt index 29aa26c06..3e3499d2c 100644 --- a/tests/specs/graph/fast_check/cache__basic.txt +++ b/tests/specs/graph/fast_check/cache__basic.txt @@ -286,6 +286,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts: } == fast check cache == -FastCheckCacheKey(4741815020074927300): +FastCheckCacheKey(13212997092325944472): Deps - [] Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","info"],["https://jsr.io/@scope/a/1.0.0/a.ts","info"],["https://jsr.io/@scope/a/1.0.0/a4.ts","info"],["https://jsr.io/@scope/a/1.0.0/a6.ts","info"]] diff --git a/tests/specs/graph/fast_check/cache__diagnostic.txt b/tests/specs/graph/fast_check/cache__diagnostic.txt index f8b337032..03949677c 100644 --- a/tests/specs/graph/fast_check/cache__diagnostic.txt +++ b/tests/specs/graph/fast_check/cache__diagnostic.txt @@ -152,6 +152,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts: == fast check cache == -FastCheckCacheKey(4741815020074927300): +FastCheckCacheKey(13212997092325944472): Deps - [] Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/c.ts","diagnostic"]] diff --git a/tests/specs/graph/fast_check/cache__diagnostic_deep.txt b/tests/specs/graph/fast_check/cache__diagnostic_deep.txt index 99551b31c..00b90a98d 100644 --- a/tests/specs/graph/fast_check/cache__diagnostic_deep.txt +++ b/tests/specs/graph/fast_check/cache__diagnostic_deep.txt @@ -153,6 +153,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts: == fast check cache == -FastCheckCacheKey(4741815020074927300): +FastCheckCacheKey(13212997092325944472): Deps - [] Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/a.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/b.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/c.ts","diagnostic"]] diff --git a/tests/specs/graph/fast_check/cache__diagnostic_multiple_exports.txt b/tests/specs/graph/fast_check/cache__diagnostic_multiple_exports.txt index dc972f177..9b49ad03a 100644 --- a/tests/specs/graph/fast_check/cache__diagnostic_multiple_exports.txt +++ b/tests/specs/graph/fast_check/cache__diagnostic_multiple_exports.txt @@ -186,6 +186,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts: == fast check cache == -FastCheckCacheKey(2640350593211828171): +FastCheckCacheKey(17039939699199502831): Deps - [] Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/b.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/a.ts","diagnostic"]] diff --git a/tests/specs/graph/fast_check/cache__diagnostic_then_nested_dep.txt b/tests/specs/graph/fast_check/cache__diagnostic_then_nested_dep.txt index 13d946b1a..c84df374f 100644 --- a/tests/specs/graph/fast_check/cache__diagnostic_then_nested_dep.txt +++ b/tests/specs/graph/fast_check/cache__diagnostic_then_nested_dep.txt @@ -192,9 +192,9 @@ Fast check https://jsr.io/@scope/b/1.0.0/mod.ts: } == fast check cache == -FastCheckCacheKey(4741815020074927300): - Deps - ["@scope/b@1.0.0"] - Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"]] -FastCheckCacheKey(15065614787034843742): +FastCheckCacheKey(3278580195394936988): Deps - [] Modules: [["https://jsr.io/@scope/b/1.0.0/mod.ts","info"]] +FastCheckCacheKey(13212997092325944472): + Deps - ["@scope/b@1.0.0"] + Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"]]