diff --git a/cli/cache/cache_db.rs b/cli/cache/cache_db.rs index 02394d4cfd..7fd66e9333 100644 --- a/cli/cache/cache_db.rs +++ b/cli/cache/cache_db.rs @@ -25,12 +25,12 @@ impl CacheDBHash { Self(hash) } - pub fn from_source(source: impl std::hash::Hash) -> Self { + pub fn from_hashable(hashable: impl std::hash::Hash) -> Self { Self::new( // always write in the deno version just in case // the clearing on deno version change doesn't work FastInsecureHasher::new_deno_versioned() - .write_hashable(source) + .write_hashable(hashable) .finish(), ) } diff --git a/cli/cache/incremental.rs b/cli/cache/incremental.rs index 9ba343f273..f430c1266f 100644 --- a/cli/cache/incremental.rs +++ b/cli/cache/incremental.rs @@ -34,12 +34,16 @@ pub static INCREMENTAL_CACHE_DB: CacheDBConfiguration = CacheDBConfiguration { pub struct IncrementalCache(IncrementalCacheInner); impl IncrementalCache { - pub fn new( + pub fn new( db: CacheDB, - state: &TState, + state_hash: CacheDBHash, initial_file_paths: &[PathBuf], ) -> Self { - IncrementalCache(IncrementalCacheInner::new(db, state, initial_file_paths)) + IncrementalCache(IncrementalCacheInner::new( + db, + state_hash, + initial_file_paths, + )) } pub fn is_file_same(&self, file_path: &Path, file_text: &str) -> bool { @@ -67,12 +71,11 @@ struct IncrementalCacheInner { } impl IncrementalCacheInner { - pub fn new( + pub fn new( db: CacheDB, - state: &TState, + state_hash: CacheDBHash, initial_file_paths: &[PathBuf], ) -> Self { - let state_hash = CacheDBHash::from_source(state); let sql_cache = SqlIncrementalCache::new(db, state_hash); Self::from_sql_incremental_cache(sql_cache, initial_file_paths) } @@ -112,13 +115,13 @@ impl IncrementalCacheInner { pub fn is_file_same(&self, file_path: &Path, file_text: &str) -> bool { match self.previous_hashes.get(file_path) { - Some(hash) => *hash == CacheDBHash::from_source(file_text), + Some(hash) => *hash == CacheDBHash::from_hashable(file_text), None => false, } } pub fn update_file(&self, file_path: &Path, file_text: &str) { - let hash = CacheDBHash::from_source(file_text); + let hash = CacheDBHash::from_hashable(file_text); if let Some(previous_hash) = self.previous_hashes.get(file_path) { if *previous_hash == hash { return; // do not bother updating the db file because nothing has changed @@ -262,7 +265,7 @@ mod test { let sql_cache = SqlIncrementalCache::new(conn, CacheDBHash::new(1)); let file_path = PathBuf::from("/mod.ts"); let file_text = "test"; - let file_hash = CacheDBHash::from_source(file_text); + let file_hash = CacheDBHash::from_hashable(file_text); sql_cache.set_source_hash(&file_path, file_hash).unwrap(); let cache = IncrementalCacheInner::from_sql_incremental_cache( sql_cache, diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 868811c587..fdd8fcf40c 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -298,7 +298,7 @@ impl Loader for FetchCacher { module_info: &deno_graph::ModuleInfo, ) { log::debug!("Caching module info for {}", specifier); - let source_hash = CacheDBHash::from_source(source); + let source_hash = CacheDBHash::from_hashable(source); let result = self.module_info_cache.set_module_info( specifier, media_type, diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 671e7e3dc8..63f52c06f9 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -194,7 +194,7 @@ impl<'a> ModuleInfoCacheModuleAnalyzer<'a> { source: &Arc, ) -> Result { // attempt to load from the cache - let source_hash = CacheDBHash::from_source(source); + let source_hash = CacheDBHash::from_hashable(source); if let Some(info) = self.load_cached_module_info(specifier, media_type, source_hash) { @@ -228,7 +228,7 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { media_type: MediaType, ) -> Result { // attempt to load from the cache - let source_hash = CacheDBHash::from_source(&source); + let source_hash = CacheDBHash::from_hashable(&source); if let Some(info) = self.load_cached_module_info(specifier, media_type, source_hash) { diff --git a/cli/node.rs b/cli/node.rs index e0feb557a7..aa44dcab18 100644 --- a/cli/node.rs +++ b/cli/node.rs @@ -68,7 +68,7 @@ impl CliCjsCodeAnalyzer { specifier: &ModuleSpecifier, source: &str, ) -> Result { - let source_hash = CacheDBHash::from_source(source); + let source_hash = CacheDBHash::from_hashable(source); if let Some(analysis) = self.cache.get_cjs_analysis(specifier.as_str(), source_hash) { diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 29db06e97f..3411d557bf 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -43,6 +43,7 @@ use crate::args::FmtOptions; use crate::args::FmtOptionsConfig; use crate::args::ProseWrap; use crate::args::UnstableFmtOptions; +use crate::cache::CacheDBHash; use crate::cache::Caches; use crate::cache::IncrementalCache; use crate::colors; @@ -202,7 +203,7 @@ async fn format_files( let paths = paths_with_options.paths; let incremental_cache = Arc::new(IncrementalCache::new( caches.fmt_incremental_cache_db(), - &(&fmt_options.options, &fmt_options.unstable), // cache key + CacheDBHash::from_hashable((&fmt_options.options, &fmt_options.unstable)), &paths, )); formatter diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs index 8b8702c0f8..e7b16f0283 100644 --- a/cli/tools/lint/mod.rs +++ b/cli/tools/lint/mod.rs @@ -39,6 +39,7 @@ use crate::args::Flags; use crate::args::LintFlags; use crate::args::LintOptions; use crate::args::WorkspaceLintOptions; +use crate::cache::CacheDBHash; use crate::cache::Caches; use crate::cache::IncrementalCache; use crate::colors; @@ -291,7 +292,7 @@ impl WorkspaceLinter { lint_rules.incremental_cache_state().map(|state| { Arc::new(IncrementalCache::new( self.caches.lint_incremental_cache_db(), - &state, + CacheDBHash::from_hashable(&state), &paths, )) });