Skip to content

Commit

Permalink
fix: topological order when optimize incoming connections
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Aug 28, 2024
1 parent a154fcf commit ecad6bc
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 154 deletions.
27 changes: 16 additions & 11 deletions crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,20 +1077,11 @@ impl Compilation {
.finish_modules
.call(self)
.await?;
logger.time_end(start);
// Collect dependencies diagnostics at here to make sure:
// 1. after finish_modules: has provide exports info
// 2. before optimize dependencies: side effects free module hasn't been skipped (move_target)
let module_graph = self.get_module_graph();
let diagnostics: Vec<_> = module_graph
.module_graph_modules()
.par_iter()
.flat_map(|(_, mgm)| &mgm.all_dependencies)
.filter_map(|dependency_id| module_graph.dependency_by_id(dependency_id))
.filter_map(|dependency| dependency.get_diagnostics(&module_graph))
.flat_map(|ds| ds)
.collect();
self.extend_diagnostics(diagnostics);
logger.time_end(start);
self.collect_dependencies_diagnostics();

// take make diagnostics
let diagnostics = self.make_artifact.take_diagnostics();
Expand All @@ -1110,6 +1101,20 @@ impl Compilation {
Ok(())
}

#[tracing::instrument(skip_all)]
fn collect_dependencies_diagnostics(&mut self) {
let module_graph = self.get_module_graph();
let diagnostics: Vec<_> = module_graph
.module_graph_modules()
.par_iter()
.flat_map(|(_, mgm)| &mgm.all_dependencies)
.filter_map(|dependency_id| module_graph.dependency_by_id(dependency_id))
.filter_map(|dependency| dependency.get_diagnostics(&module_graph))
.flat_map(|ds| ds)
.collect();
self.extend_diagnostics(diagnostics);
}

#[instrument(name = "compilation:seal", skip_all)]
pub async fn seal(&mut self, plugin_driver: SharedPluginDriver) -> Result<()> {
self.other_module_graph = Some(ModuleGraphPartial::default());
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,7 +1590,7 @@ pub struct ResolvedExportInfoTarget {
pub module: ModuleIdentifier,
pub export: Option<Vec<Atom>>,
/// using dependency id to retrieve Connection
connection: DependencyId,
pub connection: DependencyId,
}

#[derive(Clone, Debug)]
Expand Down
9 changes: 7 additions & 2 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,15 +1034,19 @@ impl<'a> ModuleGraph<'a> {
.insert(dep_id, DependencyExtraMeta { ids });
}

pub fn update_module(&mut self, dep_id: &DependencyId, module_id: &ModuleIdentifier) {
pub fn update_module(
&mut self,
dep_id: &DependencyId,
module_id: &ModuleIdentifier,
) -> Option<ConnectionId> {
let connection_id = *self
.connection_id_by_dependency_id(dep_id)
.expect("should have connection id");
let connection = self
.connection_by_connection_id_mut(&connection_id)
.expect("should have connection");
if connection.module_identifier() == module_id {
return;
return None;
}

// clone connection
Expand Down Expand Up @@ -1097,6 +1101,7 @@ impl<'a> ModuleGraph<'a> {
mgm.add_incoming_connection(new_connection_id);
mgm.remove_incoming_connection(&connection_id);
}
Some(new_connection_id)
}

pub fn get_exports_info(&self, module_identifier: &ModuleIdentifier) -> ExportsInfo {
Expand Down
Loading

0 comments on commit ecad6bc

Please sign in to comment.