Commit 30b04a27 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

hash(&self, algorithm: HashAlgorithm)

parent 1de67d8b
......@@ -4,7 +4,7 @@ use tracing::Instrument;
use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
use turbo_tasks_fs::FileSystemPath;
use turbo_tasks_hash::{HashAlgorithm, encode_hex};
use turbo_tasks_hash::HashAlgorithm;
use turbopack_core::{
asset::{Asset, no_hash_salt},
output::{OutputAsset, OutputAssets},
......@@ -44,7 +44,11 @@ async fn asset_path(
.await?
.context("asset content not found")?
} else {
encode_hex(*asset.content().hash().await?).into()
asset
.content()
.hash(HashAlgorithm::Xxh3Hash128Hex)
.owned()
.await?
};
Some(AssetPath {
path: RcStr::from(path),
......
......@@ -3,7 +3,7 @@ use serde::Serialize;
use turbo_rcstr::RcStr;
use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc};
use turbo_tasks_fs::{FileContent, FileSystemPath};
use turbo_tasks_hash::{DeterministicHash, Xxh3Hash64Hasher};
use turbo_tasks_hash::{DeterministicHash, HashAlgorithm, Xxh3Hash64Hasher, hash_xxh3_hash64};
use turbopack_core::{
asset::{Asset, AssetContent},
module::{Module, Modules},
......@@ -77,19 +77,11 @@ pub async fn outputs_hash(outputs: Vc<OutputAssets>) -> Result<Vc<u64>> {
.await?;
let outputs_hashes = output_assets
.iter()
.map(|asset| asset.content().hash())
.map(|asset| asset.content().hash(HashAlgorithm::Xxh3Hash128Hex))
.try_join()
.await?;
let outputs_hash = {
let mut hasher = Xxh3Hash64Hasher::new();
for hash in outputs_hashes.iter() {
hash.deterministic_hash(&mut hasher);
}
hasher.finish()
};
Ok(Vc::cell(outputs_hash))
Ok(Vc::cell(hash_xxh3_hash64(outputs_hashes)))
}
#[turbo_tasks::function]
......@@ -159,19 +151,11 @@ pub async fn sources_hash(module_graph: Vc<ModuleGraph>, modules: Vc<Modules>) -
.try_flat_join()
.await?
.into_iter()
.map(|source| source.content().hash())
.map(|source| source.content().hash(HashAlgorithm::Xxh3Hash128Hex))
.try_join()
.await?;
let sources_hash = {
let mut hasher = Xxh3Hash64Hasher::new();
for source in sources.iter() {
source.deterministic_hash(&mut hasher);
}
hasher.finish()
};
Ok(Vc::cell(sources_hash))
Ok(Vc::cell(hash_xxh3_hash64(sources)))
}
#[derive(Serialize)]
......
......@@ -2441,8 +2441,9 @@ impl FileContent {
}
#[turbo_tasks::function]
pub async fn hash(&self) -> Result<Vc<u64>> {
Ok(Vc::cell(hash_xxh3_hash64(self)))
pub fn hash(&self, algorithm: HashAlgorithm) -> Vc<RcStr> {
// no_hash_salt
Vc::cell(RcStr::from(deterministic_hash("", self, algorithm)))
}
/// Converts this [`FileContent`] into a [`PersistedFileContent`] by cloning.
......
......@@ -4,7 +4,7 @@ use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{
FileContent, FileJsonContent, FileLinesContent, FileSystemPath, LinkContent, LinkType,
};
use turbo_tasks_hash::{HashAlgorithm, Xxh3Hash64Hasher};
use turbo_tasks_hash::{HashAlgorithm, deterministic_hash};
use crate::version::{VersionedAssetContent, VersionedContent};
......@@ -131,16 +131,13 @@ impl AssetContent {
}
#[turbo_tasks::function]
pub async fn hash(&self) -> Result<Vc<u64>> {
pub fn hash(&self, algorithm: HashAlgorithm) -> Vc<RcStr> {
match self {
AssetContent::File(content) => Ok(content.hash()),
AssetContent::Redirect { target, link_type } => {
use turbo_tasks_hash::DeterministicHash;
let mut hasher = Xxh3Hash64Hasher::new();
target.deterministic_hash(&mut hasher);
link_type.deterministic_hash(&mut hasher);
Ok(Vc::cell(hasher.finish()))
}
AssetContent::File(content) => content.hash(algorithm),
AssetContent::Redirect { target, link_type } => Vc::cell(RcStr::from(
// no_hash_salt
deterministic_hash("", (target, link_type), algorithm),
)),
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment