From 4eb2590d5c6e03b68c9d24ab58b7ab3bbe5580bb Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 8 Jul 2026 12:58:58 +0800 Subject: [PATCH 1/7] Add persistent caching for modules codegen --- .../src/artifacts/code_generation_results.rs | 34 +- crates/rspack_core/src/cache/mixed.rs | 2 +- crates/rspack_core/src/cache/mod.rs | 2 +- .../src/cache/persistent/context.rs | 2 + .../rspack_core/src/cache/persistent/mod.rs | 21 +- .../src/cache/persistent/occasion/mod.rs | 2 + .../occasion/modules_codegen/mod.rs | 419 ++++++++++++++++++ crates/rspack_core/src/init_fragment.rs | 222 ++++++++++ crates/rspack_core/src/runtime.rs | 1 + 9 files changed, 701 insertions(+), 4 deletions(-) create mode 100644 crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs diff --git a/crates/rspack_core/src/artifacts/code_generation_results.rs b/crates/rspack_core/src/artifacts/code_generation_results.rs index d0a4de04c17e..6535c7ad878a 100644 --- a/crates/rspack_core/src/artifacts/code_generation_results.rs +++ b/crates/rspack_core/src/artifacts/code_generation_results.rs @@ -5,6 +5,10 @@ use std::{ }; use anymap::CloneAny; +use rspack_cacheable::{ + cacheable, + with::{AsPreset, AsVec}, +}; use rspack_collections::IdentifierMap; use rspack_hash::{HashDigest, HashFunction, HashSalt, RspackHash, RspackHashDigest, RspackHasher}; use rspack_sources::BoxSource; @@ -14,9 +18,11 @@ use serde::Serialize; use crate::{ ArtifactExt, AssetInfo, BindingCell, ChunkInitFragments, ConcatenationScope, ModuleIdentifier, - RuntimeGlobals, RuntimeSpec, RuntimeSpecMap, SourceType, incremental::IncrementalPasses, + RuntimeGlobals, RuntimeKey, RuntimeMode, RuntimeSpec, RuntimeSpecMap, SourceType, + incremental::IncrementalPasses, }; +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationDataUrl { inner: String, @@ -33,12 +39,15 @@ impl CodeGenerationDataUrl { } // For performance, mark the js modules containing AUTO_PUBLIC_PATH_PLACEHOLDER +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationPublicPathAutoReplace(pub bool); +#[cacheable] #[derive(Clone, Debug)] pub struct URLStaticMode; +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationDataFilename { filename: String, @@ -62,6 +71,7 @@ impl CodeGenerationDataFilename { } } +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationDataAssetInfo { inner: AssetInfo, @@ -77,8 +87,10 @@ impl CodeGenerationDataAssetInfo { } } +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationDataTopLevelDeclarations { + #[cacheable(with=AsVec)] inner: FxHashSet, } @@ -92,6 +104,7 @@ impl CodeGenerationDataTopLevelDeclarations { } } +#[cacheable] #[derive(Clone, Debug)] pub struct CodeGenerationExportsFinalNames { inner: HashMap, @@ -404,6 +417,25 @@ impl CodeGenerationResults { ) { (&self.map, &self.module_generation_result_map) } + + pub(crate) fn insert_with_runtime_keys( + &mut self, + module_identifier: ModuleIdentifier, + codegen_res: CodeGenerationResult, + runtime_keys: impl IntoIterator, + ) { + let codegen_res_id = codegen_res.id; + self + .module_generation_result_map + .insert(codegen_res_id, BindingCell::from(codegen_res)); + + let mut spec_map = RuntimeSpecMap::default(); + spec_map.mode = RuntimeMode::Map; + spec_map + .map + .extend(runtime_keys.into_iter().map(|key| (key, codegen_res_id))); + self.map.insert(module_identifier, spec_map); + } } #[derive(Debug)] diff --git a/crates/rspack_core/src/cache/mixed.rs b/crates/rspack_core/src/cache/mixed.rs index 3b4a7cb80873..684c987bc269 100644 --- a/crates/rspack_core/src/cache/mixed.rs +++ b/crates/rspack_core/src/cache/mixed.rs @@ -150,7 +150,7 @@ impl Cache for MixedCache { self.persistent.before_modules_codegen(compilation).await; } - async fn after_modules_codegen(&self, compilation: &Compilation) { + async fn after_modules_codegen(&mut self, compilation: &Compilation) { self.persistent.after_modules_codegen(compilation).await; } diff --git a/crates/rspack_core/src/cache/mod.rs b/crates/rspack_core/src/cache/mod.rs index 0517c2a0c297..5f128880d225 100644 --- a/crates/rspack_core/src/cache/mod.rs +++ b/crates/rspack_core/src/cache/mod.rs @@ -66,7 +66,7 @@ pub trait Cache: Debug + Send + Sync { // MODULES_CODEGEN hooks async fn before_modules_codegen(&mut self, _compilation: &mut Compilation) {} - async fn after_modules_codegen(&self, _compilation: &Compilation) {} + async fn after_modules_codegen(&mut self, _compilation: &Compilation) {} // MODULES_RUNTIME_REQUIREMENTS hooks async fn before_modules_runtime_requirements(&mut self, _compilation: &mut Compilation) {} diff --git a/crates/rspack_core/src/cache/persistent/context.rs b/crates/rspack_core/src/cache/persistent/context.rs index c4c973e0e6f7..dada3d99326e 100644 --- a/crates/rspack_core/src/cache/persistent/context.rs +++ b/crates/rspack_core/src/cache/persistent/context.rs @@ -320,6 +320,7 @@ fn read_occasion_timing_label(name: &'static str) -> &'static str { "make" => "read make from persistent cache", "meta" => "read meta from persistent cache", "module hashes" => "read module hashes from persistent cache", + "modules codegen" => "read modules codegen from persistent cache", "minimize" => "read minimize from persistent cache", "source map" => "read source map from persistent cache", _ => "read occasion from persistent cache", @@ -331,6 +332,7 @@ fn write_occasion_timing_label(name: &'static str) -> &'static str { "make" => "write make to persistent cache", "meta" => "write meta to persistent cache", "module hashes" => "write module hashes to persistent cache", + "modules codegen" => "write modules codegen to persistent cache", "minimize" => "write minimize to persistent cache", "source map" => "write source map to persistent cache", _ => "write occasion to persistent cache", diff --git a/crates/rspack_core/src/cache/persistent/mod.rs b/crates/rspack_core/src/cache/persistent/mod.rs index 527f1d488eb6..6a5d62ee92ca 100644 --- a/crates/rspack_core/src/cache/persistent/mod.rs +++ b/crates/rspack_core/src/cache/persistent/mod.rs @@ -23,7 +23,7 @@ use self::{ codec::CacheCodec, context::CacheContext, occasion::{ - MakeOccasion, MetaOccasion, MinimizeOccasion, ModuleHashesOccasion, + MakeOccasion, MetaOccasion, MinimizeOccasion, ModuleHashesOccasion, ModulesCodegenOccasion, SourceMapDevToolPluginOccasion, }, snapshot::{Snapshot, SnapshotOptions}, @@ -65,6 +65,7 @@ pub struct PersistentCache { make_occasion: MakeOccasion, meta_occasion: MetaOccasion, module_hashes_occasion: ModuleHashesOccasion, + modules_codegen_occasion: ModulesCodegenOccasion, minimize_occasion: MinimizeOccasion, source_map_dev_tool_plugin_occasion: SourceMapDevToolPluginOccasion, } @@ -127,6 +128,7 @@ impl PersistentCache { make_occasion: MakeOccasion::new(codec.clone()), meta_occasion: MetaOccasion::new(codec.clone()), module_hashes_occasion: ModuleHashesOccasion::new(codec.clone()), + modules_codegen_occasion: ModulesCodegenOccasion::new(codec.clone()), minimize_occasion: MinimizeOccasion::new(codec.clone()), source_map_dev_tool_plugin_occasion: SourceMapDevToolPluginOccasion::new(codec), } @@ -250,6 +252,23 @@ impl Cache for PersistentCache { .save_occasion(&self.module_hashes_occasion, &compilation.cgm_hash_artifact); } + async fn before_modules_codegen(&mut self, compilation: &mut Compilation) { + if compilation.is_rebuild { + return; + } + + if let Some(artifact) = self.ctx.load_occasion(&self.modules_codegen_occasion).await { + *compilation.code_generation_results = artifact; + } + } + + async fn after_modules_codegen(&mut self, compilation: &Compilation) { + self.ctx.save_occasion( + &self.modules_codegen_occasion, + &compilation.code_generation_results, + ); + } + async fn before_process_assets(&mut self, compilation: &mut Compilation) { if compilation.is_rebuild { return; diff --git a/crates/rspack_core/src/cache/persistent/occasion/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/mod.rs index fd63eb83990a..26e9426a9ed3 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/mod.rs @@ -3,6 +3,7 @@ pub mod make; pub mod meta; pub mod minimize; pub mod module_hashes; +pub mod modules_codegen; use std::future::Future; @@ -13,6 +14,7 @@ pub use minimize::{ CachedExtractedComments, CachedMinimizeEntry, MinimizeOccasion, MinimizePersistentCacheArtifact, }; pub use module_hashes::ModuleHashesOccasion; +pub use modules_codegen::ModulesCodegenOccasion; use rspack_error::Result; use super::storage::Storage; diff --git a/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs new file mode 100644 index 000000000000..ac112d15f7e8 --- /dev/null +++ b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs @@ -0,0 +1,419 @@ +use std::sync::Arc; + +use rspack_cacheable::{ + cacheable, + with::{AsPreset, AsVec}, +}; +use rspack_error::Result; +use rspack_sources::BoxSource; +use rustc_hash::FxHashMap; + +use super::{ + super::{codec::CacheCodec, storage::Storage}, + Occasion, +}; +use crate::{ + AssetInfo, BindingCell, CachedChunkInitFragment, ChunkInitFragments, CodeGenerationData, + CodeGenerationDataAssetInfo, CodeGenerationDataFilename, CodeGenerationDataTopLevelDeclarations, + CodeGenerationDataUrl, CodeGenerationExportsFinalNames, CodeGenerationPublicPathAutoReplace, + CodeGenerationResult, CodeGenerationResults, ModuleIdentifier, RuntimeGlobals, RuntimeKey, + SourceType, URLStaticMode, get_runtime_key, +}; + +pub const SCOPE: &str = "occasion_modules_codegen"; +const ARTIFACT_KEY: &[u8] = b"code_generation_results"; + +#[cacheable] +struct Entry { + records: Vec, +} + +#[cacheable] +struct Record { + module: ModuleIdentifier, + runtime_keys: Vec, + result: CachedCodeGenerationResult, +} + +#[cacheable] +struct CachedCodeGenerationResult { + sources: Vec, + data: Vec, + chunk_init_fragments: Vec, + runtime_requirements: RuntimeGlobals, + hash: Option, +} + +#[cacheable] +struct CachedSource { + source_type: SourceType, + #[cacheable(with=AsPreset)] + source: BoxSource, +} + +#[cacheable] +enum CachedCodeGenerationData { + Url(String), + PublicPathAutoReplace(bool), + UrlStaticMode, + Filename { + filename: String, + public_path: String, + }, + AssetInfo(AssetInfo), + TopLevelDeclarations( + #[cacheable(with=AsVec)] rustc_hash::FxHashSet, + ), + ExportsFinalNames(FxHashMap), + ChunkInitFragments(Vec), +} + +impl Entry { + fn try_from_artifact(artifact: &CodeGenerationResults) -> Option { + let (runtime_map, result_map) = artifact.inner(); + let mut records = Vec::new(); + + for (module, runtime_results) in runtime_map { + let mut grouped_runtime_keys = FxHashMap::<_, Vec>::default(); + match runtime_results.mode { + crate::RuntimeMode::Empty => {} + crate::RuntimeMode::SingleEntry => { + let runtime = runtime_results.single_runtime.as_ref()?; + let result = runtime_results.single_value?; + grouped_runtime_keys + .entry(result) + .or_default() + .push(get_runtime_key(runtime).clone()); + } + crate::RuntimeMode::Map => { + for (runtime_key, result) in &runtime_results.map { + grouped_runtime_keys + .entry(*result) + .or_default() + .push(runtime_key.clone()); + } + } + } + + for (result_id, runtime_keys) in grouped_runtime_keys { + if runtime_keys.is_empty() { + continue; + } + let result = result_map.get(&result_id)?; + records.push(Record { + module: *module, + runtime_keys, + result: CachedCodeGenerationResult::try_from_result(result)?, + }); + } + } + + Some(Self { records }) + } + + fn into_artifact(self) -> CodeGenerationResults { + let mut artifact = CodeGenerationResults::default(); + for record in self.records { + if record.runtime_keys.is_empty() { + continue; + } + artifact.insert_with_runtime_keys( + record.module, + record.result.into_result(), + record.runtime_keys, + ); + } + artifact + } +} + +impl CachedCodeGenerationResult { + fn try_from_result(result: &CodeGenerationResult) -> Option { + if result.concatenation_scope.is_some() { + return None; + } + + Some(Self { + sources: result + .inner + .as_ref() + .iter() + .map(|(source_type, source)| CachedSource { + source_type: *source_type, + source: source.clone(), + }) + .collect(), + data: cache_code_generation_data(&result.data)?, + chunk_init_fragments: cache_chunk_init_fragments(&result.chunk_init_fragments)?, + runtime_requirements: result.runtime_requirements, + hash: result.hash.clone(), + }) + } + + fn into_result(self) -> CodeGenerationResult { + let mut sources = FxHashMap::default(); + for source in self.sources { + sources.insert(source.source_type, source.source); + } + + CodeGenerationResult { + inner: BindingCell::from(sources), + data: restore_code_generation_data(self.data), + chunk_init_fragments: self + .chunk_init_fragments + .into_iter() + .map(CachedChunkInitFragment::into_fragment) + .collect(), + runtime_requirements: self.runtime_requirements, + hash: self.hash, + id: Default::default(), + concatenation_scope: None, + } + } +} + +fn cache_code_generation_data(data: &CodeGenerationData) -> Option> { + let mut cached = Vec::new(); + + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::Url(item.inner().to_string())); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::PublicPathAutoReplace(item.0)); + } + if data.contains::() { + cached.push(CachedCodeGenerationData::UrlStaticMode); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::Filename { + filename: item.filename().to_string(), + public_path: item.public_path().to_string(), + }); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::AssetInfo(item.inner().clone())); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::TopLevelDeclarations( + item.inner().clone(), + )); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::ExportsFinalNames( + item.inner().clone(), + )); + } + if let Some(item) = data.get::() { + cached.push(CachedCodeGenerationData::ChunkInitFragments( + cache_chunk_init_fragments(item)?, + )); + } + + if cached.len() == data.len() { + Some(cached) + } else { + None + } +} + +fn restore_code_generation_data(cached: Vec) -> CodeGenerationData { + let mut data = CodeGenerationData::default(); + + for item in cached { + match item { + CachedCodeGenerationData::Url(url) => { + data.insert(CodeGenerationDataUrl::new(url)); + } + CachedCodeGenerationData::PublicPathAutoReplace(value) => { + data.insert(CodeGenerationPublicPathAutoReplace(value)); + } + CachedCodeGenerationData::UrlStaticMode => { + data.insert(URLStaticMode); + } + CachedCodeGenerationData::Filename { + filename, + public_path, + } => { + data.insert(CodeGenerationDataFilename::new(filename, public_path)); + } + CachedCodeGenerationData::AssetInfo(asset_info) => { + data.insert(CodeGenerationDataAssetInfo::new(asset_info)); + } + CachedCodeGenerationData::TopLevelDeclarations(declarations) => { + data.insert(CodeGenerationDataTopLevelDeclarations::new(declarations)); + } + CachedCodeGenerationData::ExportsFinalNames(names) => { + data.insert(CodeGenerationExportsFinalNames::new(names)); + } + CachedCodeGenerationData::ChunkInitFragments(fragments) => { + data.insert( + fragments + .into_iter() + .map(CachedChunkInitFragment::into_fragment) + .collect::(), + ); + } + } + } + + data +} + +fn cache_chunk_init_fragments( + fragments: &ChunkInitFragments, +) -> Option> { + fragments + .iter() + .map(CachedChunkInitFragment::from_fragment) + .collect() +} + +#[derive(Debug)] +pub struct ModulesCodegenOccasion { + codec: Arc, +} + +impl ModulesCodegenOccasion { + pub fn new(codec: Arc) -> Self { + Self { codec } + } +} + +impl Occasion for ModulesCodegenOccasion { + type Artifact = CodeGenerationResults; + + fn name(&self) -> &'static str { + "modules codegen" + } + + #[tracing::instrument(name = "Cache::Occasion::ModulesCodegen::reset", skip_all)] + fn reset(&self, storage: &mut dyn Storage) { + storage.reset(SCOPE); + } + + #[tracing::instrument(name = "Cache::Occasion::ModulesCodegen::save", skip_all)] + fn save(&self, storage: &mut dyn Storage, artifact: &CodeGenerationResults) { + let Some(entry) = Entry::try_from_artifact(artifact) else { + tracing::debug!( + "skip modules codegen persistent cache because the artifact contains unsupported data" + ); + storage.reset(SCOPE); + return; + }; + + match self.codec.encode(&entry) { + Ok(bytes) => { + storage.set(SCOPE, ARTIFACT_KEY.to_vec(), bytes); + tracing::debug!( + "saved {} modules codegen persistent cache records", + entry.records.len() + ); + } + Err(err) => { + tracing::warn!("modules codegen persistent cache encode failed: {:?}", err); + storage.reset(SCOPE); + } + } + } + + #[tracing::instrument(name = "Cache::Occasion::ModulesCodegen::recovery", skip_all)] + async fn recovery(&self, storage: &dyn Storage) -> Result { + let items = storage.load(SCOPE).await?; + let Some((_, value)) = items + .into_iter() + .find(|(key, _)| key.as_slice() == ARTIFACT_KEY) + else { + return Ok(CodeGenerationResults::default()); + }; + + let entry = self.codec.decode::(&value)?; + tracing::debug!( + "recovered {} modules codegen persistent cache records", + entry.records.len() + ); + Ok(entry.into_artifact()) + } +} + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use rspack_sources::{RawStringSource, Source, SourceExt}; + + use super::*; + use crate::{ + InitFragmentKey, InitFragmentStage, NormalInitFragment, RuntimeSpec, + cache::persistent::storage::MemoryStorage, + }; + + #[tokio::test] + async fn should_save_and_recover_code_generation_results() { + let module = ModuleIdentifier::from("module-a"); + let runtime = RuntimeSpec::from_iter(["main".into()]); + let mut result = CodeGenerationResult::default() + .with_javascript(RawStringSource::from_static("module.exports = 1;").boxed()); + result.data.insert(CodeGenerationDataFilename::new( + "asset.png".into(), + "/".into(), + )); + result.chunk_init_fragments.push(Box::new( + NormalInitFragment::new( + "var __init = true;\n".into(), + InitFragmentStage::StageConstants, + 0, + InitFragmentKey::Const("__init".into()), + None, + ) + .with_top_level_decl_symbols(vec!["__init".into()]), + )); + result.runtime_requirements.insert(RuntimeGlobals::REQUIRE); + + let mut artifact = CodeGenerationResults::default(); + artifact.insert(module, result, [runtime.clone()]); + + let occasion = ModulesCodegenOccasion::new(Arc::new(CacheCodec::new(None))); + let mut storage = MemoryStorage::default(); + occasion.save(&mut storage, &artifact); + + let recovered = occasion.recovery(&storage).await.unwrap(); + let recovered_result = recovered.get(&module, Some(&runtime)); + let source = recovered_result.get(&SourceType::JavaScript).unwrap(); + assert_eq!(source.source().into_string_lossy(), "module.exports = 1;"); + assert!( + recovered_result + .data + .get::() + .is_some() + ); + assert_eq!(recovered_result.chunk_init_fragments.len(), 1); + assert!( + recovered_result + .runtime_requirements + .contains(RuntimeGlobals::REQUIRE) + ); + } + + #[tokio::test] + async fn should_reset_scope_for_unsupported_codegen_data() { + #[derive(Clone)] + struct UnsupportedData; + + let module = ModuleIdentifier::from("module-a"); + let runtime = RuntimeSpec::from_iter(["main".into()]); + let mut result = CodeGenerationResult::default() + .with_javascript(RawStringSource::from_static("module.exports = 1;").boxed()); + result.data.insert(UnsupportedData); + + let mut artifact = CodeGenerationResults::default(); + artifact.insert(module, result, [runtime]); + + let occasion = ModulesCodegenOccasion::new(Arc::new(CacheCodec::new(None))); + let mut storage = MemoryStorage::default(); + storage.set(SCOPE, ARTIFACT_KEY.to_vec(), vec![1]); + + occasion.save(&mut storage, &artifact); + + assert!(storage.load(SCOPE).await.unwrap().is_empty()); + } +} diff --git a/crates/rspack_core/src/init_fragment.rs b/crates/rspack_core/src/init_fragment.rs index e73b74218228..48ad5d22b075 100644 --- a/crates/rspack_core/src/init_fragment.rs +++ b/crates/rspack_core/src/init_fragment.rs @@ -8,6 +8,7 @@ use std::{ use dyn_clone::{DynClone, clone_trait_object}; use hashlink::LinkedHashSet; use indexmap::IndexMap; +use rspack_cacheable::{cacheable, with::AsPreset}; use rspack_error::Result; use rspack_hash::{RspackHash, RspackHasher}; use rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}; @@ -27,6 +28,7 @@ pub struct InitFragmentContents { pub end: Option, } +#[cacheable] #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum InitFragmentKey { Unique(u32), @@ -243,6 +245,7 @@ impl + 'static> InitFragmentExt for T { } } +#[cacheable] #[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] pub enum InitFragmentStage { StageConstants, @@ -858,3 +861,222 @@ impl InitFragment for ExternalModuleInitFragmen &self.key } } + +#[cacheable] +#[derive(Debug, Clone)] +pub(crate) enum CachedChunkInitFragment { + Normal { + content: String, + stage: InitFragmentStage, + position: i32, + key: InitFragmentKey, + end_content: Option, + #[cacheable(with=rspack_cacheable::with::AsVec)] + top_level_decl_symbols: Vec, + }, + EsmExport { + exports_argument: ExportsArgument, + export_map: Vec, + is_circular_module: Option, + }, + AwaitDependencies { + promises: Vec, + }, + Conditional { + content: String, + stage: InitFragmentStage, + position: i32, + key: InitFragmentKey, + end_content: Option, + runtime_condition: RuntimeCondition, + }, + ExternalModule { + imported_module: String, + import_specifiers: Vec, + default_import: Option, + stage: InitFragmentStage, + position: i32, + }, +} + +#[cacheable] +#[derive(Debug, Clone)] +pub(crate) struct CachedEsmExportBindingEntry { + #[cacheable(with=AsPreset)] + name: Atom, + binding: CachedEsmExportBinding, +} + +#[cacheable] +#[derive(Debug, Clone)] +pub(crate) enum CachedEsmExportBinding { + Getter(#[cacheable(with=AsPreset)] Atom), + Value(#[cacheable(with=AsPreset)] Atom), +} + +#[cacheable] +#[derive(Debug, Clone)] +pub(crate) struct CachedExternalImportSpecifier { + name: String, + specifiers: Vec, +} + +impl CachedChunkInitFragment { + pub(crate) fn from_fragment(fragment: &BoxChunkInitFragment) -> Option { + if let Ok(fragment) = fragment.clone().into_any().downcast::() { + return Some(Self::Normal { + content: fragment.content, + stage: fragment.stage, + position: fragment.position, + key: fragment.key, + end_content: fragment.end_content, + top_level_decl_symbols: fragment.top_level_decl_symbols, + }); + } + + if let Ok(fragment) = fragment + .clone() + .into_any() + .downcast::() + { + return Some(Self::EsmExport { + exports_argument: fragment.exports_argument, + export_map: fragment + .export_map + .into_iter() + .map(|(name, binding)| CachedEsmExportBindingEntry { + name, + binding: match binding { + ESMExportBinding::Getter(value) => CachedEsmExportBinding::Getter(value), + ESMExportBinding::Value(value) => CachedEsmExportBinding::Value(value), + }, + }) + .collect(), + is_circular_module: fragment.is_circular_module, + }); + } + + if let Ok(fragment) = fragment + .clone() + .into_any() + .downcast::() + { + return Some(Self::AwaitDependencies { + promises: fragment.promises.into_iter().collect(), + }); + } + + if let Ok(fragment) = fragment + .clone() + .into_any() + .downcast::() + { + return Some(Self::Conditional { + content: fragment.content, + stage: fragment.stage, + position: fragment.position, + key: fragment.key, + end_content: fragment.end_content, + runtime_condition: fragment.runtime_condition, + }); + } + + if let Ok(fragment) = fragment + .clone() + .into_any() + .downcast::() + { + return Some(Self::ExternalModule { + imported_module: fragment.imported_module, + import_specifiers: fragment + .import_specifiers + .into_iter() + .map(|(name, specifiers)| CachedExternalImportSpecifier { + name, + specifiers: specifiers.into_iter().collect(), + }) + .collect(), + default_import: fragment.default_import, + stage: fragment.stage, + position: fragment.position, + }); + } + + None + } + + pub(crate) fn into_fragment(self) -> BoxChunkInitFragment { + match self { + Self::Normal { + content, + stage, + position, + key, + end_content, + top_level_decl_symbols, + } => Box::new( + NormalInitFragment::new(content, stage, position, key, end_content) + .with_top_level_decl_symbols(top_level_decl_symbols), + ), + Self::EsmExport { + exports_argument, + export_map, + is_circular_module, + } => Box::new(ESMExportInitFragment::new( + exports_argument, + export_map + .into_iter() + .map(|entry| { + ( + entry.name, + match entry.binding { + CachedEsmExportBinding::Getter(value) => ESMExportBinding::Getter(value), + CachedEsmExportBinding::Value(value) => ESMExportBinding::Value(value), + }, + ) + }) + .collect(), + is_circular_module, + )), + Self::AwaitDependencies { promises } => Box::new(AwaitDependenciesInitFragment::new( + promises.into_iter().collect(), + )), + Self::Conditional { + content, + stage, + position, + key, + end_content, + runtime_condition, + } => Box::new(ConditionalInitFragment::new( + content, + stage, + position, + key, + end_content, + runtime_condition, + )), + Self::ExternalModule { + imported_module, + import_specifiers, + default_import, + stage, + position, + } => Box::new(ExternalModuleInitFragment::new( + imported_module, + import_specifiers + .into_iter() + .flat_map(|item| { + item + .specifiers + .into_iter() + .map(move |specifier| (item.name.clone(), specifier)) + }) + .collect(), + default_import, + stage, + position, + )), + } + } +} diff --git a/crates/rspack_core/src/runtime.rs b/crates/rspack_core/src/runtime.rs index 945c5b3220f5..c1e1552f7692 100644 --- a/crates/rspack_core/src/runtime.rs +++ b/crates/rspack_core/src/runtime.rs @@ -193,6 +193,7 @@ pub fn is_runtime_equal(a: &RuntimeSpec, b: &RuntimeSpec) -> bool { a.key == b.key } +#[cacheable] #[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(allocative, derive(allocative::Allocative))] pub enum RuntimeCondition { From 25082739202f0647651d5be5795ee55fc86ecb94 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 8 Jul 2026 18:24:56 +0800 Subject: [PATCH 2/7] Refactor cache persistence and cleanup flow --- crates/rspack_cacheable/src/with/as_inner.rs | 11 + crates/rspack_cacheable/src/with/as_vec.rs | 18 + .../src/artifacts/code_generation_results.rs | 158 ++++++-- crates/rspack_core/src/binding/cell.rs | 13 + .../occasion/modules_codegen/mod.rs | 367 +----------------- crates/rspack_core/src/concatenated_module.rs | 36 +- .../src/dependency/dependency_template.rs | 22 +- .../runtime_requirements_dependency.rs | 9 +- crates/rspack_core/src/init_fragment.rs | 319 ++++----------- crates/rspack_core/src/runtime_template.rs | 11 +- .../src/parser_and_generator/mod.rs | 12 +- crates/rspack_plugin_esm_library/src/link.rs | 28 +- .../rspack_plugin_esm_library/src/render.rs | 2 +- ...sm_export_imported_specifier_dependency.rs | 2 +- .../rspack_plugin_javascript/src/runtime.rs | 11 +- .../src/container/container_entry_module.rs | 18 +- .../sharing/consume_shared_runtime_module.rs | 11 +- .../src/sharing/share_runtime_module.rs | 13 +- .../src/esm_import_dependency.rs | 2 +- .../src/mock_method_dependency.rs | 8 +- 20 files changed, 353 insertions(+), 718 deletions(-) diff --git a/crates/rspack_cacheable/src/with/as_inner.rs b/crates/rspack_cacheable/src/with/as_inner.rs index dd379dfd43fc..7df392fc0b06 100644 --- a/crates/rspack_cacheable/src/with/as_inner.rs +++ b/crates/rspack_cacheable/src/with/as_inner.rs @@ -66,6 +66,17 @@ impl AsInnerConverter for std::sync::Arc { } } +// for Box +impl AsInnerConverter for Box { + type Inner = T; + fn to_inner(&self) -> &Self::Inner { + self.as_ref() + } + fn from_inner(data: Self::Inner) -> Self { + Self::new(data) + } +} + // for OnceCell // rkyv::with::Map #[repr(u8)] diff --git a/crates/rspack_cacheable/src/with/as_vec.rs b/crates/rspack_cacheable/src/with/as_vec.rs index 7760500c16c9..5147d8abd20a 100644 --- a/crates/rspack_cacheable/src/with/as_vec.rs +++ b/crates/rspack_cacheable/src/with/as_vec.rs @@ -131,6 +131,24 @@ where } } +// for hashlink::LinkedHashSet +impl AsVecConverter for hashlink::LinkedHashSet +where + T: std::cmp::Eq + std::hash::Hash, + S: core::hash::BuildHasher + Default, +{ + type Item = T; + fn len(&self) -> usize { + self.len() + } + fn iter(&self) -> impl Iterator { + self.iter() + } + fn from(data: impl Iterator>) -> Result { + data.collect::>>() + } +} + // for indexmap::IndexSet impl AsVecConverter for indexmap::IndexSet where diff --git a/crates/rspack_core/src/artifacts/code_generation_results.rs b/crates/rspack_core/src/artifacts/code_generation_results.rs index 6535c7ad878a..faf64848190d 100644 --- a/crates/rspack_core/src/artifacts/code_generation_results.rs +++ b/crates/rspack_core/src/artifacts/code_generation_results.rs @@ -1,25 +1,27 @@ use std::{ collections::hash_map::Entry, - ops::{Deref, DerefMut}, - sync::atomic::AtomicU32, + fmt::Debug, + sync::atomic::{AtomicU32, Ordering}, }; -use anymap::CloneAny; +use dyn_clone::{DynClone, clone_trait_object}; use rspack_cacheable::{ - cacheable, - with::{AsPreset, AsVec}, + cacheable, cacheable_dyn, + with::{AsCacheable, AsInner, AsMap, AsOption, AsPreset, AsVec, Unsupported}, }; use rspack_collections::IdentifierMap; use rspack_hash::{HashDigest, HashFunction, HashSalt, RspackHash, RspackHashDigest, RspackHasher}; use rspack_sources::BoxSource; -use rspack_util::atom::Atom; +use rspack_util::{ + atom::Atom, + ext::{AsAny, IntoAny}, +}; use rustc_hash::{FxHashMap as HashMap, FxHashSet}; use serde::Serialize; use crate::{ ArtifactExt, AssetInfo, BindingCell, ChunkInitFragments, ConcatenationScope, ModuleIdentifier, - RuntimeGlobals, RuntimeKey, RuntimeMode, RuntimeSpec, RuntimeSpecMap, SourceType, - incremental::IncrementalPasses, + RuntimeGlobals, RuntimeSpec, RuntimeSpecMap, SourceType, incremental::IncrementalPasses, }; #[cacheable] @@ -120,27 +122,109 @@ impl CodeGenerationExportsFinalNames { } } +#[cacheable_dyn] +pub trait CodeGenerationDataItem: Debug + DynClone + AsAny + IntoAny + Send + Sync {} + +clone_trait_object!(CodeGenerationDataItem); + +#[cacheable] #[derive(Debug, Default, Clone)] -pub struct CodeGenerationData { - inner: anymap::Map, +pub struct CodeGenerationDataChunkInitFragments { + inner: ChunkInitFragments, } -impl Deref for CodeGenerationData { - type Target = anymap::Map; - - fn deref(&self) -> &Self::Target { +impl CodeGenerationDataChunkInitFragments { + pub fn inner(&self) -> &ChunkInitFragments { &self.inner } -} -impl DerefMut for CodeGenerationData { - fn deref_mut(&mut self) -> &mut Self::Target { + pub fn inner_mut(&mut self) -> &mut ChunkInitFragments { &mut self.inner } } +impl From for CodeGenerationDataChunkInitFragments { + fn from(inner: ChunkInitFragments) -> Self { + Self { inner } + } +} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataUrl {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationPublicPathAutoReplace {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for URLStaticMode {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataFilename {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataAssetInfo {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataTopLevelDeclarations {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationExportsFinalNames {} + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataChunkInitFragments {} + +#[cacheable] +#[derive(Debug, Default, Clone)] +pub struct CodeGenerationData { + inner: Vec>, +} + +impl CodeGenerationData { + pub fn insert(&mut self, item: T) -> Option { + if let Some(index) = self + .inner + .iter() + .position(|item| item.as_ref().as_any().is::()) + { + let old = std::mem::replace(&mut self.inner[index], Box::new(item)); + old.into_any().downcast::().ok().map(|item| *item) + } else { + self.inner.push(Box::new(item)); + None + } + } + + pub fn get(&self) -> Option<&T> { + self + .inner + .iter() + .find_map(|item| item.as_ref().as_any().downcast_ref::()) + } + + pub fn get_mut(&mut self) -> Option<&mut T> { + self + .inner + .iter_mut() + .find_map(|item| item.as_mut().as_any_mut().downcast_mut::()) + } + + pub fn contains(&self) -> bool { + self.get::().is_some() + } + + pub fn len(&self) -> usize { + self.inner.len() + } + + pub fn is_empty(&self) -> bool { + self.inner.is_empty() + } +} + +#[cacheable] #[derive(Debug, Default, Clone)] pub struct CodeGenerationResult { + #[cacheable(with=AsInner>)] pub inner: BindingCell>, /// [definition in webpack](https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Module.js#L75) pub data: CodeGenerationData, @@ -148,6 +232,7 @@ pub struct CodeGenerationResult { pub runtime_requirements: RuntimeGlobals, pub hash: Option, pub id: CodeGenResultId, + #[cacheable(with=AsOption)] pub concatenation_scope: Option, } @@ -208,6 +293,7 @@ impl CodeGenerationResult { } } +#[cacheable] #[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, Ord, PartialOrd, Serialize)] pub struct CodeGenResultId(u32); @@ -219,8 +305,10 @@ impl Default for CodeGenResultId { pub static CODE_GEN_RESULT_ID: AtomicU32 = AtomicU32::new(0); +#[cacheable] #[derive(Debug, Default, Clone)] pub struct CodeGenerationResults { + #[cacheable(with=AsMap>)] module_generation_result_map: HashMap>, map: IdentifierMap>, } @@ -418,23 +506,27 @@ impl CodeGenerationResults { (&self.map, &self.module_generation_result_map) } - pub(crate) fn insert_with_runtime_keys( - &mut self, - module_identifier: ModuleIdentifier, - codegen_res: CodeGenerationResult, - runtime_keys: impl IntoIterator, - ) { - let codegen_res_id = codegen_res.id; - self + pub(crate) fn sync_code_generation_result_id(&self) { + if let Some(next) = self .module_generation_result_map - .insert(codegen_res_id, BindingCell::from(codegen_res)); - - let mut spec_map = RuntimeSpecMap::default(); - spec_map.mode = RuntimeMode::Map; - spec_map - .map - .extend(runtime_keys.into_iter().map(|key| (key, codegen_res_id))); - self.map.insert(module_identifier, spec_map); + .keys() + .map(|id| id.0) + .max() + .and_then(|id| id.checked_add(1)) + { + let mut current = CODE_GEN_RESULT_ID.load(Ordering::Relaxed); + while current < next { + match CODE_GEN_RESULT_ID.compare_exchange_weak( + current, + next, + Ordering::Relaxed, + Ordering::Relaxed, + ) { + Ok(_) => break, + Err(value) => current = value, + } + } + } } } diff --git a/crates/rspack_core/src/binding/cell.rs b/crates/rspack_core/src/binding/cell.rs index eff6d3444a8e..c85d535ddbda 100644 --- a/crates/rspack_core/src/binding/cell.rs +++ b/crates/rspack_core/src/binding/cell.rs @@ -23,6 +23,7 @@ mod napi_binding { bindgen_prelude::{Object, ToNapiValue}, }; use once_cell::sync::OnceCell; + use rspack_cacheable::with::AsInnerConverter; use rspack_napi::{ThreadsafeOneShotRef, object_assign}; use rspack_sources::BoxSource; use rustc_hash::FxHashMap; @@ -360,6 +361,18 @@ mod napi_binding { } } + impl>> AsInnerConverter for BindingCell { + type Inner = T; + + fn to_inner(&self) -> &Self::Inner { + self.as_ref() + } + + fn from_inner(data: Self::Inner) -> Self { + data.into() + } + } + // Implement rkyv traits for BindingCell impl rkyv::Archive for BindingCell { diff --git a/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs index ac112d15f7e8..ffd11f74ff9d 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs @@ -1,273 +1,16 @@ use std::sync::Arc; -use rspack_cacheable::{ - cacheable, - with::{AsPreset, AsVec}, -}; use rspack_error::Result; -use rspack_sources::BoxSource; -use rustc_hash::FxHashMap; use super::{ super::{codec::CacheCodec, storage::Storage}, Occasion, }; -use crate::{ - AssetInfo, BindingCell, CachedChunkInitFragment, ChunkInitFragments, CodeGenerationData, - CodeGenerationDataAssetInfo, CodeGenerationDataFilename, CodeGenerationDataTopLevelDeclarations, - CodeGenerationDataUrl, CodeGenerationExportsFinalNames, CodeGenerationPublicPathAutoReplace, - CodeGenerationResult, CodeGenerationResults, ModuleIdentifier, RuntimeGlobals, RuntimeKey, - SourceType, URLStaticMode, get_runtime_key, -}; +use crate::CodeGenerationResults; pub const SCOPE: &str = "occasion_modules_codegen"; const ARTIFACT_KEY: &[u8] = b"code_generation_results"; -#[cacheable] -struct Entry { - records: Vec, -} - -#[cacheable] -struct Record { - module: ModuleIdentifier, - runtime_keys: Vec, - result: CachedCodeGenerationResult, -} - -#[cacheable] -struct CachedCodeGenerationResult { - sources: Vec, - data: Vec, - chunk_init_fragments: Vec, - runtime_requirements: RuntimeGlobals, - hash: Option, -} - -#[cacheable] -struct CachedSource { - source_type: SourceType, - #[cacheable(with=AsPreset)] - source: BoxSource, -} - -#[cacheable] -enum CachedCodeGenerationData { - Url(String), - PublicPathAutoReplace(bool), - UrlStaticMode, - Filename { - filename: String, - public_path: String, - }, - AssetInfo(AssetInfo), - TopLevelDeclarations( - #[cacheable(with=AsVec)] rustc_hash::FxHashSet, - ), - ExportsFinalNames(FxHashMap), - ChunkInitFragments(Vec), -} - -impl Entry { - fn try_from_artifact(artifact: &CodeGenerationResults) -> Option { - let (runtime_map, result_map) = artifact.inner(); - let mut records = Vec::new(); - - for (module, runtime_results) in runtime_map { - let mut grouped_runtime_keys = FxHashMap::<_, Vec>::default(); - match runtime_results.mode { - crate::RuntimeMode::Empty => {} - crate::RuntimeMode::SingleEntry => { - let runtime = runtime_results.single_runtime.as_ref()?; - let result = runtime_results.single_value?; - grouped_runtime_keys - .entry(result) - .or_default() - .push(get_runtime_key(runtime).clone()); - } - crate::RuntimeMode::Map => { - for (runtime_key, result) in &runtime_results.map { - grouped_runtime_keys - .entry(*result) - .or_default() - .push(runtime_key.clone()); - } - } - } - - for (result_id, runtime_keys) in grouped_runtime_keys { - if runtime_keys.is_empty() { - continue; - } - let result = result_map.get(&result_id)?; - records.push(Record { - module: *module, - runtime_keys, - result: CachedCodeGenerationResult::try_from_result(result)?, - }); - } - } - - Some(Self { records }) - } - - fn into_artifact(self) -> CodeGenerationResults { - let mut artifact = CodeGenerationResults::default(); - for record in self.records { - if record.runtime_keys.is_empty() { - continue; - } - artifact.insert_with_runtime_keys( - record.module, - record.result.into_result(), - record.runtime_keys, - ); - } - artifact - } -} - -impl CachedCodeGenerationResult { - fn try_from_result(result: &CodeGenerationResult) -> Option { - if result.concatenation_scope.is_some() { - return None; - } - - Some(Self { - sources: result - .inner - .as_ref() - .iter() - .map(|(source_type, source)| CachedSource { - source_type: *source_type, - source: source.clone(), - }) - .collect(), - data: cache_code_generation_data(&result.data)?, - chunk_init_fragments: cache_chunk_init_fragments(&result.chunk_init_fragments)?, - runtime_requirements: result.runtime_requirements, - hash: result.hash.clone(), - }) - } - - fn into_result(self) -> CodeGenerationResult { - let mut sources = FxHashMap::default(); - for source in self.sources { - sources.insert(source.source_type, source.source); - } - - CodeGenerationResult { - inner: BindingCell::from(sources), - data: restore_code_generation_data(self.data), - chunk_init_fragments: self - .chunk_init_fragments - .into_iter() - .map(CachedChunkInitFragment::into_fragment) - .collect(), - runtime_requirements: self.runtime_requirements, - hash: self.hash, - id: Default::default(), - concatenation_scope: None, - } - } -} - -fn cache_code_generation_data(data: &CodeGenerationData) -> Option> { - let mut cached = Vec::new(); - - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::Url(item.inner().to_string())); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::PublicPathAutoReplace(item.0)); - } - if data.contains::() { - cached.push(CachedCodeGenerationData::UrlStaticMode); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::Filename { - filename: item.filename().to_string(), - public_path: item.public_path().to_string(), - }); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::AssetInfo(item.inner().clone())); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::TopLevelDeclarations( - item.inner().clone(), - )); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::ExportsFinalNames( - item.inner().clone(), - )); - } - if let Some(item) = data.get::() { - cached.push(CachedCodeGenerationData::ChunkInitFragments( - cache_chunk_init_fragments(item)?, - )); - } - - if cached.len() == data.len() { - Some(cached) - } else { - None - } -} - -fn restore_code_generation_data(cached: Vec) -> CodeGenerationData { - let mut data = CodeGenerationData::default(); - - for item in cached { - match item { - CachedCodeGenerationData::Url(url) => { - data.insert(CodeGenerationDataUrl::new(url)); - } - CachedCodeGenerationData::PublicPathAutoReplace(value) => { - data.insert(CodeGenerationPublicPathAutoReplace(value)); - } - CachedCodeGenerationData::UrlStaticMode => { - data.insert(URLStaticMode); - } - CachedCodeGenerationData::Filename { - filename, - public_path, - } => { - data.insert(CodeGenerationDataFilename::new(filename, public_path)); - } - CachedCodeGenerationData::AssetInfo(asset_info) => { - data.insert(CodeGenerationDataAssetInfo::new(asset_info)); - } - CachedCodeGenerationData::TopLevelDeclarations(declarations) => { - data.insert(CodeGenerationDataTopLevelDeclarations::new(declarations)); - } - CachedCodeGenerationData::ExportsFinalNames(names) => { - data.insert(CodeGenerationExportsFinalNames::new(names)); - } - CachedCodeGenerationData::ChunkInitFragments(fragments) => { - data.insert( - fragments - .into_iter() - .map(CachedChunkInitFragment::into_fragment) - .collect::(), - ); - } - } - } - - data -} - -fn cache_chunk_init_fragments( - fragments: &ChunkInitFragments, -) -> Option> { - fragments - .iter() - .map(CachedChunkInitFragment::from_fragment) - .collect() -} - #[derive(Debug)] pub struct ModulesCodegenOccasion { codec: Arc, @@ -293,21 +36,10 @@ impl Occasion for ModulesCodegenOccasion { #[tracing::instrument(name = "Cache::Occasion::ModulesCodegen::save", skip_all)] fn save(&self, storage: &mut dyn Storage, artifact: &CodeGenerationResults) { - let Some(entry) = Entry::try_from_artifact(artifact) else { - tracing::debug!( - "skip modules codegen persistent cache because the artifact contains unsupported data" - ); - storage.reset(SCOPE); - return; - }; - - match self.codec.encode(&entry) { + match self.codec.encode(artifact) { Ok(bytes) => { storage.set(SCOPE, ARTIFACT_KEY.to_vec(), bytes); - tracing::debug!( - "saved {} modules codegen persistent cache records", - entry.records.len() - ); + tracing::debug!("saved modules codegen persistent cache artifact"); } Err(err) => { tracing::warn!("modules codegen persistent cache encode failed: {:?}", err); @@ -326,94 +58,9 @@ impl Occasion for ModulesCodegenOccasion { return Ok(CodeGenerationResults::default()); }; - let entry = self.codec.decode::(&value)?; - tracing::debug!( - "recovered {} modules codegen persistent cache records", - entry.records.len() - ); - Ok(entry.into_artifact()) - } -} - -#[cfg(test)] -mod tests { - use std::sync::Arc; - - use rspack_sources::{RawStringSource, Source, SourceExt}; - - use super::*; - use crate::{ - InitFragmentKey, InitFragmentStage, NormalInitFragment, RuntimeSpec, - cache::persistent::storage::MemoryStorage, - }; - - #[tokio::test] - async fn should_save_and_recover_code_generation_results() { - let module = ModuleIdentifier::from("module-a"); - let runtime = RuntimeSpec::from_iter(["main".into()]); - let mut result = CodeGenerationResult::default() - .with_javascript(RawStringSource::from_static("module.exports = 1;").boxed()); - result.data.insert(CodeGenerationDataFilename::new( - "asset.png".into(), - "/".into(), - )); - result.chunk_init_fragments.push(Box::new( - NormalInitFragment::new( - "var __init = true;\n".into(), - InitFragmentStage::StageConstants, - 0, - InitFragmentKey::Const("__init".into()), - None, - ) - .with_top_level_decl_symbols(vec!["__init".into()]), - )); - result.runtime_requirements.insert(RuntimeGlobals::REQUIRE); - - let mut artifact = CodeGenerationResults::default(); - artifact.insert(module, result, [runtime.clone()]); - - let occasion = ModulesCodegenOccasion::new(Arc::new(CacheCodec::new(None))); - let mut storage = MemoryStorage::default(); - occasion.save(&mut storage, &artifact); - - let recovered = occasion.recovery(&storage).await.unwrap(); - let recovered_result = recovered.get(&module, Some(&runtime)); - let source = recovered_result.get(&SourceType::JavaScript).unwrap(); - assert_eq!(source.source().into_string_lossy(), "module.exports = 1;"); - assert!( - recovered_result - .data - .get::() - .is_some() - ); - assert_eq!(recovered_result.chunk_init_fragments.len(), 1); - assert!( - recovered_result - .runtime_requirements - .contains(RuntimeGlobals::REQUIRE) - ); - } - - #[tokio::test] - async fn should_reset_scope_for_unsupported_codegen_data() { - #[derive(Clone)] - struct UnsupportedData; - - let module = ModuleIdentifier::from("module-a"); - let runtime = RuntimeSpec::from_iter(["main".into()]); - let mut result = CodeGenerationResult::default() - .with_javascript(RawStringSource::from_static("module.exports = 1;").boxed()); - result.data.insert(UnsupportedData); - - let mut artifact = CodeGenerationResults::default(); - artifact.insert(module, result, [runtime]); - - let occasion = ModulesCodegenOccasion::new(Arc::new(CacheCodec::new(None))); - let mut storage = MemoryStorage::default(); - storage.set(SCOPE, ARTIFACT_KEY.to_vec(), vec![1]); - - occasion.save(&mut storage, &artifact); - - assert!(storage.load(SCOPE).await.unwrap().is_empty()); + let artifact = self.codec.decode::(&value)?; + artifact.sync_code_generation_result_id(); + tracing::debug!("recovered modules codegen persistent cache artifact"); + Ok(artifact) } } diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index a01372bf9de5..4332bde6880f 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -41,19 +41,20 @@ use swc_experimental_ecma_semantic::resolver::{Semantic, resolver}; use crate::{ AsyncDependenciesBlockIdentifier, BoxDependency, BoxDependencyTemplate, BoxModule, BoxModuleDependency, BuildContext, BuildInfo, BuildMeta, BuildMetaDefaultObject, - BuildMetaExportsType, BuildResult, ChunkGraph, ChunkInitFragments, ChunkRenderContext, - CodeGenerationDataTopLevelDeclarations, CodeGenerationExportsFinalNames, - CodeGenerationPublicPathAutoReplace, CodeGenerationResult, Compilation, ConcatenatedModuleIdent, - ConcatenationScope, ConditionalInitFragment, ConnectionState, Context, DEFAULT_EXPORT, - DEFAULT_EXPORT_ATOM, DependenciesBlock, DependencyId, DependencyType, ExportInfo, ExportProvided, - ExportsArgument, ExportsInfoArtifact, ExportsType, FactoryMeta, ImportedByDeferModulesArtifact, - InitFragment, InitFragmentStage, LibIdentOptions, Module, ModuleArgument, - ModuleCodeGenerationContext, ModuleGraph, ModuleGraphCacheArtifact, ModuleGraphConnection, - ModuleIdentifier, ModuleLayer, ModuleStaticCache, ModuleType, NAMESPACE_OBJECT_EXPORT, - ParserOptions, Resolve, RuntimeCondition, RuntimeGlobals, RuntimeSpec, SideEffectsStateArtifact, - SourceType, URLStaticMode, UsageState, UsedName, UsedNameItem, escape_identifier, fast_set, - filter_runtime, find_target, get_runtime_key, impl_source_map_config, merge_runtime_condition, - merge_runtime_condition_non_false, module_update_hash, property_access, property_name, + BuildMetaExportsType, BuildResult, ChunkGraph, ChunkInitFragments, + CodeGenerationDataChunkInitFragments, CodeGenerationDataTopLevelDeclarations, + CodeGenerationExportsFinalNames, CodeGenerationPublicPathAutoReplace, CodeGenerationResult, + Compilation, ConcatenatedModuleIdent, ConcatenationScope, ConditionalInitFragment, + ConnectionState, Context, DEFAULT_EXPORT, DEFAULT_EXPORT_ATOM, DependenciesBlock, DependencyId, + DependencyType, ExportInfo, ExportProvided, ExportsArgument, ExportsInfoArtifact, ExportsType, + FactoryMeta, ImportedByDeferModulesArtifact, InitFragment, InitFragmentStage, LibIdentOptions, + Module, ModuleArgument, ModuleCodeGenerationContext, ModuleGraph, ModuleGraphCacheArtifact, + ModuleGraphConnection, ModuleIdentifier, ModuleLayer, ModuleStaticCache, ModuleType, + NAMESPACE_OBJECT_EXPORT, ParserOptions, Resolve, RuntimeCondition, RuntimeGlobals, RuntimeSpec, + SideEffectsStateArtifact, SourceType, URLStaticMode, UsageState, UsedName, UsedNameItem, + escape_identifier, fast_set, filter_runtime, find_target, get_runtime_key, + impl_source_map_config, merge_runtime_condition, merge_runtime_condition_non_false, + module_update_hash, property_access, property_name, render_make_deferred_namespace_mode_from_exports_type, reserved_names::RESERVED_NAMES_ATOM_SET, subtract_runtime_condition, to_identifier_with_escaped, to_normal_comment, @@ -1625,7 +1626,7 @@ impl Module for ConcatenatedModule { let mut result: ConcatSource = ConcatSource::default(); let mut should_add_esm_flag = false; - let mut chunk_init_fragments: Vec>> = Vec::new(); + let mut chunk_init_fragments: Vec> = Vec::new(); for ((source, attr), import_spec) in import_stmts { let content = render_imports(&source, attr.as_deref(), &import_spec); @@ -2585,8 +2586,11 @@ impl ConcatenatedModule { runtime_requirements.extend(*runtime_template.runtime_requirements()); - if let Some(fragments) = codegen_res.data.get::() { - chunk_init_fragments.extend(fragments.iter().cloned()); + if let Some(fragments) = codegen_res + .data + .get::() + { + chunk_init_fragments.extend(fragments.inner().iter().cloned()); } let concatenation_scope = concatenation_scope.expect("should have concatenation_scope"); diff --git a/crates/rspack_core/src/dependency/dependency_template.rs b/crates/rspack_core/src/dependency/dependency_template.rs index a83879d24ab7..25cf82985cbe 100644 --- a/crates/rspack_core/src/dependency/dependency_template.rs +++ b/crates/rspack_core/src/dependency/dependency_template.rs @@ -7,34 +7,38 @@ use rspack_sources::ReplaceSource; use rspack_util::ext::AsAny; use crate::{ - ChunkInitFragments, CodeGenerationData, Compilation, ConcatenationScope, DependencyType, Module, - ModuleCodeTemplate, ModuleInitFragments, RuntimeSpec, + ChunkInitFragments, CodeGenerationData, CodeGenerationDataChunkInitFragments, Compilation, + ConcatenationScope, DependencyType, Module, ModuleCodeTemplate, ModuleInitFragments, RuntimeSpec, }; -pub struct TemplateContext<'a, 'b, 'c> { +pub struct TemplateContext<'a, 'c> { pub compilation: &'a Compilation, pub module: &'a dyn Module, - pub init_fragments: &'a mut ModuleInitFragments<'b>, + pub init_fragments: &'a mut ModuleInitFragments, pub runtime: Option<&'a RuntimeSpec>, pub concatenation_scope: Option<&'c mut ConcatenationScope>, pub data: &'a mut CodeGenerationData, pub runtime_template: &'a mut ModuleCodeTemplate, } -impl TemplateContext<'_, '_, '_> { +impl TemplateContext<'_, '_> { pub fn chunk_init_fragments(&mut self) -> &mut ChunkInitFragments { - let data_fragments = self.data.get::(); + let data_fragments = self.data.get::(); if data_fragments.is_some() { self .data - .get_mut::() + .get_mut::() .expect("should have chunk_init_fragments") + .inner_mut() } else { - self.data.insert(ChunkInitFragments::default()); self .data - .get_mut::() + .insert(CodeGenerationDataChunkInitFragments::default()); + self + .data + .get_mut::() .expect("should have chunk_init_fragments") + .inner_mut() } } } diff --git a/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs b/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs index 374946e55cca..e411ec402946 100644 --- a/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs +++ b/crates/rspack_core/src/dependency/runtime_requirements_dependency.rs @@ -4,8 +4,9 @@ use rspack_cacheable::{cacheable, cacheable_dyn}; use rspack_hash::{RspackHash, RspackHasher}; use crate::{ - Compilation, DependencyCodeGeneration, DependencyRange, DependencyTemplate, - DependencyTemplateType, RuntimeGlobals, RuntimeSpec, TemplateContext, TemplateReplaceSource, + CodeGenerationDataItem, Compilation, DependencyCodeGeneration, DependencyRange, + DependencyTemplate, DependencyTemplateType, RuntimeGlobals, RuntimeSpec, TemplateContext, + TemplateReplaceSource, }; #[cacheable] @@ -150,11 +151,15 @@ impl RuntimeRequirementsDependency { } } +#[cacheable] #[derive(Debug, Default, Clone)] pub struct CodeGenerationRuntimeRequirementsWrite { pub runtime_requirements: RuntimeGlobals, } +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationRuntimeRequirementsWrite {} + impl CodeGenerationRuntimeRequirementsWrite { pub fn insert(&mut self, runtime_requirements: RuntimeGlobals) { self.runtime_requirements.insert(runtime_requirements); diff --git a/crates/rspack_core/src/init_fragment.rs b/crates/rspack_core/src/init_fragment.rs index 48ad5d22b075..b391327b3c23 100644 --- a/crates/rspack_core/src/init_fragment.rs +++ b/crates/rspack_core/src/init_fragment.rs @@ -8,7 +8,10 @@ use std::{ use dyn_clone::{DynClone, clone_trait_object}; use hashlink::LinkedHashSet; use indexmap::IndexMap; -use rspack_cacheable::{cacheable, with::AsPreset}; +use rspack_cacheable::{ + cacheable, cacheable_dyn, + with::{AsPreset, AsTuple2, AsVec}, +}; use rspack_error::Result; use rspack_hash::{RspackHash, RspackHasher}; use rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}; @@ -105,10 +108,7 @@ impl RspackHash for InitFragmentKey { } impl InitFragmentKey { - pub fn merge_fragments( - &self, - fragments: Vec>>, - ) -> Box> { + pub fn merge_fragments(&self, fragments: Vec) -> BoxInitFragment { match self { InitFragmentKey::ESMImport(_) => { let mut iter = fragments.into_iter(); @@ -205,7 +205,7 @@ impl InitFragmentKey { } } -fn first(fragments: Vec>>) -> Box> { +fn first(fragments: Vec) -> BoxInitFragment { fragments .into_iter() .next() @@ -217,9 +217,13 @@ pub trait InitFragmentRenderContext { fn runtime_template(&mut self) -> &mut ModuleCodeTemplate; } -pub trait InitFragment: IntoAny + RspackHash + DynClone + Debug + Sync + Send { +#[cacheable_dyn] +pub trait InitFragment: IntoAny + RspackHash + DynClone + Debug + Sync + Send { /// getContent + getEndContent - fn contents(self: Box, context: &mut C) -> Result; + fn contents( + self: Box, + context: &mut dyn InitFragmentRenderContext, + ) -> Result; fn stage(&self) -> InitFragmentStage; @@ -232,15 +236,14 @@ pub trait InitFragment: IntoAny + RspackHash + DynClone + Debug + Sync + Send } } -clone_trait_object!(InitFragment>); -clone_trait_object!(InitFragment); +clone_trait_object!(InitFragment); -pub trait InitFragmentExt { - fn boxed(self) -> Box>; +pub trait InitFragmentExt { + fn boxed(self) -> BoxInitFragment; } -impl + 'static> InitFragmentExt for T { - fn boxed(self) -> Box> { +impl InitFragmentExt for T { + fn boxed(self) -> BoxInitFragment { Box::new(self) } } @@ -284,10 +287,10 @@ impl Display for InitFragmentStage { } /// InitFragment.addToSource -pub fn render_init_fragments( +pub fn render_init_fragments( source: BoxSource, - mut fragments: Vec>>, - context: &mut C, + mut fragments: Vec, + context: &mut dyn InitFragmentRenderContext, ) -> Result { // here use sort_by_key because need keep order equal stage fragments fragments.sort_by(|a, b| { @@ -300,7 +303,7 @@ pub fn render_init_fragments( let mut keyed_fragments: IndexMap< InitFragmentKey, - Vec>>, + Vec, BuildHasherDefault, > = IndexMap::default(); for fragment in fragments { @@ -333,10 +336,10 @@ pub fn render_init_fragments( Ok(concat_source.boxed()) } -pub type BoxInitFragment = Box>; -pub type BoxModuleInitFragment<'a> = BoxInitFragment>; -pub type BoxChunkInitFragment = BoxInitFragment; -pub type ModuleInitFragments<'a> = Vec>; +pub type BoxInitFragment = Box; +pub type BoxModuleInitFragment = BoxInitFragment; +pub type BoxChunkInitFragment = BoxInitFragment; +pub type ModuleInitFragments = Vec; pub type ChunkInitFragments = Vec; impl InitFragmentRenderContext for GenerateContext<'_> { @@ -365,6 +368,7 @@ impl InitFragmentRenderContext for ChunkRenderContext { } } +#[cacheable] #[derive(Debug, Clone, rspack_hash::RspackHash)] pub struct NormalInitFragment { content: String, @@ -372,6 +376,7 @@ pub struct NormalInitFragment { position: i32, key: InitFragmentKey, end_content: Option, + #[cacheable(with=AsVec)] top_level_decl_symbols: Vec, } @@ -399,8 +404,12 @@ impl NormalInitFragment { } } -impl InitFragment for NormalInitFragment { - fn contents(self: Box, _context: &mut C) -> Result { +#[cacheable_dyn] +impl InitFragment for NormalInitFragment { + fn contents( + self: Box, + _context: &mut dyn InitFragmentRenderContext, + ) -> Result { Ok(InitFragmentContents { start: self.content, end: self.end_content, @@ -424,10 +433,11 @@ impl InitFragment for NormalInitFragment { } } +#[cacheable] #[derive(Debug, Clone)] pub enum ESMExportBinding { - Getter(Atom), - Value(Atom), + Getter(#[cacheable(with=AsPreset)] Atom), + Value(#[cacheable(with=AsPreset)] Atom), } impl RspackHash for ESMExportBinding { @@ -445,10 +455,12 @@ impl RspackHash for ESMExportBinding { } } +#[cacheable] #[derive(Debug, Clone, rspack_hash::RspackHash)] pub struct ESMExportInitFragment { exports_argument: ExportsArgument, // TODO: should be a map + #[cacheable(with=AsVec>)] export_map: Vec<(Atom, ESMExportBinding)>, is_circular_module: Option, } @@ -467,8 +479,12 @@ impl ESMExportInitFragment { } } -impl InitFragment for ESMExportInitFragment { - fn contents(mut self: Box, context: &mut C) -> Result { +#[cacheable_dyn] +impl InitFragment for ESMExportInitFragment { + fn contents( + mut self: Box, + context: &mut dyn InitFragmentRenderContext, + ) -> Result { let runtime_template = context.runtime_template(); self.export_map.sort_by(|a, b| a.0.cmp(&b.0)); @@ -556,8 +572,10 @@ impl InitFragment for ESMExportInitFragment { } } +#[cacheable] #[derive(Debug, Clone)] pub struct AwaitDependenciesInitFragment { + #[cacheable(with=AsVec)] promises: LinkedHashSet>, } @@ -581,8 +599,12 @@ impl RspackHash for AwaitDependenciesInitFragment { } } -impl InitFragment for AwaitDependenciesInitFragment { - fn contents(self: Box, _context: &mut C) -> Result { +#[cacheable_dyn] +impl InitFragment for AwaitDependenciesInitFragment { + fn contents( + self: Box, + _context: &mut dyn InitFragmentRenderContext, + ) -> Result { if self.promises.is_empty() { Ok(InitFragmentContents { start: String::new(), @@ -620,6 +642,7 @@ impl InitFragment for AwaitDependenciesInitFrag } } +#[cacheable] #[derive(Debug, Clone, rspack_hash::RspackHash)] pub struct ConditionalInitFragment { content: String, @@ -683,8 +706,12 @@ impl ConditionalInitFragment { } } -impl InitFragment for ConditionalInitFragment { - fn contents(self: Box, context: &mut C) -> Result { +#[cacheable_dyn] +impl InitFragment for ConditionalInitFragment { + fn contents( + self: Box, + context: &mut dyn InitFragmentRenderContext, + ) -> Result { Ok( if matches!(self.runtime_condition, RuntimeCondition::Boolean(false)) || self.content.is_empty() @@ -736,6 +763,7 @@ fn wrap_in_condition(condition: &str, source: &str) -> String { ) } +#[cacheable] #[derive(Debug, Clone, rspack_hash::RspackHash)] pub struct ExternalModuleInitFragment { imported_module: String, @@ -807,8 +835,12 @@ impl ExternalModuleInitFragment { } } -impl InitFragment for ExternalModuleInitFragment { - fn contents(self: Box, _context: &mut C) -> Result { +#[cacheable_dyn] +impl InitFragment for ExternalModuleInitFragment { + fn contents( + self: Box, + _context: &mut dyn InitFragmentRenderContext, + ) -> Result { let mut named_imports = vec![]; for (name, specifiers) in self.import_specifiers { @@ -861,222 +893,3 @@ impl InitFragment for ExternalModuleInitFragmen &self.key } } - -#[cacheable] -#[derive(Debug, Clone)] -pub(crate) enum CachedChunkInitFragment { - Normal { - content: String, - stage: InitFragmentStage, - position: i32, - key: InitFragmentKey, - end_content: Option, - #[cacheable(with=rspack_cacheable::with::AsVec)] - top_level_decl_symbols: Vec, - }, - EsmExport { - exports_argument: ExportsArgument, - export_map: Vec, - is_circular_module: Option, - }, - AwaitDependencies { - promises: Vec, - }, - Conditional { - content: String, - stage: InitFragmentStage, - position: i32, - key: InitFragmentKey, - end_content: Option, - runtime_condition: RuntimeCondition, - }, - ExternalModule { - imported_module: String, - import_specifiers: Vec, - default_import: Option, - stage: InitFragmentStage, - position: i32, - }, -} - -#[cacheable] -#[derive(Debug, Clone)] -pub(crate) struct CachedEsmExportBindingEntry { - #[cacheable(with=AsPreset)] - name: Atom, - binding: CachedEsmExportBinding, -} - -#[cacheable] -#[derive(Debug, Clone)] -pub(crate) enum CachedEsmExportBinding { - Getter(#[cacheable(with=AsPreset)] Atom), - Value(#[cacheable(with=AsPreset)] Atom), -} - -#[cacheable] -#[derive(Debug, Clone)] -pub(crate) struct CachedExternalImportSpecifier { - name: String, - specifiers: Vec, -} - -impl CachedChunkInitFragment { - pub(crate) fn from_fragment(fragment: &BoxChunkInitFragment) -> Option { - if let Ok(fragment) = fragment.clone().into_any().downcast::() { - return Some(Self::Normal { - content: fragment.content, - stage: fragment.stage, - position: fragment.position, - key: fragment.key, - end_content: fragment.end_content, - top_level_decl_symbols: fragment.top_level_decl_symbols, - }); - } - - if let Ok(fragment) = fragment - .clone() - .into_any() - .downcast::() - { - return Some(Self::EsmExport { - exports_argument: fragment.exports_argument, - export_map: fragment - .export_map - .into_iter() - .map(|(name, binding)| CachedEsmExportBindingEntry { - name, - binding: match binding { - ESMExportBinding::Getter(value) => CachedEsmExportBinding::Getter(value), - ESMExportBinding::Value(value) => CachedEsmExportBinding::Value(value), - }, - }) - .collect(), - is_circular_module: fragment.is_circular_module, - }); - } - - if let Ok(fragment) = fragment - .clone() - .into_any() - .downcast::() - { - return Some(Self::AwaitDependencies { - promises: fragment.promises.into_iter().collect(), - }); - } - - if let Ok(fragment) = fragment - .clone() - .into_any() - .downcast::() - { - return Some(Self::Conditional { - content: fragment.content, - stage: fragment.stage, - position: fragment.position, - key: fragment.key, - end_content: fragment.end_content, - runtime_condition: fragment.runtime_condition, - }); - } - - if let Ok(fragment) = fragment - .clone() - .into_any() - .downcast::() - { - return Some(Self::ExternalModule { - imported_module: fragment.imported_module, - import_specifiers: fragment - .import_specifiers - .into_iter() - .map(|(name, specifiers)| CachedExternalImportSpecifier { - name, - specifiers: specifiers.into_iter().collect(), - }) - .collect(), - default_import: fragment.default_import, - stage: fragment.stage, - position: fragment.position, - }); - } - - None - } - - pub(crate) fn into_fragment(self) -> BoxChunkInitFragment { - match self { - Self::Normal { - content, - stage, - position, - key, - end_content, - top_level_decl_symbols, - } => Box::new( - NormalInitFragment::new(content, stage, position, key, end_content) - .with_top_level_decl_symbols(top_level_decl_symbols), - ), - Self::EsmExport { - exports_argument, - export_map, - is_circular_module, - } => Box::new(ESMExportInitFragment::new( - exports_argument, - export_map - .into_iter() - .map(|entry| { - ( - entry.name, - match entry.binding { - CachedEsmExportBinding::Getter(value) => ESMExportBinding::Getter(value), - CachedEsmExportBinding::Value(value) => ESMExportBinding::Value(value), - }, - ) - }) - .collect(), - is_circular_module, - )), - Self::AwaitDependencies { promises } => Box::new(AwaitDependenciesInitFragment::new( - promises.into_iter().collect(), - )), - Self::Conditional { - content, - stage, - position, - key, - end_content, - runtime_condition, - } => Box::new(ConditionalInitFragment::new( - content, - stage, - position, - key, - end_content, - runtime_condition, - )), - Self::ExternalModule { - imported_module, - import_specifiers, - default_import, - stage, - position, - } => Box::new(ExternalModuleInitFragment::new( - imported_module, - import_specifiers - .into_iter() - .flat_map(|item| { - item - .specifiers - .into_iter() - .map(move |specifier| (item.name.clone(), specifier)) - }) - .collect(), - default_import, - stage, - position, - )), - } - } -} diff --git a/crates/rspack_core/src/runtime_template.rs b/crates/rspack_core/src/runtime_template.rs index 51f78eed5b65..071b05c9991c 100644 --- a/crates/rspack_core/src/runtime_template.rs +++ b/crates/rspack_core/src/runtime_template.rs @@ -20,11 +20,10 @@ use swc_core::atoms::Atom; use crate::{ AsyncDependenciesBlockIdentifier, ChunkGraph, Compilation, CompilerOptions, DependenciesBlock, DependencyId, DependencyType, ExportsArgument, ExportsInfoArtifact, ExportsType, - FakeNamespaceObjectMode, GenerateContext, ImportPhase, InitFragment, InitFragmentExt, - InitFragmentKey, InitFragmentStage, Module, ModuleArgument, ModuleGraph, - ModuleGraphCacheArtifact, ModuleId, ModuleIdentifier, NormalInitFragment, PathInfo, - RuntimeCondition, RuntimeGlobals, RuntimeSpec, UsedName, compile_boolean_matcher_from_lists, - contextify, property_access, + FakeNamespaceObjectMode, ImportPhase, InitFragment, InitFragmentExt, InitFragmentKey, + InitFragmentStage, Module, ModuleArgument, ModuleGraph, ModuleGraphCacheArtifact, ModuleId, + ModuleIdentifier, NormalInitFragment, PathInfo, RuntimeCondition, RuntimeGlobals, RuntimeSpec, + UsedName, compile_boolean_matcher_from_lists, contextify, property_access, runtime_globals::{ RuntimeVariable, rspack_runtime_variable_name, runtime_globals_to_string, runtime_variable_name, runtime_variable_to_string, @@ -1190,7 +1189,7 @@ impl ModuleCodeTemplate { pub fn export_from_import( &mut self, compilation: &Compilation, - init_fragments: &mut Vec>>>, + init_fragments: &mut Vec>, module_id: Identifier, runtime: Option<&RuntimeSpec>, default_interop: bool, diff --git a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs index d90dd22fd3e0..7ac9ea47e395 100644 --- a/crates/rspack_plugin_css/src/parser_and_generator/mod.rs +++ b/crates/rspack_plugin_css/src/parser_and_generator/mod.rs @@ -8,9 +8,12 @@ use std::{ }; use regex::Regex; -use rspack_cacheable::{cacheable, cacheable_dyn}; +use rspack_cacheable::{ + cacheable, cacheable_dyn, + with::{AsPreset, AsVec}, +}; use rspack_core::{ - BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, Compilation, + BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, CodeGenerationDataItem, Compilation, CssAutoOrModuleParserOptions, CssBuildInfo, CssExportType, DependencyType, ExportsInfoArtifact, GenerateContext, Module, ModuleGraph, ModuleIdentifier, NormalModule, ParseContext, ParseResult, ParserAndGenerator, ParserOptions, ResolvedModuleOptions, RuntimeSpec, SourceType, UsageState, @@ -133,11 +136,16 @@ pub fn get_used_exports<'a>( ) } +#[cacheable] #[derive(Debug, Clone)] pub struct CodeGenerationDataUnusedLocalIdent { + #[cacheable(with=AsVec)] pub(crate) idents: FxHashSet, } +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataUnusedLocalIdent {} + pub fn get_unused_local_ident( css_build_info: &CssBuildInfo, identifier: ModuleIdentifier, diff --git a/crates/rspack_plugin_esm_library/src/link.rs b/crates/rspack_plugin_esm_library/src/link.rs index fe4bfe529650..074b40adc4df 100644 --- a/crates/rspack_plugin_esm_library/src/link.rs +++ b/crates/rspack_plugin_esm_library/src/link.rs @@ -7,13 +7,13 @@ use std::{ use rayon::{iter::Either, prelude::*}; use rspack_collections::{IdentifierIndexMap, IdentifierIndexSet, IdentifierMap}; use rspack_core::{ - BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, ChunkInitFragments, ChunkRenderContext, - ChunkUkey, CodeGenerationPublicPathAutoReplace, Compilation, ConcatenatedModuleIdent, - ConditionalInitFragment, DependencyType, ExportInfo, ExportMode, ExportProvided, - ExportsInfoArtifact, ExportsType, FindTargetResult, ImportSpec, InitFragmentKey, ModuleGraph, - ModuleGraphCacheArtifact, ModuleIdentifier, ModuleInfo, NAMESPACE_OBJECT_EXPORT, PathData, - RuntimeGlobals, SideEffectsStateArtifact, SourceType, URLStaticMode, UsageState, UsedName, - UsedNameItem, collect_ident, escape_name_atom_ref, find_new_name, find_target, + BuildMetaDefaultObject, BuildMetaExportsType, ChunkGraph, ChunkInitFragments, ChunkUkey, + CodeGenerationDataChunkInitFragments, CodeGenerationPublicPathAutoReplace, Compilation, + ConcatenatedModuleIdent, ConditionalInitFragment, DependencyType, ExportInfo, ExportMode, + ExportProvided, ExportsInfoArtifact, ExportsType, FindTargetResult, ImportSpec, InitFragmentKey, + ModuleGraph, ModuleGraphCacheArtifact, ModuleIdentifier, ModuleInfo, NAMESPACE_OBJECT_EXPORT, + PathData, RuntimeGlobals, SideEffectsStateArtifact, SourceType, URLStaticMode, UsageState, + UsedName, UsedNameItem, collect_ident, escape_name_atom_ref, find_new_name, find_target, get_cached_readable_identifier, get_js_chunk_filename_template, get_module_directives, get_module_hashbang, property_access, property_name, reserved_names::RESERVED_NAMES_ATOM_SET, rspack_sources::ReplaceSource, split_readable_identifier, to_normal_comment, @@ -75,7 +75,7 @@ enum ExternalImportBinding { impl EsmLibraryPlugin { fn module_external_fragment_content( - init_fragment: Box>, + init_fragment: Box, ) -> Option { if !matches!(init_fragment.key(), InitFragmentKey::ModuleExternal(_)) { return None; @@ -90,7 +90,7 @@ impl EsmLibraryPlugin { } else { init_fragment .clone() - .contents(&mut ChunkRenderContext {}) + .contents(&mut rspack_core::ChunkRenderContext {}) .ok() .map(|contents| contents.start) } @@ -98,7 +98,7 @@ impl EsmLibraryPlugin { fn collect_module_external_fragments_in_render_order<'a>( init_fragment_groups: impl IntoIterator, - ) -> Vec>> { + ) -> Vec> { let mut ordered_fragments = Vec::new(); for init_fragments in init_fragment_groups { @@ -1470,8 +1470,8 @@ var {} = {{}}; } let mut chunk_init_fragments = codegen_res .data - .get::() - .cloned() + .get::() + .map(|fragments| fragments.inner().clone()) .unwrap_or_default(); chunk_init_fragments.extend(codegen_res.chunk_init_fragments.clone()); Ok(( @@ -1612,8 +1612,8 @@ var {} = {{}}; concate_info.runtime_requirements = codegen_res.runtime_requirements; concate_info.chunk_init_fragments = codegen_res .data - .get::() - .cloned() + .get::() + .map(|fragments| fragments.inner().clone()) .unwrap_or_default(); concate_info .chunk_init_fragments diff --git a/crates/rspack_plugin_esm_library/src/render.rs b/crates/rspack_plugin_esm_library/src/render.rs index 8db9fc7a5a8c..919acb946824 100644 --- a/crates/rspack_plugin_esm_library/src/render.rs +++ b/crates/rspack_plugin_esm_library/src/render.rs @@ -144,7 +144,7 @@ impl EsmLibraryPlugin { let chunk_link_guard = self.links.borrow(); let chunk_link = &chunk_link_guard[chunk_ukey]; - let mut chunk_init_fragments: Vec + 'static>> = + let mut chunk_init_fragments: Vec> = chunk_link.init_fragments.clone(); let mut replace_auto_public_path = false; diff --git a/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs b/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs index d9fb1f12b814..967d3c5c2b03 100644 --- a/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs +++ b/crates/rspack_plugin_javascript/src/dependency/esm/esm_export_imported_specifier_dependency.rs @@ -952,7 +952,7 @@ impl ESMExportImportedSpecifierDependency { fn get_conditional_reexport_statement( &self, - ctxt: &mut TemplateContext<'_, '_, '_>, + ctxt: &mut TemplateContext<'_, '_>, key: Atom, name: &String, first_value_key: Atom, diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index ef1fab0c39b2..2b294ef58f82 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -1,8 +1,8 @@ use rayon::prelude::*; use rspack_core::{ ChunkCodeTemplate, ChunkGraph, ChunkInitFragments, ChunkKind, ChunkUkey, - CodeGenerationPublicPathAutoReplace, Compilation, Module, RuntimeGlobals, - RuntimeModuleGenerateContext, SourceType, + CodeGenerationDataChunkInitFragments, CodeGenerationPublicPathAutoReplace, Compilation, Module, + RuntimeGlobals, RuntimeModuleGenerateContext, SourceType, chunk_graph_chunk::ChunkIdSet, get_undo_path, render_runtime_module_source, rspack_sources::{ @@ -131,8 +131,11 @@ pub async fn render_module( return Ok(None); }; - let mut module_chunk_init_fragments = match code_gen_result.data.get::() { - Some(fragments) => fragments.clone(), + let mut module_chunk_init_fragments = match code_gen_result + .data + .get::() + { + Some(fragments) => fragments.inner().clone(), None => ChunkInitFragments::default(), }; diff --git a/crates/rspack_plugin_mf/src/container/container_entry_module.rs b/crates/rspack_plugin_mf/src/container/container_entry_module.rs index 6cae0e887a86..c64ba1b1554a 100644 --- a/crates/rspack_plugin_mf/src/container/container_entry_module.rs +++ b/crates/rspack_plugin_mf/src/container/container_entry_module.rs @@ -5,12 +5,13 @@ use rspack_cacheable::{cacheable, cacheable_dyn}; use rspack_collections::{Identifiable, Identifier}; use rspack_core::{ AsyncDependenciesBlock, AsyncDependenciesBlockIdentifier, BoxDependency, BoxModule, BuildContext, - BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult, ChunkGroupOptions, CodeGenerationResult, - CodeGenerationRuntimeRequirementsWrite, Compilation, Context, DependenciesBlock, Dependency, - DependencyId, DependencyType, ExportsArgument, FactoryMeta, GroupOptions, LibIdentOptions, - Module, ModuleCodeGenerationContext, ModuleCodeTemplate, ModuleDependency, ModuleGraph, - ModuleIdentifier, ModuleType, RuntimeGlobals, RuntimeSpec, SourceType, StaticExportsDependency, - StaticExportsSpec, impl_module_meta_info, impl_source_map_config, module_update_hash, + BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult, ChunkGroupOptions, + CodeGenerationDataItem, CodeGenerationResult, CodeGenerationRuntimeRequirementsWrite, + Compilation, Context, DependenciesBlock, Dependency, DependencyId, DependencyType, + ExportsArgument, FactoryMeta, GroupOptions, LibIdentOptions, Module, ModuleCodeGenerationContext, + ModuleCodeTemplate, ModuleDependency, ModuleGraph, ModuleIdentifier, ModuleType, RuntimeGlobals, + RuntimeSpec, SourceType, StaticExportsDependency, StaticExportsSpec, impl_module_meta_info, + impl_source_map_config, module_update_hash, rspack_sources::{BoxSource, RawStringSource, SourceExt}, }; use rspack_error::{Result, impl_empty_diagnosable_trait}; @@ -441,6 +442,7 @@ var init = function(shareScope, initScope) {{ impl_empty_diagnosable_trait!(ContainerEntryModule); +#[cacheable] #[derive(Debug, Clone)] pub struct ExposeModuleMap(Vec<(String, String)>); @@ -515,9 +517,13 @@ impl ExposeModuleMap { } } +#[cacheable] #[derive(Debug, Clone)] pub struct CodeGenerationDataExpose { pub module_map: ExposeModuleMap, pub module_map_runtime_requirements: RuntimeGlobals, pub share_scope: ShareScope, } + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataExpose {} diff --git a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs index c4f442643f0f..3da1aa121ed3 100644 --- a/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/consume_shared_runtime_module.rs @@ -1,9 +1,10 @@ use std::{collections::BTreeMap, sync::LazyLock}; +use rspack_cacheable::{cacheable, cacheable_dyn}; use rspack_core::{ - Chunk, ChunkGraph, Compilation, ModuleIdentifier, RuntimeGlobals, RuntimeModule, - RuntimeModuleGenerateContext, RuntimeModuleRuntimeRequirements, RuntimeModuleStage, - RuntimeTemplate, SourceType, impl_runtime_module, + Chunk, ChunkGraph, CodeGenerationDataItem, Compilation, ModuleIdentifier, RuntimeGlobals, + RuntimeModule, RuntimeModuleGenerateContext, RuntimeModuleRuntimeRequirements, + RuntimeModuleStage, RuntimeTemplate, SourceType, impl_runtime_module, }; use rspack_plugin_runtime::extract_runtime_globals_from_ejs; use rspack_util::json_stringify_str; @@ -244,6 +245,7 @@ impl RuntimeModule for ConsumeSharedRuntimeModule { } } +#[cacheable] #[derive(Debug, Clone)] pub struct CodeGenerationDataConsumeShared { pub share_scope: ShareScope, @@ -256,3 +258,6 @@ pub struct CodeGenerationDataConsumeShared { pub fallback: Option, pub tree_shaking_mode: Option, } + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataConsumeShared {} diff --git a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs index 599f751ff2f3..456892915816 100644 --- a/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs +++ b/crates/rspack_plugin_mf/src/sharing/share_runtime_module.rs @@ -1,9 +1,11 @@ use std::sync::LazyLock; use itertools::Itertools; +use rspack_cacheable::{cacheable, cacheable_dyn}; use rspack_core::{ - Compilation, ModuleId, RuntimeGlobals, RuntimeModule, RuntimeModuleGenerateContext, - RuntimeModuleRuntimeRequirements, RuntimeTemplate, SourceType, impl_runtime_module, + CodeGenerationDataItem, Compilation, ModuleId, RuntimeGlobals, RuntimeModule, + RuntimeModuleGenerateContext, RuntimeModuleRuntimeRequirements, RuntimeTemplate, SourceType, + impl_runtime_module, }; use rspack_plugin_runtime::extract_runtime_globals_from_ejs; use rspack_util::{ @@ -178,11 +180,13 @@ impl RuntimeModule for ShareRuntimeModule { } } +#[cacheable] #[derive(Debug, Clone)] pub struct CodeGenerationDataShareInit { pub items: Vec, } +#[cacheable] #[derive(Debug, Clone)] pub struct ShareInitData { pub share_scope: ShareScope, @@ -192,12 +196,14 @@ pub struct ShareInitData { pub type DataInitStage = i8; +#[cacheable] #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub enum DataInitInfo { ExternalModuleId(Option), ProvideSharedInfo(ProvideSharedInfo), } +#[cacheable] #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ProvideSharedInfo { pub name: String, @@ -209,3 +215,6 @@ pub struct ProvideSharedInfo { pub strict_version: Option, pub tree_shaking_mode: Option, } + +#[cacheable_dyn] +impl CodeGenerationDataItem for CodeGenerationDataShareInit {} diff --git a/crates/rspack_plugin_rstest/src/esm_import_dependency.rs b/crates/rspack_plugin_rstest/src/esm_import_dependency.rs index 3b1181b1f5b7..c84bb81fa9b5 100644 --- a/crates/rspack_plugin_rstest/src/esm_import_dependency.rs +++ b/crates/rspack_plugin_rstest/src/esm_import_dependency.rs @@ -98,7 +98,7 @@ fn hoist_new_esm_import_fragments( continue; }; - let cloned: Box> = fragment.clone(); + let cloned: Box = fragment.clone(); let Ok(conditional_fragment) = cloned .into_any() .downcast::() diff --git a/crates/rspack_plugin_rstest/src/mock_method_dependency.rs b/crates/rspack_plugin_rstest/src/mock_method_dependency.rs index f26d37a4b280..614ad560efda 100644 --- a/crates/rspack_plugin_rstest/src/mock_method_dependency.rs +++ b/crates/rspack_plugin_rstest/src/mock_method_dependency.rs @@ -194,7 +194,7 @@ impl MockMethodDependencyTemplate { /// Add a placeholder init fragment that marks where hoisted code should be inserted fn add_placeholder_fragment( - init_fragments: &mut Vec>>>, + init_fragments: &mut Vec>, flag: &str, hoist_id: &str, request: &str, @@ -217,9 +217,7 @@ impl MockMethodDependencyTemplate { /// We achieve this by inserting a higher-priority fragment with the same key. /// Since ESMImport's merge logic returns the first fragment when its runtime_condition is true, /// our new fragment will take precedence and the original will be ignored. - fn hoist_rstest_core_import( - init_fragments: &mut Vec>>>, - ) { + fn hoist_rstest_core_import(init_fragments: &mut Vec>) { let target_key = InitFragmentKey::ESMImport("ESM import external global \"@rstest/core\"".to_string()); @@ -229,7 +227,7 @@ impl MockMethodDependencyTemplate { }; // Clone and downcast to get the content - let cloned: Box> = fragment.clone(); + let cloned: Box = fragment.clone(); let Ok(conditional_fragment) = cloned.into_any().downcast::() else { return; }; From 73efedd10b06819bb072037de08cea530f95bbec Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Wed, 8 Jul 2026 19:45:41 +0800 Subject: [PATCH 3/7] Persist code generation result id in compiler context --- .../src/artifacts/code_generation_results.rs | 34 ++----------------- .../src/cache/persistent/occasion/meta/mod.rs | 13 ++++++- .../occasion/modules_codegen/mod.rs | 1 - crates/rspack_tasks/src/lib.rs | 30 ++++++++++++++++ 4 files changed, 45 insertions(+), 33 deletions(-) diff --git a/crates/rspack_core/src/artifacts/code_generation_results.rs b/crates/rspack_core/src/artifacts/code_generation_results.rs index faf64848190d..4cea93cf0a7c 100644 --- a/crates/rspack_core/src/artifacts/code_generation_results.rs +++ b/crates/rspack_core/src/artifacts/code_generation_results.rs @@ -1,8 +1,4 @@ -use std::{ - collections::hash_map::Entry, - fmt::Debug, - sync::atomic::{AtomicU32, Ordering}, -}; +use std::{collections::hash_map::Entry, fmt::Debug}; use dyn_clone::{DynClone, clone_trait_object}; use rspack_cacheable::{ @@ -12,6 +8,7 @@ use rspack_cacheable::{ use rspack_collections::IdentifierMap; use rspack_hash::{HashDigest, HashFunction, HashSalt, RspackHash, RspackHashDigest, RspackHasher}; use rspack_sources::BoxSource; +use rspack_tasks::fetch_new_code_generation_result_id; use rspack_util::{ atom::Atom, ext::{AsAny, IntoAny}, @@ -299,12 +296,10 @@ pub struct CodeGenResultId(u32); impl Default for CodeGenResultId { fn default() -> Self { - Self(CODE_GEN_RESULT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed)) + Self(fetch_new_code_generation_result_id()) } } -pub static CODE_GEN_RESULT_ID: AtomicU32 = AtomicU32::new(0); - #[cacheable] #[derive(Debug, Default, Clone)] pub struct CodeGenerationResults { @@ -505,29 +500,6 @@ impl CodeGenerationResults { ) { (&self.map, &self.module_generation_result_map) } - - pub(crate) fn sync_code_generation_result_id(&self) { - if let Some(next) = self - .module_generation_result_map - .keys() - .map(|id| id.0) - .max() - .and_then(|id| id.checked_add(1)) - { - let mut current = CODE_GEN_RESULT_ID.load(Ordering::Relaxed); - while current < next { - match CODE_GEN_RESULT_ID.compare_exchange_weak( - current, - next, - Ordering::Relaxed, - Ordering::Relaxed, - ) { - Ok(_) => break, - Err(value) => current = value, - } - } - } - } } #[derive(Debug)] diff --git a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs index 54df77b1acec..92af8b1005bc 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs @@ -2,7 +2,10 @@ use std::sync::Arc; use rspack_cacheable::cacheable; use rspack_error::Result; -use rspack_tasks::{get_current_dependency_id, set_current_dependency_id}; +use rspack_tasks::{ + get_current_code_generation_result_id, get_current_dependency_id, + set_current_code_generation_result_id, set_current_dependency_id, +}; use super::{ super::{codec::CacheCodec, storage::Storage}, @@ -15,6 +18,7 @@ pub const SCOPE: &str = "meta"; #[cacheable] struct Meta { pub max_dependencies_id: u32, + pub max_code_generation_result_id: u32, } /// Meta Occasion is used to save compiler state. @@ -46,6 +50,7 @@ impl Occasion for MetaOccasion { fn save(&self, storage: &mut dyn Storage, _artifact: &()) { let meta = Meta { max_dependencies_id: get_current_dependency_id(), + max_code_generation_result_id: get_current_code_generation_result_id(), }; storage.set( SCOPE, @@ -64,7 +69,13 @@ impl Occasion for MetaOccasion { if get_current_dependency_id() != 0 { panic!("The global dependency id generator is not 0 when the persistent cache is restored."); } + if get_current_code_generation_result_id() != 0 { + panic!( + "The global code generation result id generator is not 0 when the persistent cache is restored." + ); + } set_current_dependency_id(meta.max_dependencies_id); + set_current_code_generation_result_id(meta.max_code_generation_result_id); Ok(()) } } diff --git a/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs index ffd11f74ff9d..d4ea77740305 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/modules_codegen/mod.rs @@ -59,7 +59,6 @@ impl Occasion for ModulesCodegenOccasion { }; let artifact = self.codec.decode::(&value)?; - artifact.sync_code_generation_result_id(); tracing::debug!("recovered modules codegen persistent cache artifact"); Ok(artifact) } diff --git a/crates/rspack_tasks/src/lib.rs b/crates/rspack_tasks/src/lib.rs index c8e3647e0d45..e4be41199d02 100644 --- a/crates/rspack_tasks/src/lib.rs +++ b/crates/rspack_tasks/src/lib.rs @@ -18,6 +18,7 @@ use tokio::{ #[derive(Debug)] pub struct CompilerContext { dependenc_id_generator: AtomicU32, + code_generation_result_id_generator: AtomicU32, exports_info_artifact_ptr: AtomicPtr, } @@ -30,6 +31,7 @@ impl CompilerContext { pub fn new() -> Self { Self { dependenc_id_generator: AtomicU32::new(0), + code_generation_result_id_generator: AtomicU32::new(0), exports_info_artifact_ptr: AtomicPtr::new(std::ptr::null_mut()), } } @@ -48,6 +50,21 @@ impl CompilerContext { .dependenc_id_generator .store(id, std::sync::atomic::Ordering::SeqCst); } + pub fn fetch_new_code_generation_result_id(&self) -> u32 { + self + .code_generation_result_id_generator + .fetch_add(1, std::sync::atomic::Ordering::SeqCst) + } + pub fn code_generation_result_id(&self) -> u32 { + self + .code_generation_result_id_generator + .load(std::sync::atomic::Ordering::SeqCst) + } + pub fn set_code_generation_result_id(&self, id: u32) { + self + .code_generation_result_id_generator + .store(id, std::sync::atomic::Ordering::SeqCst); + } pub fn exports_info_artifact_ptr(&self) -> Option<*mut c_void> { let ptr = self @@ -73,6 +90,19 @@ pub fn get_current_dependency_id() -> u32 { pub fn set_current_dependency_id(id: u32) { CURRENT_COMPILER_CONTEXT.get().set_dependency_id(id); } +pub fn fetch_new_code_generation_result_id() -> u32 { + CURRENT_COMPILER_CONTEXT + .get() + .fetch_new_code_generation_result_id() +} +pub fn get_current_code_generation_result_id() -> u32 { + CURRENT_COMPILER_CONTEXT.get().code_generation_result_id() +} +pub fn set_current_code_generation_result_id(id: u32) { + CURRENT_COMPILER_CONTEXT + .get() + .set_code_generation_result_id(id); +} pub fn within_compiler_context( compiler_context: Arc, From 9bbce32abc6443efad77d5973075bdcf17f14920 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Fri, 10 Jul 2026 15:35:29 +0800 Subject: [PATCH 4/7] test --- crates/rspack_core/src/compiler/mod.rs | 10 +-- .../__snapshots__/stats-0.txt | 23 +++++ .../__snapshots__/stats-1.txt | 24 +++++ .../__snapshots__/stats-2.txt | 8 ++ .../module-codegen-cache/async-module.js | 5 ++ .../common/module-codegen-cache/file.js | 5 ++ .../common/module-codegen-cache/index.js | 21 +++++ .../module-codegen-cache/rspack.config.js | 89 +++++++++++++++++++ .../common/module-codegen-cache/stable.js | 5 ++ 9 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-0.txt create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-1.txt create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-2.txt create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/async-module.js create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/file.js create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/index.js create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js create mode 100644 tests/rspack-test/cacheCases/common/module-codegen-cache/stable.js diff --git a/crates/rspack_core/src/compiler/mod.rs b/crates/rspack_core/src/compiler/mod.rs index b538358a689f..b9a8218528a7 100644 --- a/crates/rspack_core/src/compiler/mod.rs +++ b/crates/rspack_core/src/compiler/mod.rs @@ -273,11 +273,11 @@ impl Compiler { ); let is_hot = self.cache.before_compile(&mut self.compilation).await; if is_hot { - let passes = self - .options - .incremental - .passes - .intersection(IncrementalPasses::BUILD_MODULE_GRAPH | IncrementalPasses::MODULES_HASHES); + let passes = self.options.incremental.passes.intersection( + IncrementalPasses::BUILD_MODULE_GRAPH + | IncrementalPasses::MODULES_HASHES + | IncrementalPasses::MODULES_CODEGEN, + ); if !passes.is_empty() { self.compilation.incremental = Incremental::new_hot(IncrementalOptions { silent: self.options.incremental.silent, diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-0.txt new file mode 100644 index 000000000000..c7099b399675 --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-0.txt @@ -0,0 +1,23 @@ +DEBUG LOG from rspack.persistentCache + persistent cache enabled + build dependencies are valid (0 tracked) + validate build dependencies: xx ms + meta persistent cache recovery succeeded + read meta from persistent cache: xx ms + read snapshot from persistent cache: xx ms + make persistent cache recovery succeeded + read make from persistent cache: xx ms + write make to persistent cache: xx ms + module hashes persistent cache recovery succeeded + read module hashes from persistent cache: xx ms + write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms + minimize persistent cache recovery succeeded + read minimize from persistent cache: xx ms + write minimize to persistent cache: xx ms + write meta to persistent cache: xx ms + write snapshot to persistent cache: xx ms + write build dependencies to persistent cache: xx ms + stage persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-1.txt new file mode 100644 index 000000000000..5c6f1ff3ae5a --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-1.txt @@ -0,0 +1,24 @@ +DEBUG LOG from rspack.persistentCache + persistent cache enabled + build dependencies are valid (0 tracked) + validate build dependencies: xx ms + meta persistent cache recovery succeeded + read meta from persistent cache: xx ms + read snapshot from persistent cache: xx ms + snapshot restored with no changed dependencies + make persistent cache recovery succeeded + read make from persistent cache: xx ms + write make to persistent cache: xx ms + module hashes persistent cache recovery succeeded + read module hashes from persistent cache: xx ms + write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms + minimize persistent cache recovery succeeded + read minimize from persistent cache: xx ms + write minimize to persistent cache: xx ms + write meta to persistent cache: xx ms + write snapshot to persistent cache: xx ms + write build dependencies to persistent cache: xx ms + stage persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-2.txt new file mode 100644 index 000000000000..62bd1a999e3b --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/__snapshots__/stats-2.txt @@ -0,0 +1,8 @@ +DEBUG LOG from rspack.persistentCache + write make to persistent cache: xx ms + write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms + write meta to persistent cache: xx ms + write snapshot to persistent cache: xx ms + write build dependencies to persistent cache: xx ms + stage persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/async-module.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/async-module.js new file mode 100644 index 000000000000..e333370e9d4c --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/async-module.js @@ -0,0 +1,5 @@ +export const value = 42; +--- +export const value = 42; +--- +export const value = 42; diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/file.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/file.js new file mode 100644 index 000000000000..ae2a3a04fdf2 --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/file.js @@ -0,0 +1,5 @@ +export default 1; +--- +export default 1; +--- +export default 2; diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/index.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/index.js new file mode 100644 index 000000000000..99ab72f6474f --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/index.js @@ -0,0 +1,21 @@ +import value from "./file"; +import { stable } from "./stable"; + +it("should reduce affected modules in module codegen on persistent cache restart", async () => { + const asyncMod = await import("./async-module"); + + expect(value).toBe(1); + expect(stable).toBe("stable"); + expect(asyncMod.value).toBe(42); + + if (COMPILER_INDEX == 0) { + await NEXT_START(); + } + if (COMPILER_INDEX == 1) { + expect(value).toBe(1); + await NEXT_HMR(); + expect(value).toBe(2); + } +}); + +module.hot.accept("./file"); diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js new file mode 100644 index 000000000000..0af51353da87 --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js @@ -0,0 +1,89 @@ +let updateIndex = 0; + +const MODULES_HASHES_LOGGER_NAME = 'rspack.incremental.modulesHashes'; +const MODULES_CODEGEN_LOGGER_NAME = 'rspack.incremental.modulesCodegen'; + +function getAffectedLogEntry(logging, loggerName) { + return (logging?.[loggerName]?.entries ?? []).find( + (e) => + e.type === 'log' && + typeof e.message === 'string' && + e.message.includes('modules are affected'), + ); +} + +function parseAffectedLogEntry(entry) { + const match = entry?.message.match( + /(\d+) modules are affected, (\d+) in total/, + ); + expect(match).toBeTruthy(); + return { + affected: Number(match[1]), + total: Number(match[2]), + }; +} + +/** @type {import("@rspack/core").Configuration} */ +module.exports = { + context: __dirname, + mode: 'development', + cache: { + type: 'persistent', + }, + incremental: { + buildModuleGraph: true, + modulesHashes: true, + modulesCodegen: true, + }, + optimization: { + concatenateModules: false, + innerGraph: false, + mangleExports: false, + providedExports: false, + usedExports: false, + }, + plugins: [ + { + apply(compiler) { + compiler.hooks.done.tap('ModuleCodegenPersistentCacheTest', (stats) => { + const s = stats.toJson({ + all: false, + logging: 'verbose', + }); + const modulesCodegenAffectedLogEntry = getAffectedLogEntry( + s.logging, + MODULES_CODEGEN_LOGGER_NAME, + ); + + if (updateIndex === 0) { + expect(modulesCodegenAffectedLogEntry).toBeUndefined(); + } + + if (updateIndex === 2) { + expect(modulesCodegenAffectedLogEntry).toBeTruthy(); + const modulesHashesAffectedLogEntry = getAffectedLogEntry( + s.logging, + MODULES_HASHES_LOGGER_NAME, + ); + expect(modulesHashesAffectedLogEntry).toBeTruthy(); + const modulesCodegen = parseAffectedLogEntry( + modulesCodegenAffectedLogEntry, + ); + expect(modulesCodegen.total).toBeGreaterThan(0); + if (modulesCodegen.affected >= modulesCodegen.total) { + throw new Error( + [ + `Expected module codegen affected modules to be less than total modules.`, + `modulesHashes: ${modulesHashesAffectedLogEntry?.message}`, + `modulesCodegen: ${modulesCodegenAffectedLogEntry.message}`, + ].join('\n'), + ); + } + } + + updateIndex++; + }); + }, + }, + ], +}; diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/stable.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/stable.js new file mode 100644 index 000000000000..11b18604919e --- /dev/null +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/stable.js @@ -0,0 +1,5 @@ +export const stable = "stable"; +--- +export const stable = "stable"; +--- +export const stable = "stable"; From 529222c599336500feb87e5fbc061d68a43adce4 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Fri, 10 Jul 2026 16:15:50 +0800 Subject: [PATCH 5/7] fix: harden module codegen persistent cache --- .../rspack_core/src/cache/persistent/mod.rs | 18 ++++++- .../src/cache/persistent/occasion/meta/mod.rs | 51 ++++++++++++++++++- crates/rspack_core/src/init_fragment.rs | 8 +-- crates/rspack_tasks/src/lib.rs | 30 +++++++++++ .../common/basic/__snapshots__/stats-0.txt | 3 ++ .../common/basic/__snapshots__/stats-1.txt | 1 + .../common/basic/__snapshots__/stats-2.txt | 3 ++ .../common/basic/__snapshots__/stats-3.txt | 1 + .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 1 + .../__snapshots__/stats-2.txt | 1 + .../__snapshots__/stats-3.txt | 1 + .../__snapshots__/stats-4.txt | 1 + .../__snapshots__/stats-5.txt | 1 + .../__snapshots__/stats-6.txt | 1 + .../__snapshots__/stats-7.txt | 1 + .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 1 + .../__snapshots__/stats-2.txt | 3 ++ .../__snapshots__/stats-3.txt | 1 + .../__snapshots__/stats-4.txt | 3 ++ .../__snapshots__/stats-5.txt | 1 + .../__snapshots__/stats-6.txt | 3 ++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../__snapshots__/stats-2.txt | 1 + .../__snapshots__/stats-3.txt | 1 + .../__snapshots__/stats-4.txt | 3 ++ .../__snapshots__/stats-5.txt | 1 + .../minimize-cache/__snapshots__/stats-0.txt | 3 ++ .../minimize-cache/__snapshots__/stats-1.txt | 3 ++ .../minimize-cache/__snapshots__/stats-2.txt | 3 ++ .../minimize-cache/__snapshots__/stats-3.txt | 3 ++ .../minimize-cache/__snapshots__/stats-4.txt | 3 ++ .../minimize-cache/__snapshots__/stats-5.txt | 1 + .../module-asset/__snapshots__/stats-0.txt | 3 ++ .../module-asset/__snapshots__/stats-1.txt | 1 + .../module-asset/__snapshots__/stats-2.txt | 3 ++ .../module-asset/__snapshots__/stats-3.txt | 1 + .../module-codegen-cache/rspack.config.js | 10 ++++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../common/readonly/__snapshots__/stats-0.txt | 3 ++ .../common/readonly/__snapshots__/stats-1.txt | 2 + .../common/readonly/__snapshots__/stats-2.txt | 2 + .../common/readonly/__snapshots__/stats-3.txt | 3 ++ .../common/readonly/__snapshots__/stats-4.txt | 2 + .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../__snapshots__/stats-2.txt | 3 ++ .../update-file/__snapshots__/stats-0.txt | 3 ++ .../update-file/__snapshots__/stats-1.txt | 1 + .../update-file/__snapshots__/stats-2.txt | 3 ++ .../update-file/__snapshots__/stats-3.txt | 3 ++ .../update-file/__snapshots__/stats-4.txt | 3 ++ .../common/version/__snapshots__/stats-0.txt | 3 ++ .../common/version/__snapshots__/stats-1.txt | 1 + .../common/version/__snapshots__/stats-2.txt | 3 ++ .../common/version/__snapshots__/stats-3.txt | 1 + .../config-mode/__snapshots__/stats-0.txt | 3 ++ .../config-mode/__snapshots__/stats-1.txt | 1 + .../config-mode/__snapshots__/stats-2.txt | 3 ++ .../config-mode/__snapshots__/stats-3.txt | 1 + .../config-name/__snapshots__/stats-0.txt | 3 ++ .../config-name/__snapshots__/stats-1.txt | 1 + .../config-name/__snapshots__/stats-2.txt | 3 ++ .../config-name/__snapshots__/stats-3.txt | 1 + .../lib-symlink/__snapshots__/stats-0.txt | 3 ++ .../lib-symlink/__snapshots__/stats-1.txt | 3 ++ .../define-plugin/__snapshots__/stats-0.txt | 3 ++ .../define-plugin/__snapshots__/stats-1.txt | 3 ++ .../define-plugin/__snapshots__/stats-2.txt | 3 ++ .../define-plugin/__snapshots__/stats-3.txt | 3 ++ .../isolated_module/__snapshots__/stats-0.txt | 3 ++ .../isolated_module/__snapshots__/stats-1.txt | 1 + .../isolated_module/__snapshots__/stats-2.txt | 3 ++ .../isolated_module/__snapshots__/stats-3.txt | 1 + .../issuer-update/__snapshots__/stats-0.txt | 3 ++ .../issuer-update/__snapshots__/stats-1.txt | 1 + .../issuer-update/__snapshots__/stats-2.txt | 3 ++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../lazy-barrel/__snapshots__/stats-0.txt | 3 ++ .../lazy-barrel/__snapshots__/stats-1.txt | 1 + .../lazy-barrel/__snapshots__/stats-2.txt | 3 ++ .../lazy-barrel/__snapshots__/stats-3.txt | 1 + .../lazy-barrel/__snapshots__/stats-4.txt | 3 ++ .../lazy-barrel/__snapshots__/stats-5.txt | 1 + .../provide-plugin/__snapshots__/stats-0.txt | 3 ++ .../provide-plugin/__snapshots__/stats-1.txt | 3 ++ .../provide-plugin/__snapshots__/stats-2.txt | 3 ++ .../provide-plugin/__snapshots__/stats-3.txt | 3 ++ .../refactorize_dep/__snapshots__/stats-0.txt | 3 ++ .../refactorize_dep/__snapshots__/stats-1.txt | 1 + .../refactorize_dep/__snapshots__/stats-2.txt | 3 ++ .../mf/issue-9150/__snapshots__/stats-0.txt | 3 ++ .../mf/issue-9150/__snapshots__/stats-1.txt | 1 + .../mf/issue-9150/__snapshots__/stats-2.txt | 3 ++ .../mf/issue-9150/__snapshots__/stats-3.txt | 1 + .../portable/basic/__snapshots__/stats-0.txt | 3 ++ .../portable/basic/__snapshots__/stats-1.txt | 3 ++ .../portable/basic/__snapshots__/stats-2.txt | 3 ++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../__snapshots__/stats-2.txt | 3 ++ .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../__snapshots__/stats-2.txt | 3 ++ .../default_value/__snapshots__/stats-0.txt | 3 ++ .../default_value/__snapshots__/stats-1.txt | 1 + .../default_value/__snapshots__/stats-2.txt | 3 ++ .../default_value/__snapshots__/stats-3.txt | 1 + .../immutable-paths/__snapshots__/stats-0.txt | 3 ++ .../immutable-paths/__snapshots__/stats-1.txt | 1 + .../immutable-paths/__snapshots__/stats-2.txt | 3 ++ .../immutable-paths/__snapshots__/stats-3.txt | 1 + .../managed-paths/__snapshots__/stats-0.txt | 3 ++ .../managed-paths/__snapshots__/stats-1.txt | 1 + .../managed-paths/__snapshots__/stats-2.txt | 3 ++ .../managed-paths/__snapshots__/stats-3.txt | 1 + .../__snapshots__/stats-0.txt | 3 ++ .../__snapshots__/stats-1.txt | 3 ++ .../unmanaged-paths/__snapshots__/stats-0.txt | 3 ++ .../unmanaged-paths/__snapshots__/stats-1.txt | 1 + .../unmanaged-paths/__snapshots__/stats-2.txt | 3 ++ .../unmanaged-paths/__snapshots__/stats-3.txt | 1 + .../directory/__snapshots__/stats-0.txt | 3 ++ .../directory/__snapshots__/stats-1.txt | 1 + .../directory/__snapshots__/stats-2.txt | 3 ++ .../directory/__snapshots__/stats-3.txt | 1 + .../storage/max-age/__snapshots__/stats-0.txt | 3 ++ .../storage/max-age/__snapshots__/stats-1.txt | 3 ++ .../storage/max-age/__snapshots__/stats-2.txt | 3 ++ .../max-versions/__snapshots__/stats-0.txt | 3 ++ .../max-versions/__snapshots__/stats-1.txt | 3 ++ .../max-versions/__snapshots__/stats-2.txt | 3 ++ .../max-versions/__snapshots__/stats-3.txt | 3 ++ 139 files changed, 419 insertions(+), 9 deletions(-) diff --git a/crates/rspack_core/src/cache/persistent/mod.rs b/crates/rspack_core/src/cache/persistent/mod.rs index 6a5d62ee92ca..437e01d7b576 100644 --- a/crates/rspack_core/src/cache/persistent/mod.rs +++ b/crates/rspack_core/src/cache/persistent/mod.rs @@ -30,7 +30,10 @@ use self::{ storage::{StorageOptions, Version, create_storage}, }; use super::Cache; -use crate::{Compilation, CompilationLogger, CompilationLogging, CompilerOptions, Logger}; +use crate::{ + Compilation, CompilationLogger, CompilationLogging, CompilerOptions, Logger, + incremental::IncrementalPasses, +}; const LOGGER_NAME: &str = "rspack.persistentCache"; @@ -253,7 +256,11 @@ impl Cache for PersistentCache { } async fn before_modules_codegen(&mut self, compilation: &mut Compilation) { - if compilation.is_rebuild { + if compilation.is_rebuild + || !compilation + .incremental + .passes_enabled(IncrementalPasses::MODULES_CODEGEN) + { return; } @@ -263,6 +270,13 @@ impl Cache for PersistentCache { } async fn after_modules_codegen(&mut self, compilation: &Compilation) { + if !compilation + .incremental + .passes_enabled(IncrementalPasses::MODULES_CODEGEN) + { + return; + } + self.ctx.save_occasion( &self.modules_codegen_occasion, &compilation.code_generation_results, diff --git a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs index 92af8b1005bc..b73c1cd8671f 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs @@ -4,7 +4,8 @@ use rspack_cacheable::cacheable; use rspack_error::Result; use rspack_tasks::{ get_current_code_generation_result_id, get_current_dependency_id, - set_current_code_generation_result_id, set_current_dependency_id, + get_current_init_fragment_key_unique_id, set_current_code_generation_result_id, + set_current_dependency_id, set_current_init_fragment_key_unique_id, }; use super::{ @@ -19,6 +20,7 @@ pub const SCOPE: &str = "meta"; struct Meta { pub max_dependencies_id: u32, pub max_code_generation_result_id: u32, + pub max_init_fragment_key_unique_id: u32, } /// Meta Occasion is used to save compiler state. @@ -51,6 +53,7 @@ impl Occasion for MetaOccasion { let meta = Meta { max_dependencies_id: get_current_dependency_id(), max_code_generation_result_id: get_current_code_generation_result_id(), + max_init_fragment_key_unique_id: get_current_init_fragment_key_unique_id(), }; storage.set( SCOPE, @@ -74,8 +77,54 @@ impl Occasion for MetaOccasion { "The global code generation result id generator is not 0 when the persistent cache is restored." ); } + if get_current_init_fragment_key_unique_id() != 0 { + panic!( + "The global init fragment key unique id generator is not 0 when the persistent cache is restored." + ); + } set_current_dependency_id(meta.max_dependencies_id); set_current_code_generation_result_id(meta.max_code_generation_result_id); + set_current_init_fragment_key_unique_id(meta.max_init_fragment_key_unique_id); Ok(()) } } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use rspack_tasks::{ + CompilerContext, get_current_code_generation_result_id, get_current_dependency_id, + get_current_init_fragment_key_unique_id, set_current_code_generation_result_id, + set_current_dependency_id, set_current_init_fragment_key_unique_id, within_compiler_context, + }; + + use super::{MetaOccasion, Occasion}; + use crate::{InitFragmentKey, cache::persistent::storage::MemoryStorage}; + + #[tokio::test] + async fn should_restore_compiler_id_generators() { + let occasion = MetaOccasion::new(Arc::new(super::CacheCodec::new(None))); + let mut storage = MemoryStorage::default(); + + within_compiler_context(Arc::new(CompilerContext::new()), async { + set_current_dependency_id(7); + set_current_code_generation_result_id(11); + set_current_init_fragment_key_unique_id(13); + occasion.save(&mut storage, &()); + }) + .await; + + within_compiler_context(Arc::new(CompilerContext::new()), async { + occasion + .recovery(&storage) + .await + .expect("should recover meta"); + assert_eq!(get_current_dependency_id(), 7); + assert_eq!(get_current_code_generation_result_id(), 11); + assert_eq!(get_current_init_fragment_key_unique_id(), 13); + assert_eq!(InitFragmentKey::unique(), InitFragmentKey::Unique(13)); + }) + .await; + } +} diff --git a/crates/rspack_core/src/init_fragment.rs b/crates/rspack_core/src/init_fragment.rs index b391327b3c23..29225cd10258 100644 --- a/crates/rspack_core/src/init_fragment.rs +++ b/crates/rspack_core/src/init_fragment.rs @@ -2,7 +2,6 @@ use std::{ collections::{BTreeMap, BTreeSet}, fmt::{Debug, Display, Formatter}, hash::BuildHasherDefault, - sync::atomic::AtomicU32, }; use dyn_clone::{DynClone, clone_trait_object}; @@ -15,6 +14,7 @@ use rspack_cacheable::{ use rspack_error::Result; use rspack_hash::{RspackHash, RspackHasher}; use rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}; +use rspack_tasks::fetch_new_init_fragment_key_unique_id; use rspack_util::ext::IntoAny; use rustc_hash::FxHasher; use swc_core::ecma::atoms::Atom; @@ -24,8 +24,6 @@ use crate::{ merge_runtime, property_name, }; -static NEXT_INIT_FRAGMENT_KEY_UNIQUE_ID: AtomicU32 = AtomicU32::new(0); - pub struct InitFragmentContents { pub start: String, pub end: Option, @@ -51,9 +49,7 @@ pub enum InitFragmentKey { impl InitFragmentKey { pub fn unique() -> Self { - Self::Unique( - NEXT_INIT_FRAGMENT_KEY_UNIQUE_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed), - ) + Self::Unique(fetch_new_init_fragment_key_unique_id()) } } diff --git a/crates/rspack_tasks/src/lib.rs b/crates/rspack_tasks/src/lib.rs index e4be41199d02..9662303b3060 100644 --- a/crates/rspack_tasks/src/lib.rs +++ b/crates/rspack_tasks/src/lib.rs @@ -19,6 +19,7 @@ use tokio::{ pub struct CompilerContext { dependenc_id_generator: AtomicU32, code_generation_result_id_generator: AtomicU32, + init_fragment_key_unique_id_generator: AtomicU32, exports_info_artifact_ptr: AtomicPtr, } @@ -32,6 +33,7 @@ impl CompilerContext { Self { dependenc_id_generator: AtomicU32::new(0), code_generation_result_id_generator: AtomicU32::new(0), + init_fragment_key_unique_id_generator: AtomicU32::new(0), exports_info_artifact_ptr: AtomicPtr::new(std::ptr::null_mut()), } } @@ -65,6 +67,21 @@ impl CompilerContext { .code_generation_result_id_generator .store(id, std::sync::atomic::Ordering::SeqCst); } + pub fn fetch_new_init_fragment_key_unique_id(&self) -> u32 { + self + .init_fragment_key_unique_id_generator + .fetch_add(1, std::sync::atomic::Ordering::SeqCst) + } + pub fn init_fragment_key_unique_id(&self) -> u32 { + self + .init_fragment_key_unique_id_generator + .load(std::sync::atomic::Ordering::SeqCst) + } + pub fn set_init_fragment_key_unique_id(&self, id: u32) { + self + .init_fragment_key_unique_id_generator + .store(id, std::sync::atomic::Ordering::SeqCst); + } pub fn exports_info_artifact_ptr(&self) -> Option<*mut c_void> { let ptr = self @@ -103,6 +120,19 @@ pub fn set_current_code_generation_result_id(id: u32) { .get() .set_code_generation_result_id(id); } +pub fn fetch_new_init_fragment_key_unique_id() -> u32 { + CURRENT_COMPILER_CONTEXT + .get() + .fetch_new_init_fragment_key_unique_id() +} +pub fn get_current_init_fragment_key_unique_id() -> u32 { + CURRENT_COMPILER_CONTEXT.get().init_fragment_key_unique_id() +} +pub fn set_current_init_fragment_key_unique_id(id: u32) { + CURRENT_COMPILER_CONTEXT + .get() + .set_init_fragment_key_unique_id(id); +} pub fn within_compiler_context( compiler_context: Arc, diff --git a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-2.txt index 3f7b6a176f3a..4e0126afcc14 100644 --- a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/basic/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-2.txt index 7287fcd40884..3c35a0649327 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-2.txt @@ -8,6 +8,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-4.txt index f16854220de4..90d3d84eb8ea 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-4.txt @@ -9,6 +9,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-5.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-5.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-5.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-5.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-6.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-6.txt index f16854220de4..90d3d84eb8ea 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-6.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-6.txt @@ -9,6 +9,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-7.txt b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-7.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-7.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-dir/__snapshots__/stats-7.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-0.txt index 5cb54d8d27ca..0add16be5c6b 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-1.txt index b6f7879cb4b0..212fc866fe42 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-1.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-2.txt index a41ffe6406c2..94c4a7d41a2e 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-3.txt index 6bfd208797ac..871f6b244247 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-3.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-4.txt index a41ffe6406c2..94c4a7d41a2e 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-4.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-5.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-5.txt index a9d3bcfb99ba..c323c903bb3e 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-5.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-5.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-6.txt b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-6.txt index 97b4a1a40d04..16b150f290b2 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-6.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies-resolve/__snapshots__/stats-6.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-1.txt index 1a676916996c..56e4c0ca6d7c 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-2.txt index dca7b2b27ee1..346179d59b35 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-2.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-3.txt index d5ac97a116a1..e110ea09926a 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-3.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-4.txt index 1a676916996c..56e4c0ca6d7c 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-4.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-5.txt b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-5.txt index f860e0a91830..a95b9670f56e 100644 --- a/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-5.txt +++ b/tests/rspack-test/cacheCases/common/build-dependencies/__snapshots__/stats-5.txt @@ -6,6 +6,7 @@ DEBUG LOG from rspack.persistentCache validate build dependencies: xx ms write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write minimize to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-1.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-3.txt index f00d70814079..d71bbb3adba6 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-3.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-4.txt index f00d70814079..d71bbb3adba6 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-4.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-5.txt b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-5.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-5.txt +++ b/tests/rspack-test/cacheCases/common/minimize-cache/__snapshots__/stats-5.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-2.txt index 54f22f28f804..1ef3e3f63505 100644 --- a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/module-asset/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js b/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js index 0af51353da87..0dd326c99a00 100644 --- a/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js +++ b/tests/rspack-test/cacheCases/common/module-codegen-cache/rspack.config.js @@ -59,6 +59,15 @@ module.exports = { expect(modulesCodegenAffectedLogEntry).toBeUndefined(); } + if (updateIndex === 1) { + expect(modulesCodegenAffectedLogEntry).toBeTruthy(); + const modulesCodegen = parseAffectedLogEntry( + modulesCodegenAffectedLogEntry, + ); + expect(modulesCodegen.affected).toBe(0); + expect(modulesCodegen.total).toBeGreaterThan(0); + } + if (updateIndex === 2) { expect(modulesCodegenAffectedLogEntry).toBeTruthy(); const modulesHashesAffectedLogEntry = getAffectedLogEntry( @@ -69,6 +78,7 @@ module.exports = { const modulesCodegen = parseAffectedLogEntry( modulesCodegenAffectedLogEntry, ); + expect(modulesCodegen.affected).toBeGreaterThan(0); expect(modulesCodegen.total).toBeGreaterThan(0); if (modulesCodegen.affected >= modulesCodegen.total) { throw new Error( diff --git a/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-1.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/module-hashes-cache/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-1.txt index 8f83d6aea802..e11011e32729 100644 --- a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-1.txt @@ -12,5 +12,7 @@ DEBUG LOG from rspack.persistentCache read make from persistent cache: xx ms module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-2.txt index fac118cb9aa8..fa1331c24287 100644 --- a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-2.txt @@ -10,5 +10,7 @@ DEBUG LOG from rspack.persistentCache read make from persistent cache: xx ms module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-3.txt index bd94e669ba4e..09e5ab0d80b0 100644 --- a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-3.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-4.txt index fac118cb9aa8..fa1331c24287 100644 --- a/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/readonly/__snapshots__/stats-4.txt @@ -10,5 +10,7 @@ DEBUG LOG from rspack.persistentCache read make from persistent cache: xx ms module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms \ No newline at end of file diff --git a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-1.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/rstest-virtual-module-mock-build-cache/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-0.txt index 0ba66d329716..acdc87f298bf 100644 --- a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms source map persistent cache recovery succeeded diff --git a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-1.txt index e93770f11558..fdc2352bc3e2 100644 --- a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms source map persistent cache recovery succeeded diff --git a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-2.txt index 35960aaa117d..013c91324061 100644 --- a/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/source-map-devtool-plugin-cache/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms source map persistent cache recovery succeeded diff --git a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-3.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-3.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-4.txt index 9e2ff82dfa54..0780d2c1d91e 100644 --- a/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/common/update-file/__snapshots__/stats-4.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-2.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-2.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/common/version/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-2.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-2.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-mode/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-2.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-2.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/invalidation/config-name/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-1.txt index 0e2eb12577d0..c113559b4791 100644 --- a/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/invalidation/lib-symlink/__snapshots__/stats-1.txt @@ -16,6 +16,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-1.txt index 6e9829b40019..2ca4988575a7 100644 --- a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-1.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-2.txt index 6e9829b40019..2ca4988575a7 100644 --- a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-3.txt index 6e9829b40019..2ca4988575a7 100644 --- a/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/make/define-plugin/__snapshots__/stats-3.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-2.txt index db71ef020e38..5357f6c312dc 100644 --- a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/make/isolated_module/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/issuer-update/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-1.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/keep-module-error/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-2.txt index c682adee2dff..d159c251fa36 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-4.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-4.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-4.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-4.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-5.txt b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-5.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-5.txt +++ b/tests/rspack-test/cacheCases/make/lazy-barrel/__snapshots__/stats-5.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-1.txt index c7e5246b4f42..d9858352cb8f 100644 --- a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-1.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-2.txt index c7e5246b4f42..d9858352cb8f 100644 --- a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-3.txt index c7e5246b4f42..d9858352cb8f 100644 --- a/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/make/provide-plugin/__snapshots__/stats-3.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-2.txt index 509cfb7a8559..c47ae58aa189 100644 --- a/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/make/refactorize_dep/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-2.txt index a17ef0d0b90f..77d51ef41c1c 100644 --- a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/mf/issue-9150/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-1.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-1.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/portable/basic/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-1.txt index c9975f06e96e..64757a88d2d8 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-1.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies-timestamp/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-1.txt index ff46000b9bc3..f31ef59bbf06 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-1.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/context-dependencies/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-2.txt index 68319af89510..7d75a69d1b01 100644 --- a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/snapshot/default_value/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/snapshot/immutable-paths/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-2.txt index f75eb5de9b32..5c6f1ff3ae5a 100644 --- a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-2.txt @@ -12,6 +12,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/snapshot/managed-paths/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-1.txt index 28a7ac6e5baf..2f038b4b3acf 100644 --- a/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/missing_dependencies/__snapshots__/stats-1.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-2.txt index eaecdb3e15af..8f26d93cb088 100644 --- a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/snapshot/unmanaged-paths/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-1.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-1.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-2.txt index 705e8d1186e7..c12ab1b40018 100644 --- a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-2.txt @@ -14,6 +14,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-3.txt index 9c35db16843b..62bd1a999e3b 100644 --- a/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/storage/directory/__snapshots__/stats-3.txt @@ -1,6 +1,7 @@ DEBUG LOG from rspack.persistentCache write make to persistent cache: xx ms write module hashes to persistent cache: xx ms + write modules codegen to persistent cache: xx ms write meta to persistent cache: xx ms write snapshot to persistent cache: xx ms write build dependencies to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-1.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-1.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-2.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/storage/max-age/__snapshots__/stats-2.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-0.txt b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-0.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-0.txt +++ b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-0.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-1.txt b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-1.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-1.txt +++ b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-1.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-2.txt b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-2.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-2.txt +++ b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-2.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms diff --git a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-3.txt b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-3.txt index 4bb2265675ce..c7099b399675 100644 --- a/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-3.txt +++ b/tests/rspack-test/cacheCases/storage/max-versions/__snapshots__/stats-3.txt @@ -11,6 +11,9 @@ DEBUG LOG from rspack.persistentCache module hashes persistent cache recovery succeeded read module hashes from persistent cache: xx ms write module hashes to persistent cache: xx ms + modules codegen persistent cache recovery succeeded + read modules codegen from persistent cache: xx ms + write modules codegen to persistent cache: xx ms minimize persistent cache recovery succeeded read minimize from persistent cache: xx ms write minimize to persistent cache: xx ms From dc68b53468099da981f18cc6e070caaa22f4f38a Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Fri, 10 Jul 2026 18:47:47 +0800 Subject: [PATCH 6/7] Refactor init fragment handling into code generation data --- .../src/artifacts/code_generation_results.rs | 3 - .../src/cache/persistent/occasion/meta/mod.rs | 19 +-- crates/rspack_core/src/concatenated_module.rs | 30 +++-- .../src/dependency/dependency_template.rs | 19 +-- crates/rspack_core/src/external_module.rs | 20 +-- crates/rspack_core/src/init_fragment.rs | 126 +++++------------- crates/rspack_plugin_esm_library/src/link.rs | 6 +- .../rspack_plugin_esm_library/src/render.rs | 5 +- .../src/plugin/mod.rs | 3 +- .../src/plugin/runtime_context.rs | 3 +- .../rspack_plugin_javascript/src/runtime.rs | 25 ++-- crates/rspack_tasks/src/lib.rs | 32 ----- 12 files changed, 87 insertions(+), 204 deletions(-) diff --git a/crates/rspack_core/src/artifacts/code_generation_results.rs b/crates/rspack_core/src/artifacts/code_generation_results.rs index 4cea93cf0a7c..d05f05a371d0 100644 --- a/crates/rspack_core/src/artifacts/code_generation_results.rs +++ b/crates/rspack_core/src/artifacts/code_generation_results.rs @@ -225,7 +225,6 @@ pub struct CodeGenerationResult { pub inner: BindingCell>, /// [definition in webpack](https://github.com/webpack/webpack/blob/4b4ca3bb53f36a5b8fc6bc1bd976ed7af161bd80/lib/Module.js#L75) pub data: CodeGenerationData, - pub chunk_init_fragments: ChunkInitFragments, pub runtime_requirements: RuntimeGlobals, pub hash: Option, pub id: CodeGenResultId, @@ -263,7 +262,6 @@ impl CodeGenerationResult { source_type.hash(&mut hasher); std::hash::Hash::hash(source, &mut hasher); } - self.chunk_init_fragments.hash(&mut hasher); self.runtime_requirements.hash(&mut hasher); self.hash = Some(hasher.digest(hash_digest)); } @@ -284,7 +282,6 @@ impl CodeGenerationResult { for source_type in self.inner.as_ref().keys() { source_type.hash(&mut hasher); } - self.chunk_init_fragments.hash(&mut hasher); self.runtime_requirements.hash(&mut hasher); self.hash = Some(hasher.digest(hash_digest)); } diff --git a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs index b73c1cd8671f..af66e013e2a2 100644 --- a/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs +++ b/crates/rspack_core/src/cache/persistent/occasion/meta/mod.rs @@ -4,8 +4,7 @@ use rspack_cacheable::cacheable; use rspack_error::Result; use rspack_tasks::{ get_current_code_generation_result_id, get_current_dependency_id, - get_current_init_fragment_key_unique_id, set_current_code_generation_result_id, - set_current_dependency_id, set_current_init_fragment_key_unique_id, + set_current_code_generation_result_id, set_current_dependency_id, }; use super::{ @@ -20,7 +19,6 @@ pub const SCOPE: &str = "meta"; struct Meta { pub max_dependencies_id: u32, pub max_code_generation_result_id: u32, - pub max_init_fragment_key_unique_id: u32, } /// Meta Occasion is used to save compiler state. @@ -53,7 +51,6 @@ impl Occasion for MetaOccasion { let meta = Meta { max_dependencies_id: get_current_dependency_id(), max_code_generation_result_id: get_current_code_generation_result_id(), - max_init_fragment_key_unique_id: get_current_init_fragment_key_unique_id(), }; storage.set( SCOPE, @@ -77,14 +74,8 @@ impl Occasion for MetaOccasion { "The global code generation result id generator is not 0 when the persistent cache is restored." ); } - if get_current_init_fragment_key_unique_id() != 0 { - panic!( - "The global init fragment key unique id generator is not 0 when the persistent cache is restored." - ); - } set_current_dependency_id(meta.max_dependencies_id); set_current_code_generation_result_id(meta.max_code_generation_result_id); - set_current_init_fragment_key_unique_id(meta.max_init_fragment_key_unique_id); Ok(()) } } @@ -95,12 +86,11 @@ mod tests { use rspack_tasks::{ CompilerContext, get_current_code_generation_result_id, get_current_dependency_id, - get_current_init_fragment_key_unique_id, set_current_code_generation_result_id, - set_current_dependency_id, set_current_init_fragment_key_unique_id, within_compiler_context, + set_current_code_generation_result_id, set_current_dependency_id, within_compiler_context, }; use super::{MetaOccasion, Occasion}; - use crate::{InitFragmentKey, cache::persistent::storage::MemoryStorage}; + use crate::cache::persistent::storage::MemoryStorage; #[tokio::test] async fn should_restore_compiler_id_generators() { @@ -110,7 +100,6 @@ mod tests { within_compiler_context(Arc::new(CompilerContext::new()), async { set_current_dependency_id(7); set_current_code_generation_result_id(11); - set_current_init_fragment_key_unique_id(13); occasion.save(&mut storage, &()); }) .await; @@ -122,8 +111,6 @@ mod tests { .expect("should recover meta"); assert_eq!(get_current_dependency_id(), 7); assert_eq!(get_current_code_generation_result_id(), 11); - assert_eq!(get_current_init_fragment_key_unique_id(), 13); - assert_eq!(InitFragmentKey::unique(), InitFragmentKey::Unique(13)); }) .await; } diff --git a/crates/rspack_core/src/concatenated_module.rs b/crates/rspack_core/src/concatenated_module.rs index 4332bde6880f..5dd9f5d1f0da 100644 --- a/crates/rspack_core/src/concatenated_module.rs +++ b/crates/rspack_core/src/concatenated_module.rs @@ -2004,7 +2004,13 @@ impl Module for ConcatenatedModule { let mut code_generation_result = CodeGenerationResult::default(); code_generation_result.add(SourceType::JavaScript, CachedSource::new(result).boxed()); - code_generation_result.chunk_init_fragments = chunk_init_fragments; + if !chunk_init_fragments.is_empty() { + code_generation_result + .data + .insert(CodeGenerationDataChunkInitFragments::from( + chunk_init_fragments, + )); + } if public_path_auto_replace { code_generation_result @@ -2578,20 +2584,17 @@ impl ConcatenatedModule { let CodeGenerationResult { mut inner, - mut chunk_init_fragments, + mut data, mut runtime_requirements, concatenation_scope, .. } = codegen_res; runtime_requirements.extend(*runtime_template.runtime_requirements()); - - if let Some(fragments) = codegen_res - .data - .get::() - { - chunk_init_fragments.extend(fragments.inner().iter().cloned()); - } + let chunk_init_fragments = data + .get_mut::() + .map(|fragments| mem::take(fragments.inner_mut())) + .unwrap_or_default(); let concatenation_scope = concatenation_scope.expect("should have concatenation_scope"); let source = inner @@ -2690,13 +2693,12 @@ impl ConcatenatedModule { module_info.internal_source = Some(source); module_info.source = Some(result_source); module_info.chunk_init_fragments = chunk_init_fragments; - if let Some(CodeGenerationPublicPathAutoReplace(true)) = codegen_res - .data - .get::( - ) { + if let Some(CodeGenerationPublicPathAutoReplace(true)) = + data.get::() + { module_info.public_path_auto_replacement = Some(true); } - if codegen_res.data.contains::() { + if data.contains::() { module_info.static_url_replacement = true; } Ok(ModuleInfo::Concatenated(Box::new(module_info))) diff --git a/crates/rspack_core/src/dependency/dependency_template.rs b/crates/rspack_core/src/dependency/dependency_template.rs index 25cf82985cbe..38a0ee86a356 100644 --- a/crates/rspack_core/src/dependency/dependency_template.rs +++ b/crates/rspack_core/src/dependency/dependency_template.rs @@ -23,23 +23,16 @@ pub struct TemplateContext<'a, 'c> { impl TemplateContext<'_, '_> { pub fn chunk_init_fragments(&mut self) -> &mut ChunkInitFragments { - let data_fragments = self.data.get::(); - if data_fragments.is_some() { - self - .data - .get_mut::() - .expect("should have chunk_init_fragments") - .inner_mut() - } else { + if !self.data.contains::() { self .data .insert(CodeGenerationDataChunkInitFragments::default()); - self - .data - .get_mut::() - .expect("should have chunk_init_fragments") - .inner_mut() } + self + .data + .get_mut::() + .expect("chunk init fragments should exist") + .inner_mut() } } diff --git a/crates/rspack_core/src/external_module.rs b/crates/rspack_core/src/external_module.rs index 0d0731e93421..8725df9bc743 100644 --- a/crates/rspack_core/src/external_module.rs +++ b/crates/rspack_core/src/external_module.rs @@ -12,13 +12,13 @@ use serde::Serialize; use crate::{ AsyncDependenciesBlockIdentifier, BoxModule, BuildContext, BuildInfo, BuildMeta, BuildMetaExportsType, BuildResult, ChunkGraph, ChunkInitFragments, ChunkUkey, - CodeGenerationDataUrl, CodeGenerationResult, Compilation, ConcatenationScope, Context, - DependenciesBlock, DependencyId, ExportProvided, ExternalType, FactoryMeta, ImportAttributes, - ImportPhase, InitFragmentExt, InitFragmentKey, InitFragmentStage, LibIdentOptions, Module, - ModuleArgument, ModuleCodeGenerationContext, ModuleCodeTemplate, ModuleGraph, ModuleType, - NAMESPACE_OBJECT_EXPORT, NormalInitFragment, RuntimeGlobals, RuntimeSpec, SourceType, - StaticExportsDependency, StaticExportsSpec, UsageState, UsedExports, UsedNameItem, - extract_url_and_global, impl_module_meta_info, module_update_hash, property_access, + CodeGenerationDataChunkInitFragments, CodeGenerationDataUrl, CodeGenerationResult, Compilation, + ConcatenationScope, Context, DependenciesBlock, DependencyId, ExportProvided, ExternalType, + FactoryMeta, ImportAttributes, ImportPhase, InitFragmentExt, InitFragmentKey, InitFragmentStage, + LibIdentOptions, Module, ModuleArgument, ModuleCodeGenerationContext, ModuleCodeTemplate, + ModuleGraph, ModuleType, NAMESPACE_OBJECT_EXPORT, NormalInitFragment, RuntimeGlobals, + RuntimeSpec, SourceType, StaticExportsDependency, StaticExportsSpec, UsageState, UsedExports, + UsedNameItem, extract_url_and_global, impl_module_meta_info, module_update_hash, property_access, rspack_sources::{BoxSource, RawStringSource, SourceExt}, to_identifier, }; @@ -1235,7 +1235,11 @@ impl Module for ExternalModule { runtime_template, )?; cgr.add(SourceType::JavaScript, source); - cgr.chunk_init_fragments = chunk_init_fragments; + if !chunk_init_fragments.is_empty() { + cgr.data.insert(CodeGenerationDataChunkInitFragments::from( + chunk_init_fragments, + )); + } } }; cgr.concatenation_scope = std::mem::take(concatenation_scope); diff --git a/crates/rspack_core/src/init_fragment.rs b/crates/rspack_core/src/init_fragment.rs index 29225cd10258..8ed3b840e3b7 100644 --- a/crates/rspack_core/src/init_fragment.rs +++ b/crates/rspack_core/src/init_fragment.rs @@ -1,7 +1,8 @@ use std::{ collections::{BTreeMap, BTreeSet}, fmt::{Debug, Display, Formatter}, - hash::BuildHasherDefault, + hash::{BuildHasherDefault, Hash, Hasher}, + sync::Arc, }; use dyn_clone::{DynClone, clone_trait_object}; @@ -9,12 +10,10 @@ use hashlink::LinkedHashSet; use indexmap::IndexMap; use rspack_cacheable::{ cacheable, cacheable_dyn, - with::{AsPreset, AsTuple2, AsVec}, + with::{AsInner, AsPreset, AsTuple2, AsVec}, }; use rspack_error::Result; -use rspack_hash::{RspackHash, RspackHasher}; use rspack_sources::{BoxSource, ConcatSource, RawStringSource, SourceExt}; -use rspack_tasks::fetch_new_init_fragment_key_unique_id; use rspack_util::ext::IntoAny; use rustc_hash::FxHasher; use swc_core::ecma::atoms::Atom; @@ -29,10 +28,36 @@ pub struct InitFragmentContents { pub end: Option, } +/// Runtime-only identity: clones share it, while deserialization creates a fresh allocation. +#[doc(hidden)] +#[cacheable] +#[derive(Debug, Clone)] +pub struct UniqueInitFragmentKey(#[cacheable(with=AsInner)] Arc); + +impl UniqueInitFragmentKey { + fn new() -> Self { + Self(Arc::new(0)) + } +} + +impl PartialEq for UniqueInitFragmentKey { + fn eq(&self, other: &Self) -> bool { + Arc::ptr_eq(&self.0, &other.0) + } +} + +impl Eq for UniqueInitFragmentKey {} + +impl Hash for UniqueInitFragmentKey { + fn hash(&self, state: &mut H) { + std::ptr::hash(Arc::as_ptr(&self.0), state); + } +} + #[cacheable] #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum InitFragmentKey { - Unique(u32), + Unique(UniqueInitFragmentKey), ESMImport(String), ESMExportStar(String), // TODO: align with webpack and remove this ESMExports, @@ -49,57 +74,7 @@ pub enum InitFragmentKey { impl InitFragmentKey { pub fn unique() -> Self { - Self::Unique(fetch_new_init_fragment_key_unique_id()) - } -} - -impl RspackHash for InitFragmentKey { - fn hash(&self, state: &mut RspackHasher) { - match self { - InitFragmentKey::Unique(id) => { - "unique".hash(state); - id.hash(state); - } - InitFragmentKey::ESMImport(value) => { - "esm-import".hash(state); - value.hash(state); - } - InitFragmentKey::ESMExportStar(value) => { - "esm-export-star".hash(state); - value.hash(state); - } - InitFragmentKey::ESMExports => "esm-exports".hash(state), - InitFragmentKey::CommonJsExports(value) => { - "commonjs-exports".hash(state); - value.hash(state); - } - InitFragmentKey::ModuleExternal(value) => { - "module-external".hash(state); - value.hash(state); - } - InitFragmentKey::ExternalModule(value) => { - "external-module".hash(state); - value.hash(state); - } - InitFragmentKey::AwaitDependencies => "await-dependencies".hash(state), - InitFragmentKey::ESMCompatibility => "esm-compatibility".hash(state), - InitFragmentKey::ModuleDecorator(value) => { - "module-decorator".hash(state); - value.hash(state); - } - InitFragmentKey::ESMFakeNamespaceObjectFragment(value) => { - "esm-fake-namespace-object".hash(state); - value.hash(state); - } - InitFragmentKey::ESMDeferImportNamespaceObjectFragment(value) => { - "esm-defer-import-namespace-object".hash(state); - value.hash(state); - } - InitFragmentKey::Const(value) => { - "const".hash(state); - value.hash(state); - } - } + Self::Unique(UniqueInitFragmentKey::new()) } } @@ -214,7 +189,7 @@ pub trait InitFragmentRenderContext { } #[cacheable_dyn] -pub trait InitFragment: IntoAny + RspackHash + DynClone + Debug + Sync + Send { +pub trait InitFragment: IntoAny + DynClone + Debug + Sync + Send { /// getContent + getEndContent fn contents( self: Box, @@ -256,12 +231,6 @@ pub enum InitFragmentStage { StageAsyncESMImports, } -impl RspackHash for InitFragmentStage { - fn hash(&self, state: &mut RspackHasher) { - self.as_str().hash(state); - } -} - impl InitFragmentStage { fn as_str(self) -> &'static str { match self { @@ -365,7 +334,7 @@ impl InitFragmentRenderContext for ChunkRenderContext { } #[cacheable] -#[derive(Debug, Clone, rspack_hash::RspackHash)] +#[derive(Debug, Clone)] pub struct NormalInitFragment { content: String, stage: InitFragmentStage, @@ -436,23 +405,8 @@ pub enum ESMExportBinding { Value(#[cacheable(with=AsPreset)] Atom), } -impl RspackHash for ESMExportBinding { - fn hash(&self, state: &mut RspackHasher) { - match self { - ESMExportBinding::Getter(value) => { - "getter".hash(state); - value.hash(state); - } - ESMExportBinding::Value(value) => { - "value".hash(state); - value.hash(state); - } - } - } -} - #[cacheable] -#[derive(Debug, Clone, rspack_hash::RspackHash)] +#[derive(Debug, Clone)] pub struct ESMExportInitFragment { exports_argument: ExportsArgument, // TODO: should be a map @@ -587,14 +541,6 @@ impl AwaitDependenciesInitFragment { } } -impl RspackHash for AwaitDependenciesInitFragment { - fn hash(&self, state: &mut RspackHasher) { - for promise in &self.promises { - promise.hash(state); - } - } -} - #[cacheable_dyn] impl InitFragment for AwaitDependenciesInitFragment { fn contents( @@ -639,7 +585,7 @@ impl InitFragment for AwaitDependenciesInitFragment { } #[cacheable] -#[derive(Debug, Clone, rspack_hash::RspackHash)] +#[derive(Debug, Clone)] pub struct ConditionalInitFragment { content: String, stage: InitFragmentStage, @@ -760,7 +706,7 @@ fn wrap_in_condition(condition: &str, source: &str) -> String { } #[cacheable] -#[derive(Debug, Clone, rspack_hash::RspackHash)] +#[derive(Debug, Clone)] pub struct ExternalModuleInitFragment { imported_module: String, // webpack also supports `ImportSpecifiers` but not ever used. diff --git a/crates/rspack_plugin_esm_library/src/link.rs b/crates/rspack_plugin_esm_library/src/link.rs index 074b40adc4df..8a850d7ee034 100644 --- a/crates/rspack_plugin_esm_library/src/link.rs +++ b/crates/rspack_plugin_esm_library/src/link.rs @@ -1468,12 +1468,11 @@ var {} = {{}}; .runtime_requirements .insert(RuntimeGlobals::REQUIRE | RuntimeGlobals::MODULE_FACTORIES); } - let mut chunk_init_fragments = codegen_res + let chunk_init_fragments = codegen_res .data .get::() .map(|fragments| fragments.inner().clone()) .unwrap_or_default(); - chunk_init_fragments.extend(codegen_res.chunk_init_fragments.clone()); Ok(( ModuleInfo::External(external_module_info), if chunk_init_fragments.is_empty() { @@ -1615,9 +1614,6 @@ var {} = {{}}; .get::() .map(|fragments| fragments.inner().clone()) .unwrap_or_default(); - concate_info - .chunk_init_fragments - .extend(codegen_res.chunk_init_fragments.clone()); concate_info .chunk_init_fragments .extend(chunk_init_fragments); diff --git a/crates/rspack_plugin_esm_library/src/render.rs b/crates/rspack_plugin_esm_library/src/render.rs index 919acb946824..6119aabb0489 100644 --- a/crates/rspack_plugin_esm_library/src/render.rs +++ b/crates/rspack_plugin_esm_library/src/render.rs @@ -203,7 +203,7 @@ impl EsmLibraryPlugin { .expect("should have module"); let hooks = hooks.read().await; - let Some((module_source, init_frags, init_frags2)) = render_module( + let Some((module_source, init_fragments)) = render_module( compilation, chunk_ukey, module.as_ref(), @@ -219,8 +219,7 @@ impl EsmLibraryPlugin { }; drop(hooks); - chunk_init_fragments.extend(init_frags); - chunk_init_fragments.extend(init_frags2); + chunk_init_fragments.extend(init_fragments); decl_inner.add(module_source.clone()); } diff --git a/crates/rspack_plugin_javascript/src/plugin/mod.rs b/crates/rspack_plugin_javascript/src/plugin/mod.rs index 8121649db89a..0d302740dff7 100644 --- a/crates/rspack_plugin_javascript/src/plugin/mod.rs +++ b/crates/rspack_plugin_javascript/src/plugin/mod.rs @@ -890,7 +890,7 @@ var {} = {{}}; let m = module_graph .module_by_identifier(m_identifier) .expect("should have module"); - let Some((mut rendered_module, fragments, additional_fragments)) = render_module( + let Some((mut rendered_module, fragments)) = render_module( compilation, chunk_ukey, m.as_ref(), @@ -913,7 +913,6 @@ var {} = {{}}; }; chunk_init_fragments.extend(fragments); - chunk_init_fragments.extend(additional_fragments); let inner_strict = !all_strict && m.build_info().strict; let module_runtime_requirements = ChunkGraph::get_module_runtime_requirements(compilation, *m_identifier, chunk.runtime()); diff --git a/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs b/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs index c79805d1cb19..d8ebb40826e3 100644 --- a/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs +++ b/crates/rspack_plugin_javascript/src/plugin/runtime_context.rs @@ -740,7 +740,7 @@ impl JsPlugin { let m = module_graph .module_by_identifier(m_identifier) .expect("should have module"); - let Some((mut rendered_module, fragments, additional_fragments)) = render_module( + let Some((mut rendered_module, fragments)) = render_module( compilation, chunk_ukey, m.as_ref(), @@ -763,7 +763,6 @@ impl JsPlugin { }; chunk_init_fragments.extend(fragments); - chunk_init_fragments.extend(additional_fragments); let inner_strict = !all_strict && m.build_info().strict; let module_runtime_requirements = ChunkGraph::get_module_runtime_requirements(compilation, *m_identifier, chunk.runtime()); diff --git a/crates/rspack_plugin_javascript/src/runtime.rs b/crates/rspack_plugin_javascript/src/runtime.rs index 2b294ef58f82..ac0de10df907 100644 --- a/crates/rspack_plugin_javascript/src/runtime.rs +++ b/crates/rspack_plugin_javascript/src/runtime.rs @@ -57,7 +57,7 @@ pub async fn render_chunk_modules( runtime_template ) .await - .map(|result| result.map(|(s, f, a)| (module.identifier(), s, f, a))) + .map(|result| result.map(|(source, fragments)| (module.identifier(), source, fragments))) }, ); }); @@ -78,20 +78,19 @@ pub async fn render_chunk_modules( return Ok(None); } - module_code_array.sort_unstable_by_key(|(module_identifier, _, _, _)| *module_identifier); + module_code_array.sort_unstable_by_key(|(module_identifier, _, _)| *module_identifier); let chunk_init_fragments = module_code_array.iter().fold( ChunkInitFragments::default(), - |mut chunk_init_fragments, (_, _, fragments, additional_fragments)| { + |mut chunk_init_fragments, (_, _, fragments)| { chunk_init_fragments.extend((*fragments).clone()); - chunk_init_fragments.extend(additional_fragments.clone()); chunk_init_fragments }, ); let module_sources: Vec<_> = module_code_array .into_iter() - .map(|(_, source, _, _)| source) + .map(|(_, source, _)| source) .collect(); let module_sources = module_sources .into_par_iter() @@ -119,7 +118,7 @@ pub async fn render_module( output_path: &str, hooks: &JavascriptModulesPluginHooks, runtime_template: &ChunkCodeTemplate, -) -> Result> { +) -> Result> { let chunk = compilation .build_chunk_graph_artifact .chunk_by_ukey @@ -131,13 +130,11 @@ pub async fn render_module( return Ok(None); }; - let mut module_chunk_init_fragments = match code_gen_result + let mut module_chunk_init_fragments = code_gen_result .data .get::() - { - Some(fragments) => fragments.inner().clone(), - None => ChunkInitFragments::default(), - }; + .map(|fragments| fragments.inner().clone()) + .unwrap_or_default(); let mut render_source = if code_gen_result .data @@ -325,11 +322,7 @@ pub async fn render_module( render_source.source }; - Ok(Some(( - sources, - code_gen_result.chunk_init_fragments.clone(), - module_chunk_init_fragments, - ))) + Ok(Some((sources, module_chunk_init_fragments))) } pub async fn render_chunk_runtime_modules( diff --git a/crates/rspack_tasks/src/lib.rs b/crates/rspack_tasks/src/lib.rs index 9662303b3060..ccd8bad1d12d 100644 --- a/crates/rspack_tasks/src/lib.rs +++ b/crates/rspack_tasks/src/lib.rs @@ -19,7 +19,6 @@ use tokio::{ pub struct CompilerContext { dependenc_id_generator: AtomicU32, code_generation_result_id_generator: AtomicU32, - init_fragment_key_unique_id_generator: AtomicU32, exports_info_artifact_ptr: AtomicPtr, } @@ -33,7 +32,6 @@ impl CompilerContext { Self { dependenc_id_generator: AtomicU32::new(0), code_generation_result_id_generator: AtomicU32::new(0), - init_fragment_key_unique_id_generator: AtomicU32::new(0), exports_info_artifact_ptr: AtomicPtr::new(std::ptr::null_mut()), } } @@ -67,22 +65,6 @@ impl CompilerContext { .code_generation_result_id_generator .store(id, std::sync::atomic::Ordering::SeqCst); } - pub fn fetch_new_init_fragment_key_unique_id(&self) -> u32 { - self - .init_fragment_key_unique_id_generator - .fetch_add(1, std::sync::atomic::Ordering::SeqCst) - } - pub fn init_fragment_key_unique_id(&self) -> u32 { - self - .init_fragment_key_unique_id_generator - .load(std::sync::atomic::Ordering::SeqCst) - } - pub fn set_init_fragment_key_unique_id(&self, id: u32) { - self - .init_fragment_key_unique_id_generator - .store(id, std::sync::atomic::Ordering::SeqCst); - } - pub fn exports_info_artifact_ptr(&self) -> Option<*mut c_void> { let ptr = self .exports_info_artifact_ptr @@ -120,20 +102,6 @@ pub fn set_current_code_generation_result_id(id: u32) { .get() .set_code_generation_result_id(id); } -pub fn fetch_new_init_fragment_key_unique_id() -> u32 { - CURRENT_COMPILER_CONTEXT - .get() - .fetch_new_init_fragment_key_unique_id() -} -pub fn get_current_init_fragment_key_unique_id() -> u32 { - CURRENT_COMPILER_CONTEXT.get().init_fragment_key_unique_id() -} -pub fn set_current_init_fragment_key_unique_id(id: u32) { - CURRENT_COMPILER_CONTEXT - .get() - .set_init_fragment_key_unique_id(id); -} - pub fn within_compiler_context( compiler_context: Arc, f: F, From 867abccd85b45aff3fbd509b77e4c4467bbeff25 Mon Sep 17 00:00:00 2001 From: ahabhgk Date: Mon, 13 Jul 2026 14:04:09 +0800 Subject: [PATCH 7/7] update --- tests/rspack-test/statsAPICases/basic.js | 6 +++--- tests/rspack-test/statsAPICases/exports.js | 4 ++-- tests/rspack-test/statsAPICases/ids.js | 2 +- tests/rspack-test/statsAPICases/with-query.js | 4 ++-- .../all-stats/__snapshots__/stats.txt | 2 +- .../__snapshots__/stats.txt | 2 +- .../__snapshots__/stats.txt | 4 ++-- .../immutable/__snapshots__/stats.txt | 4 ++-- .../issue-7577/__snapshots__/stats.txt | 20 +++++++++---------- .../preset-detailed/__snapshots__/stats.txt | 2 +- .../preset-verbose/__snapshots__/stats.txt | 2 +- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/rspack-test/statsAPICases/basic.js b/tests/rspack-test/statsAPICases/basic.js index fa368f1d89ab..90dfb522fcce 100644 --- a/tests/rspack-test/statsAPICases/basic.js +++ b/tests/rspack-test/statsAPICases/basic.js @@ -69,7 +69,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: b5cd62d7f1e244c4, + hash: 38a4677ffcccf553, id: 889, idHints: Array [], initial: true, @@ -199,7 +199,7 @@ module.exports = { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: f36e50fd765d4017, + hash: d3ee7084bc938420, modules: Array [ Object { assets: Array [], @@ -319,7 +319,7 @@ module.exports = { entry ./fixtures/a cjs self exports reference self [195] ./fixtures/a.js - Rspack compiled successfully (f36e50fd765d4017) + Rspack compiled successfully (d3ee7084bc938420) `); } }; diff --git a/tests/rspack-test/statsAPICases/exports.js b/tests/rspack-test/statsAPICases/exports.js index a4d9cfe4fdbe..c0958da95b92 100644 --- a/tests/rspack-test/statsAPICases/exports.js +++ b/tests/rspack-test/statsAPICases/exports.js @@ -79,7 +79,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: 01b216cf5147ae81, + hash: 58302b97ac7f8626, id: 889, idHints: Array [], initial: true, @@ -467,7 +467,7 @@ module.exports = { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: 5a1a86e0fbb6505a, + hash: 8a01e1c2459a457e, modules: Array [ Object { assets: Array [], diff --git a/tests/rspack-test/statsAPICases/ids.js b/tests/rspack-test/statsAPICases/ids.js index 7f38b3663ba9..f038577a6313 100644 --- a/tests/rspack-test/statsAPICases/ids.js +++ b/tests/rspack-test/statsAPICases/ids.js @@ -58,7 +58,7 @@ module.exports = { files: Array [ main.js, ], - hash: b5cd62d7f1e244c4, + hash: 38a4677ffcccf553, id: 889, idHints: Array [], initial: true, diff --git a/tests/rspack-test/statsAPICases/with-query.js b/tests/rspack-test/statsAPICases/with-query.js index 25152c996ca2..f62fae5b0740 100644 --- a/tests/rspack-test/statsAPICases/with-query.js +++ b/tests/rspack-test/statsAPICases/with-query.js @@ -63,7 +63,7 @@ module.exports = { main.js, ], filteredModules: undefined, - hash: 216c30c6b146db6a, + hash: c7ed46ce8cf17581, id: 889, idHints: Array [], initial: true, @@ -432,7 +432,7 @@ module.exports = { errorsCount: 0, filteredAssets: undefined, filteredModules: undefined, - hash: 0cf5aaf453d712ad, + hash: 25924f9211365f23, modules: Array [ Object { assets: Array [], diff --git a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt index 4a43201e06f6..64212c289077 100644 --- a/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/all-stats/__snapshots__/stats.txt @@ -23,4 +23,4 @@ webpack/runtime/make_namespace_object xx bytes {main} [code generated] [no exports] [used exports unknown] -1970-04-20 12: Rspack x.x.x compiled successfully in X s (57e2ffc689d21328) \ No newline at end of file +1970-04-20 12: Rspack x.x.x compiled successfully in X s (a19f37e5e8587de1) \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/auxiliary-files-test/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/auxiliary-files-test/__snapshots__/stats.txt index 196d8bb1a56e..7693374aa48e 100644 --- a/tests/rspack-test/statsOutputCases/auxiliary-files-test/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/auxiliary-files-test/__snapshots__/stats.txt @@ -54,4 +54,4 @@ runtime modules xx KiB [no exports] [used exports unknown] -Rspack compiled successfully (bee7df9b548baf98) \ No newline at end of file +Rspack compiled successfully (0d9fb923e909ebfe) \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/commons-plugin-issue-4980/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/commons-plugin-issue-4980/__snapshots__/stats.txt index 19c9727bb971..ad7af390139b 100644 --- a/tests/rspack-test/statsOutputCases/commons-plugin-issue-4980/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/commons-plugin-issue-4980/__snapshots__/stats.txt @@ -1,9 +1,9 @@ -asset app.decef6386e7e7d32-1.js xx bytes [emitted] [immutable] (name: app) +asset app.39be147ee19168b4-1.js xx bytes [emitted] [immutable] (name: app) orphan modules xx bytes [orphan] 3 modules ./entry-1.js xx bytes [built] [code generated] Rspack x.x.x compiled successfully in X s -asset app.b65486f187f982bb-2.js xx bytes [emitted] [immutable] (name: app) +asset app.4591d16f7c49efa5-2.js xx bytes [emitted] [immutable] (name: app) orphan modules xx bytes [orphan] 3 modules ./entry-2.js xx bytes [built] [code generated] Rspack x.x.x compiled successfully in X s \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt index 44d5de67d09f..6abe51c4dd21 100644 --- a/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/immutable/__snapshots__/stats.txt @@ -1,2 +1,2 @@ -asset 888fc24a99342c5a.js xx KiB [emitted] [immutable] (name: main) -asset 5cd84ab679fd62af.js xx bytes [emitted] [immutable] \ No newline at end of file +asset e401b7acc241c902.js xx KiB [emitted] [immutable] (name: main) +asset 4123c33a1199d6db.js xx bytes [emitted] [immutable] \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt index d71ec43d635c..35632f6b0aad 100644 --- a/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/issue-7577/__snapshots__/stats.txt @@ -1,16 +1,16 @@ asset a-runtime~main-11cd436bbbc1c116.js xx KiB [emitted] [immutable] (name: runtime~main) asset a-main-c77a3d065156afc1.js xx bytes [emitted] [immutable] (name: main) -asset a-all-a_js-51f880c5bf774503.js xx bytes [emitted] [immutable] (id hint: all) -Entrypoint main xx KiB = a-runtime~main-11cd436bbbc1c116.js xx KiB a-all-a_js-51f880c5bf774503.js xx bytes a-main-c77a3d065156afc1.js xx bytes +asset a-all-a_js-9063e5bd4ab3ef51.js xx bytes [emitted] [immutable] (id hint: all) +Entrypoint main xx KiB = a-runtime~main-11cd436bbbc1c116.js xx KiB a-all-a_js-9063e5bd4ab3ef51.js xx bytes a-main-c77a3d065156afc1.js xx bytes runtime modules xx KiB 3 modules ./a.js xx bytes [built] [code generated] Rspack x.x.x compiled successfully in X s asset b-runtime~main-22cf12a92560e0a4.js xx KiB [emitted] [immutable] (name: runtime~main) asset b-main-e089c161fcafa0a5.js xx bytes [emitted] [immutable] (name: main) -asset b-all-b_js-63ff151d1000e301.js xx bytes [emitted] [immutable] (id hint: all) -asset b-vendors-node_modules_vendor_js-927ca68fe3cfdb29.js xx bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main xx KiB = b-runtime~main-22cf12a92560e0a4.js xx KiB b-vendors-node_modules_vendor_js-927ca68fe3cfdb29.js xx bytes b-all-b_js-63ff151d1000e301.js xx bytes b-main-e089c161fcafa0a5.js xx bytes +asset b-all-b_js-f91dcd8ab5fd5819.js xx bytes [emitted] [immutable] (id hint: all) +asset b-vendors-node_modules_vendor_js-42f46aded7bde86b.js xx bytes [emitted] [immutable] (id hint: vendors) +Entrypoint main xx KiB = b-runtime~main-22cf12a92560e0a4.js xx KiB b-vendors-node_modules_vendor_js-42f46aded7bde86b.js xx bytes b-all-b_js-f91dcd8ab5fd5819.js xx bytes b-main-e089c161fcafa0a5.js xx bytes runtime modules xx KiB 5 modules cacheable modules xx bytes ./b.js xx bytes [built] [code generated] @@ -18,12 +18,12 @@ cacheable modules xx bytes Rspack x.x.x compiled successfully in X s assets by chunk xx bytes (id hint: all) - asset c-all-b_js-e3933abfcccbcbe8.js xx bytes [emitted] [immutable] (id hint: all) - asset c-all-c_js-e739a3749165ad2d.js xx bytes [emitted] [immutable] (id hint: all) -asset c-runtime~main-2a2946b44c8c50c3.js xx KiB [emitted] [immutable] (name: runtime~main) + asset c-all-b_js-a47e287156676af1.js xx bytes [emitted] [immutable] (id hint: all) + asset c-all-c_js-32cdb8e87d873a2f.js xx bytes [emitted] [immutable] (id hint: all) +asset c-runtime~main-46bd2507bc44e493.js xx KiB [emitted] [immutable] (name: runtime~main) asset c-main-98aad2badde92840.js xx bytes [emitted] [immutable] (name: main) -asset c-vendors-node_modules_vendor_js-927ca68fe3cfdb29.js xx bytes [emitted] [immutable] (id hint: vendors) -Entrypoint main xx KiB = c-runtime~main-2a2946b44c8c50c3.js xx KiB c-all-c_js-e739a3749165ad2d.js xx bytes c-main-98aad2badde92840.js xx bytes +asset c-vendors-node_modules_vendor_js-42f46aded7bde86b.js xx bytes [emitted] [immutable] (id hint: vendors) +Entrypoint main xx KiB = c-runtime~main-46bd2507bc44e493.js xx KiB c-all-c_js-32cdb8e87d873a2f.js xx bytes c-main-98aad2badde92840.js xx bytes runtime modules xx KiB 13 modules cacheable modules xx bytes ./c.js xx bytes [built] [code generated] diff --git a/tests/rspack-test/statsOutputCases/preset-detailed/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/preset-detailed/__snapshots__/stats.txt index 5151d929e4b8..be31d0e4c34a 100644 --- a/tests/rspack-test/statsOutputCases/preset-detailed/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/preset-detailed/__snapshots__/stats.txt @@ -54,4 +54,4 @@ WARNING in ./index.js 3:1-17 · ─────── ╰──── -1970-04-20 12: Rspack x.x.x compiled with 2 warnings in X s (d2cff3f6f4e0a843) \ No newline at end of file +1970-04-20 12: Rspack x.x.x compiled with 2 warnings in X s (e340a34265153bc4) \ No newline at end of file diff --git a/tests/rspack-test/statsOutputCases/preset-verbose/__snapshots__/stats.txt b/tests/rspack-test/statsOutputCases/preset-verbose/__snapshots__/stats.txt index a45b1a12b770..2deaf5d122a4 100644 --- a/tests/rspack-test/statsOutputCases/preset-verbose/__snapshots__/stats.txt +++ b/tests/rspack-test/statsOutputCases/preset-verbose/__snapshots__/stats.txt @@ -134,4 +134,4 @@ WARNING in ./index.js 3:1-17 · ─────── ╰──── -1970-04-20 12: Rspack x.x.x compiled with 2 warnings in X s (d2cff3f6f4e0a843) \ No newline at end of file +1970-04-20 12: Rspack x.x.x compiled with 2 warnings in X s (e340a34265153bc4) \ No newline at end of file