From d6c74bedc153e282536ca19ef02cabb77f595894 Mon Sep 17 00:00:00 2001 From: jerrykingxyz Date: Mon, 2 Sep 2024 17:12:08 +0800 Subject: [PATCH] fix(make): isolated module clean incomplete --- .../make/cutout/clean_isolated_module.rs | 6 +-- .../src/compiler/make/cutout/mod.rs | 4 +- crates/rspack_core/src/compiler/make/mod.rs | 41 +++++++++---------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/crates/rspack_core/src/compiler/make/cutout/clean_isolated_module.rs b/crates/rspack_core/src/compiler/make/cutout/clean_isolated_module.rs index 4e97216a661..48996bba926 100644 --- a/crates/rspack_core/src/compiler/make/cutout/clean_isolated_module.rs +++ b/crates/rspack_core/src/compiler/make/cutout/clean_isolated_module.rs @@ -31,8 +31,6 @@ impl CleanIsolatedModule { } pub fn fix_artifact(self, artifact: &mut MakeArtifact) { - let module_graph = artifact.get_module_graph_mut(); - let mut need_remove_modules = IdentifierSet::default(); let mut queue = VecDeque::from( self .need_check_isolated_module_ids @@ -40,6 +38,7 @@ impl CleanIsolatedModule { .collect::>(), ); while let Some(module_identifier) = queue.pop_front() { + let module_graph = artifact.get_module_graph(); let Some(mgm) = module_graph.module_graph_module_by_identifier(&module_identifier) else { tracing::trace!("Module is cleaned: {}", module_identifier); continue; @@ -53,9 +52,8 @@ impl CleanIsolatedModule { // clean child module queue.push_back(*connection.module_identifier()); } + artifact.revoke_module(&module_identifier); tracing::trace!("Module is cleaned: {}", module_identifier); - need_remove_modules.insert(module_identifier); } - artifact.revoke_modules(need_remove_modules); } } diff --git a/crates/rspack_core/src/compiler/make/cutout/mod.rs b/crates/rspack_core/src/compiler/make/cutout/mod.rs index 023261ce6a3..281a0cf4809 100644 --- a/crates/rspack_core/src/compiler/make/cutout/mod.rs +++ b/crates/rspack_core/src/compiler/make/cutout/mod.rs @@ -125,7 +125,9 @@ impl Cutout { } // do revoke module and collect deps - force_build_deps.extend(artifact.revoke_modules(force_build_modules)); + for id in force_build_modules { + force_build_deps.extend(artifact.revoke_module(&id)); + } let mut module_graph = artifact.get_module_graph_mut(); for dep_id in remove_entry_deps { diff --git a/crates/rspack_core/src/compiler/make/mod.rs b/crates/rspack_core/src/compiler/make/mod.rs index 4ae78b71481..d4497dea0ff 100644 --- a/crates/rspack_core/src/compiler/make/mod.rs +++ b/crates/rspack_core/src/compiler/make/mod.rs @@ -10,6 +10,7 @@ use rustc_hash::FxHashSet as HashSet; use self::{cutout::Cutout, repair::repair}; use crate::{ utils::FileCounter, BuildDependency, Compilation, DependencyId, ModuleGraph, ModuleGraphPartial, + ModuleIdentifier, }; #[derive(Debug, Default)] @@ -55,30 +56,26 @@ impl MakeArtifact { std::mem::take(&mut self.built_modules) } - fn revoke_modules(&mut self, ids: IdentifierSet) -> Vec { + fn revoke_module(&mut self, module_identifier: &ModuleIdentifier) -> Vec { let mut module_graph = ModuleGraph::new(vec![], Some(&mut self.module_graph_partial)); - let mut res = vec![]; - for module_identifier in &ids { - let module = module_graph - .module_by_identifier(module_identifier) - .expect("should have module"); - if let Some(build_info) = module.build_info() { - self - .file_dependencies - .remove_batch_file(&build_info.file_dependencies); - self - .context_dependencies - .remove_batch_file(&build_info.context_dependencies); - self - .missing_dependencies - .remove_batch_file(&build_info.missing_dependencies); - self - .build_dependencies - .remove_batch_file(&build_info.build_dependencies); - } - res.extend(module_graph.revoke_module(module_identifier)); + let module = module_graph + .module_by_identifier(module_identifier) + .expect("should have module"); + if let Some(build_info) = module.build_info() { + self + .file_dependencies + .remove_batch_file(&build_info.file_dependencies); + self + .context_dependencies + .remove_batch_file(&build_info.context_dependencies); + self + .missing_dependencies + .remove_batch_file(&build_info.missing_dependencies); + self + .build_dependencies + .remove_batch_file(&build_info.build_dependencies); } - res + module_graph.revoke_module(module_identifier) } pub fn reset_dependencies_incremental_info(&mut self) {