Skip to content

Commit c81db6e

Browse files
authored
fix: bust fast check cache on deno_graph version change (#491)
1 parent c1a8eec commit c81db6e

File tree

9 files changed

+29
-12
lines changed

9 files changed

+29
-12
lines changed

src/fast_check/cache.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ pub struct FastCheckCacheKey(u64);
1717
impl FastCheckCacheKey {
1818
#[cfg(feature = "fast_check")]
1919
pub fn build(
20+
hash_seed: &'static str,
2021
package_nv: &PackageNv,
2122
entrypoints: &BTreeSet<ModuleSpecifier>,
2223
) -> Self {
2324
use std::hash::Hash;
2425
use std::hash::Hasher;
2526
let mut hasher = twox_hash::XxHash64::default();
27+
hash_seed.hash(&mut hasher);
2628
package_nv.hash(&mut hasher);
2729
for value in entrypoints {
2830
value.hash(&mut hasher);
@@ -83,9 +85,15 @@ pub struct FastCheckCacheModuleItemDiagnostic {
8385
}
8486

8587
/// Cache for storing the results of fast checks based on a package.
86-
///
87-
/// Note: Implementors should bust their cache when their version changes.
8888
pub trait FastCheckCache {
89+
/// Seed that is provided to the hash in order to cache bust
90+
/// it on version changes.
91+
///
92+
/// This defaults to the current deno_graph version.
93+
fn hash_seed(&self) -> &'static str {
94+
env!("CARGO_PKG_VERSION")
95+
}
96+
8997
fn get(&self, key: FastCheckCacheKey) -> Option<FastCheckCacheItem>;
9098
fn set(&self, key: FastCheckCacheKey, value: FastCheckCacheItem);
9199
}

src/fast_check/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,11 @@ pub fn build_fast_check_type_graph<'a>(
570570
),
571571
));
572572
}
573-
let cache_key = FastCheckCacheKey::build(&nv, &package.entrypoints);
573+
let cache_key = FastCheckCacheKey::build(
574+
fast_check_cache.hash_seed(),
575+
&nv,
576+
&package.entrypoints,
577+
);
574578
fast_check_cache.set(
575579
cache_key,
576580
FastCheckCacheItem {

src/fast_check/range_finder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,8 @@ impl<'a> PublicRangeFinder<'a> {
466466
let Some(fast_check_cache) = &self.fast_check_cache else {
467467
return None;
468468
};
469-
let cache_key = FastCheckCacheKey::build(nv, entrypoints);
469+
let cache_key =
470+
FastCheckCacheKey::build(fast_check_cache.hash_seed(), nv, entrypoints);
470471
let Some(cache_item) = fast_check_cache.get(cache_key) else {
471472
return None;
472473
};

tests/helpers/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ pub struct TestFastCheckCache {
142142
}
143143

144144
impl FastCheckCache for TestFastCheckCache {
145+
fn hash_seed(&self) -> &'static str {
146+
"stable-for-tests"
147+
}
148+
145149
fn get(
146150
&self,
147151
key: deno_graph::FastCheckCacheKey,

tests/specs/graph/fast_check/cache__basic.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
286286
}
287287

288288
== fast check cache ==
289-
FastCheckCacheKey(4741815020074927300):
289+
FastCheckCacheKey(13212997092325944472):
290290
Deps - []
291291
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"]]

tests/specs/graph/fast_check/cache__diagnostic.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
152152

153153

154154
== fast check cache ==
155-
FastCheckCacheKey(4741815020074927300):
155+
FastCheckCacheKey(13212997092325944472):
156156
Deps - []
157157
Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"],["https://jsr.io/@scope/a/1.0.0/c.ts","diagnostic"]]

tests/specs/graph/fast_check/cache__diagnostic_deep.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
153153

154154

155155
== fast check cache ==
156-
FastCheckCacheKey(4741815020074927300):
156+
FastCheckCacheKey(13212997092325944472):
157157
Deps - []
158158
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"]]

tests/specs/graph/fast_check/cache__diagnostic_multiple_exports.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ Fast check https://jsr.io/@scope/a/1.0.0/mod.ts:
186186

187187

188188
== fast check cache ==
189-
FastCheckCacheKey(2640350593211828171):
189+
FastCheckCacheKey(17039939699199502831):
190190
Deps - []
191191
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"]]

tests/specs/graph/fast_check/cache__diagnostic_then_nested_dep.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ Fast check https://jsr.io/@scope/b/1.0.0/mod.ts:
192192
}
193193

194194
== fast check cache ==
195-
FastCheckCacheKey(4741815020074927300):
196-
Deps - ["@scope/[email protected]"]
197-
Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"]]
198-
FastCheckCacheKey(15065614787034843742):
195+
FastCheckCacheKey(3278580195394936988):
199196
Deps - []
200197
Modules: [["https://jsr.io/@scope/b/1.0.0/mod.ts","info"]]
198+
FastCheckCacheKey(13212997092325944472):
199+
Deps - ["@scope/[email protected]"]
200+
Modules: [["https://jsr.io/@scope/a/1.0.0/mod.ts","diagnostic"]]

0 commit comments

Comments
 (0)