Skip to content

Commit

Permalink
refactor(content_hash): remove keys_being_calculated
Browse files Browse the repository at this point in the history
This parameter won't be useful once we parallelize content hashing, because the keys being calculated won't be helpful to find the dependency cycle when other tasks are also calculating keys.
  • Loading branch information
arxanas committed Sep 6, 2022
1 parent 91b3b95 commit 30037f2
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions focus/internals/src/lib/index/content_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use std::cell::RefCell;
use std::collections::HashMap;
use std::collections::{BTreeSet, HashSet};
use std::collections::{BTreeSet, HashMap};
use std::fmt::{Display, Write};
use std::hash::Hash;
use std::path::Path;
Expand Down Expand Up @@ -107,31 +106,19 @@ impl std::fmt::Debug for HashContext<'_> {
/// Compute a content-addressable hash for the provided [`DependencyKey`] using
/// the context in `ctx`.
pub fn content_hash(ctx: &HashContext, key: &DependencyKey) -> anyhow::Result<ContentHash> {
content_hash_dependency_key(ctx, key, &mut HashSet::new())
content_hash_dependency_key(ctx, key)
}

fn content_hash_dependency_key(
ctx: &HashContext,
key: &DependencyKey,
keys_being_calculated: &mut HashSet<DependencyKey>,
) -> anyhow::Result<ContentHash> {
debug!(?key, "Hashing dependency key");

{
let cache = &mut ctx.caches.borrow_mut().dependency_key_cache;
match cache.get(key) {
Some(hash) => return Ok(hash.to_owned()),
None => {
if !keys_being_calculated.insert(key.clone()) {
anyhow::bail!(
"\
Circular dependency when hashing: {:?}
These are the keys currently being hashed: {:?}",
key,
keys_being_calculated.iter().collect::<BTreeSet<_>>(),
);
}
}
if let Some(hash) = cache.get(key) {
return Ok(hash.to_owned());
}
}

Expand Down Expand Up @@ -259,9 +246,7 @@ These are the keys currently being hashed: {:?}",
let hashes = values_to_hash
.into_iter()
.map(|key_or_hash| match key_or_hash {
KeyOrPath::Key(dep_key) => {
content_hash_dependency_key(ctx, &dep_key, keys_being_calculated)
}
KeyOrPath::Key(dep_key) => content_hash_dependency_key(ctx, &dep_key),
KeyOrPath::Path(path) => content_hash_tree_path(ctx, path),
})
.collect::<Result<Vec<_>, _>>()?;
Expand Down

0 comments on commit 30037f2

Please sign in to comment.