Skip to content

Commit 70ffab9

Browse files
authored
refactor: unify artifact clear logic (#12677)
1 parent 2feb455 commit 70ffab9

File tree

6 files changed

+54
-26
lines changed

6 files changed

+54
-26
lines changed

crates/rspack_core/src/compilation/build_chunk_graph/code_splitter.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ impl CodeSplitter {
404404
)
405405
{
406406
incremental_diagnostic = diagnostic;
407-
compilation.chunk_render_artifact.clear();
408407
}
409408
}
410409

crates/rspack_core/src/compilation/mod.rs

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,10 +1254,16 @@ impl Compilation {
12541254
"Chunk filename that dependent on full hash",
12551255
"chunk filename that dependent on full hash is not supported in incremental compilation",
12561256
)
1257+
&& let Some(diagnostic) = diagnostic
1258+
{
1259+
self.push_diagnostic(diagnostic);
1260+
}
1261+
1262+
// Check if CHUNKS_RENDER pass is disabled, and clear artifact if needed
1263+
if !self
1264+
.incremental
1265+
.passes_enabled(IncrementalPasses::CHUNKS_RENDER)
12571266
{
1258-
if let Some(diagnostic) = diagnostic {
1259-
self.push_diagnostic(diagnostic);
1260-
}
12611267
self.chunk_render_artifact.clear();
12621268
}
12631269

@@ -1292,7 +1298,6 @@ impl Compilation {
12921298
));
12931299
chunks
12941300
} else {
1295-
self.chunk_render_artifact.clear();
12961301
self.chunk_by_ukey.keys().copied().collect()
12971302
};
12981303
let results = rspack_futures::scope::<_, Result<_>>(|token| {
@@ -1732,6 +1737,14 @@ impl Compilation {
17321737

17331738
let start = logger.time("module ids");
17341739

1740+
// Check if MODULE_IDS pass is disabled, and clear artifact if needed
1741+
if !self
1742+
.incremental
1743+
.passes_enabled(IncrementalPasses::MODULE_IDS)
1744+
{
1745+
self.module_ids_artifact.clear();
1746+
}
1747+
17351748
let mut diagnostics = vec![];
17361749
let mut module_ids_artifact = mem::take(&mut self.module_ids_artifact);
17371750
plugin_driver
@@ -1745,6 +1758,15 @@ impl Compilation {
17451758
logger.time_end(start);
17461759

17471760
let start = logger.time("chunk ids");
1761+
1762+
// Check if CHUNK_IDS pass is disabled, and clear artifact if needed
1763+
if !self
1764+
.incremental
1765+
.passes_enabled(IncrementalPasses::CHUNK_IDS)
1766+
{
1767+
self.named_chunk_ids_artifact.clear();
1768+
}
1769+
17481770
let mut diagnostics = vec![];
17491771
let mut chunk_by_ukey = mem::take(&mut self.chunk_by_ukey);
17501772
let mut named_chunk_ids_artifact = mem::take(&mut self.named_chunk_ids_artifact);
@@ -1775,6 +1797,14 @@ impl Compilation {
17751797
.map_err(|e| e.wrap_err("caused by plugins in Compilation.hooks.optimizeCodeGeneration"))?;
17761798
logger.time_end(start);
17771799

1800+
// Check if MODULES_HASHES pass is disabled, and clear artifact if needed
1801+
if !self
1802+
.incremental
1803+
.passes_enabled(IncrementalPasses::MODULES_HASHES)
1804+
{
1805+
self.cgm_hash_artifact.clear();
1806+
}
1807+
17781808
let create_module_hashes_modules = if let Some(mutations) = self
17791809
.incremental
17801810
.mutations_read(IncrementalPasses::MODULES_HASHES)
@@ -1851,7 +1881,6 @@ impl Compilation {
18511881

18521882
modules
18531883
} else {
1854-
self.cgm_hash_artifact.clear();
18551884
self.get_module_graph().modules().keys().copied().collect()
18561885
};
18571886
self
@@ -1947,6 +1976,15 @@ impl Compilation {
19471976
)
19481977
.await?;
19491978
let runtime_chunks = self.get_chunk_graph_entries().collect();
1979+
1980+
// Check if CHUNKS_RUNTIME_REQUIREMENTS pass is disabled, and clear artifact if needed
1981+
if !self
1982+
.incremental
1983+
.passes_enabled(IncrementalPasses::CHUNKS_RUNTIME_REQUIREMENTS)
1984+
{
1985+
self.cgc_runtime_requirements_artifact.clear();
1986+
}
1987+
19501988
let process_runtime_requirements_chunks = if let Some(mutations) = self
19511989
.incremental
19521990
.mutations_read(IncrementalPasses::CHUNKS_RUNTIME_REQUIREMENTS)
@@ -1979,7 +2017,6 @@ impl Compilation {
19792017
));
19802018
affected_chunks
19812019
} else {
1982-
self.cgc_runtime_requirements_artifact.clear();
19832020
self.chunk_by_ukey.keys().copied().collect()
19842021
};
19852022
self
@@ -2350,10 +2387,14 @@ impl Compilation {
23502387
"Chunk content that dependent on full hash",
23512388
"it requires calculating the hashes of all the chunks, which is a global effect",
23522389
)
2390+
&& let Some(diagnostic) = diagnostic
2391+
{
2392+
self.push_diagnostic(diagnostic);
2393+
}
2394+
if !self
2395+
.incremental
2396+
.passes_enabled(IncrementalPasses::CHUNKS_HASHES)
23532397
{
2354-
if let Some(diagnostic) = diagnostic {
2355-
self.push_diagnostic(diagnostic);
2356-
}
23572398
self.chunk_hashes_artifact.clear();
23582399
}
23592400

@@ -2382,7 +2423,6 @@ impl Compilation {
23822423
));
23832424
chunks
23842425
} else {
2385-
self.chunk_hashes_artifact.clear();
23862426
self.chunk_by_ukey.keys().copied().collect()
23872427
};
23882428

crates/rspack_plugin_javascript/src/plugin/flag_dependency_usage_plugin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,6 @@ async fn optimize_dependencies(
501501
"it requires calculating the used exports based on all modules, which is a global effect",
502502
) {
503503
diagnostics.extend(diagnostic);
504-
// compilation.cgm_hash_artifact.clear();
505504
}
506505

507506
let mut proxy =

crates/rspack_plugin_javascript/src/plugin/inline_exports_plugin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ async fn optimize_dependencies(
107107
"it requires calculating the export names of all the modules, which is a global effect",
108108
) {
109109
diagnostics.extend(diagnostic);
110-
//compilation.cgm_hash_artifact.clear();
111110
}
112111

113112
let mg = build_module_graph_artifact.get_module_graph_mut();

crates/rspack_plugin_javascript/src/plugin/mangle_exports_plugin.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ async fn optimize_code_generation(&self, compilation: &mut Compilation) -> Resul
6464
IncrementalPasses::MODULES_HASHES,
6565
"MangleExportsPlugin (optimization.mangleExports = true)",
6666
"it requires calculating the export names of all the modules, which is a global effect",
67-
) {
68-
if let Some(diagnostic) = diagnostic {
69-
compilation.push_diagnostic(diagnostic);
70-
}
71-
compilation.cgm_hash_artifact.clear();
67+
) && let Some(diagnostic) = diagnostic
68+
{
69+
compilation.push_diagnostic(diagnostic);
7270
}
7371

7472
let mg = compilation.get_module_graph_mut();

crates/rspack_plugin_javascript/src/plugin/module_concatenation_plugin.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,15 +1402,8 @@ async fn optimize_chunk_modules(&self, compilation: &mut Compilation) -> Result<
14021402
| IncrementalPasses::CHUNKS_HASHES,
14031403
"ModuleConcatenationPlugin (optimization.concatenateModules = true)",
14041404
"it requires calculating the modules that can be concatenated based on all the modules, which is a global effect",
1405-
) {
1406-
if let Some(diagnostic) = diagnostic {
1405+
) && let Some(diagnostic) = diagnostic {
14071406
compilation.push_diagnostic(diagnostic);
1408-
}
1409-
compilation.cgm_hash_artifact.clear();
1410-
compilation.module_ids_artifact.clear();
1411-
compilation.named_chunk_ids_artifact.clear();
1412-
compilation.cgc_runtime_requirements_artifact.clear();
1413-
compilation.chunk_hashes_artifact.clear();
14141407
}
14151408

14161409
self.optimize_chunk_modules_impl(compilation).await?;

0 commit comments

Comments
 (0)