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

hash(&self, algorithm: HashAlgorithm)

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