Skip to content

Commit cbf75a4

Browse files
authored
fix(incremental): disappeared chunk panic in chunks render (#8492)
1 parent 0891a65 commit cbf75a4

67 files changed

Lines changed: 123 additions & 15 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/rspack_core/src/compiler/compilation.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,9 @@ impl Compilation {
960960
for removed_chunk in removed_chunks {
961961
self.chunk_render_results.remove(&removed_chunk);
962962
}
963+
self
964+
.chunk_render_results
965+
.retain(|chunk, _| self.chunk_by_ukey.contains(chunk));
963966
mutations.get_affected_chunks_with_chunk_graph(self)
964967
} else {
965968
self.chunk_by_ukey.keys().copied().collect()
@@ -1111,7 +1114,7 @@ impl Compilation {
11111114
mutations.extend(
11121115
revoked_modules
11131116
.iter()
1114-
.map(|&module| Mutation::ModuleRevoke { module }),
1117+
.map(|&module| Mutation::ModuleRemove { module }),
11151118
);
11161119
mutations.extend(
11171120
built_modules
@@ -1147,7 +1150,7 @@ impl Compilation {
11471150
.mutations_read(IncrementalPasses::DEPENDENCIES_DIAGNOSTICS);
11481151
let modules = if let Some(mutations) = mutations {
11491152
let revoked_modules = mutations.iter().filter_map(|mutation| match mutation {
1150-
Mutation::ModuleRevoke { module } => Some(*module),
1153+
Mutation::ModuleRemove { module } => Some(*module),
11511154
_ => None,
11521155
});
11531156
for revoked_module in revoked_modules {
@@ -1204,6 +1207,9 @@ impl Compilation {
12041207
) {}
12051208
logger.time_end(start);
12061209

1210+
// ModuleGraph is frozen for now on, we have a module graph that won't change
1211+
// so now we can start to create a chunk graph based on the module graph
1212+
12071213
let start = logger.time("create chunks");
12081214
use_code_splitting_cache(self, |compilation| async {
12091215
build_chunk_graph(compilation)?;
@@ -1245,6 +1251,9 @@ impl Compilation {
12451251
.await?;
12461252
logger.time_end(start);
12471253

1254+
// ChunkGraph is frozen for now on, we have a chunk graph that won't change
1255+
// so now we can start to generate assets based on the chunk graph
1256+
12481257
let start = logger.time("module ids");
12491258
plugin_driver.compilation_hooks.module_ids.call(self)?;
12501259
logger.time_end(start);
@@ -1261,7 +1270,7 @@ impl Compilation {
12611270
.mutations_read(IncrementalPasses::MODULES_HASHES)
12621271
{
12631272
let revoked_modules = mutations.iter().filter_map(|mutation| match mutation {
1264-
Mutation::ModuleRevoke { module } => Some(*module),
1273+
Mutation::ModuleRemove { module } => Some(*module),
12651274
_ => None,
12661275
});
12671276
for revoked_module in revoked_modules {
@@ -1286,7 +1295,7 @@ impl Compilation {
12861295
.mutations_read(IncrementalPasses::MODULES_CODEGEN)
12871296
{
12881297
let revoked_modules = mutations.iter().filter_map(|mutation| match mutation {
1289-
Mutation::ModuleRevoke { module } => Some(*module),
1298+
Mutation::ModuleRemove { module } => Some(*module),
12901299
_ => None,
12911300
});
12921301
for revoked_module in revoked_modules {
@@ -1305,7 +1314,7 @@ impl Compilation {
13051314
.mutations_read(IncrementalPasses::MODULES_RUNTIME_REQUIREMENTS)
13061315
{
13071316
let revoked_modules = mutations.iter().filter_map(|mutation| match mutation {
1308-
Mutation::ModuleRevoke { module } => Some(*module),
1317+
Mutation::ModuleRemove { module } => Some(*module),
13091318
_ => None,
13101319
});
13111320
for revoked_module in revoked_modules {
@@ -1334,6 +1343,9 @@ impl Compilation {
13341343
for removed_chunk in removed_chunks {
13351344
self.cgc_runtime_requirements_results.remove(&removed_chunk);
13361345
}
1346+
self
1347+
.cgc_runtime_requirements_results
1348+
.retain(|chunk, _| self.chunk_by_ukey.contains(chunk));
13371349
mutations.get_affected_chunks_with_chunk_graph(self)
13381350
} else {
13391351
self.chunk_by_ukey.keys().copied().collect()
@@ -1364,6 +1376,9 @@ impl Compilation {
13641376
for removed_chunk in removed_chunks {
13651377
self.chunk_hashes_results.remove(&removed_chunk);
13661378
}
1379+
self
1380+
.chunk_hashes_results
1381+
.retain(|chunk, _| self.chunk_by_ukey.contains(chunk));
13671382
mutations.get_affected_chunks_with_chunk_graph(self)
13681383
} else {
13691384
self.chunk_by_ukey.keys().copied().collect()

crates/rspack_core/src/compiler/module_executor/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl ModuleExecutor {
151151
let built_modules = self.make_artifact.take_built_modules();
152152
if let Some(mutations) = compilation.incremental.mutations_write() {
153153
for id in &built_modules {
154-
mutations.add(Mutation::ModuleRevoke { module: *id });
154+
mutations.add(Mutation::ModuleRemove { module: *id });
155155
}
156156
}
157157
for id in built_modules {
@@ -161,7 +161,7 @@ impl ModuleExecutor {
161161
let revoked_modules = self.make_artifact.take_revoked_modules();
162162
if let Some(mutations) = compilation.incremental.mutations_write() {
163163
for id in revoked_modules {
164-
mutations.add(Mutation::ModuleRevoke { module: id });
164+
mutations.add(Mutation::ModuleRemove { module: id });
165165
}
166166
}
167167

crates/rspack_core/src/incremental/mutations.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use std::hash::{Hash, Hasher};
1+
use std::{
2+
fmt,
3+
hash::{Hash, Hasher},
4+
};
25

36
use once_cell::sync::OnceCell;
47
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
@@ -21,17 +24,43 @@ pub struct Mutations {
2124
affected_chunks_with_chunk_graph: OnceCell<UkeySet<ChunkUkey>>,
2225
}
2326

27+
impl fmt::Display for Mutations {
28+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29+
writeln!(f, "[")?;
30+
for mutation in self.iter() {
31+
writeln!(f, "{},", mutation)?;
32+
}
33+
writeln!(f, "]")
34+
}
35+
}
36+
2437
#[derive(Debug)]
2538
pub enum Mutation {
2639
ModuleBuild { module: ModuleIdentifier },
27-
ModuleRevoke { module: ModuleIdentifier },
40+
ModuleRemove { module: ModuleIdentifier },
2841
ModuleSetAsync { module: ModuleIdentifier },
2942
ChunkAdd { chunk: ChunkUkey },
3043
ChunkSplit { from: ChunkUkey, to: ChunkUkey },
3144
ChunksIntegrate { to: ChunkUkey },
3245
ChunkRemove { chunk: ChunkUkey },
3346
}
3447

48+
impl fmt::Display for Mutation {
49+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
50+
match self {
51+
Mutation::ModuleBuild { module } => write!(f, "build module {}", module),
52+
Mutation::ModuleRemove { module } => write!(f, "remove module {}", module),
53+
Mutation::ModuleSetAsync { module } => write!(f, "set async module {}", module),
54+
Mutation::ChunkAdd { chunk } => write!(f, "add chunk {}", chunk.as_u32()),
55+
Mutation::ChunkSplit { from, to } => {
56+
write!(f, "split chunk {} to {}", from.as_u32(), to.as_u32())
57+
}
58+
Mutation::ChunksIntegrate { to } => write!(f, "integrate chunks to {}", to.as_u32()),
59+
Mutation::ChunkRemove { chunk } => write!(f, "remove chunk {}", chunk.as_u32()),
60+
}
61+
}
62+
}
63+
3564
impl Mutations {
3665
pub fn add(&mut self, mutation: Mutation) {
3766
self.inner.push(mutation);
@@ -104,7 +133,7 @@ impl Mutations {
104133
self
105134
.iter()
106135
.filter_map(|mutation| match mutation {
107-
Mutation::ModuleRevoke { module } => Some(*module),
136+
Mutation::ModuleRemove { module } => Some(*module),
108137
_ => None,
109138
})
110139
.collect(),

crates/rspack_plugin_javascript/src/plugin/infer_async_modules_plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async fn finish_modules(&self, compilation: &mut Compilation) -> Result<()> {
2525
Mutation::ModuleBuild { module } => {
2626
acc.insert(*module);
2727
}
28-
Mutation::ModuleRevoke { module } => {
28+
Mutation::ModuleRemove { module } => {
2929
// we keep the state for the module only if the module revoke first, and then rebuild
3030
// otherwise we gc its state
3131
if !acc.contains(module) {

packages/rspack-test-tools/etc/test-tools.api.md

Lines changed: 2 additions & 2 deletions

packages/rspack-test-tools/src/processor/watch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,15 @@ export class WatchProcessor<
257257
}
258258

259259
static findBundle<T extends ECompilerType>(
260+
this: IWatchProcessorOptions<T>,
260261
index: number,
261262
context: ITestContext,
262263
options: TCompilerOptions<T>
263264
) {
264265
const testConfig = context.getTestConfig();
265266

266267
if (typeof testConfig.findBundle === "function") {
267-
return testConfig.findBundle!(index, options);
268+
return testConfig.findBundle!(index, options, this.stepName);
268269
}
269270
return "./bundle.js";
270271
}

packages/rspack-test-tools/src/type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ export type TTestConfig<T extends ECompilerType> = {
201201
) => boolean;
202202
findBundle?: (
203203
index: number,
204-
options: TCompilerOptions<T>
204+
options: TCompilerOptions<T>,
205+
stepName?: string
205206
) => string | string[];
206207
bundlePath?: string[];
207208
nonEsmThis?: (p: string | string[]) => Object;

packages/rspack-test-tools/tests/watchCases/split-chunks-incremental/available-modules-change/0/dyn-1.js renamed to packages/rspack-test-tools/tests/watchCases/build-chunk-graph/available-modules-change/0/dyn-1.js

File renamed without changes.

packages/rspack-test-tools/tests/watchCases/split-chunks-incremental/available-modules-change/0/dyn-2.js renamed to packages/rspack-test-tools/tests/watchCases/build-chunk-graph/available-modules-change/0/dyn-2.js

File renamed without changes.

packages/rspack-test-tools/tests/watchCases/split-chunks-incremental/available-modules-change/0/index.js renamed to packages/rspack-test-tools/tests/watchCases/build-chunk-graph/available-modules-change/0/index.js

File renamed without changes.

0 commit comments

Comments
 (0)