Skip to content

refactor: split module_graph into ModuleGraphRef and ModuleGraphMut#12199

Merged
hardfist merged 2 commits intomainfrom
yj/split-module-graph
Nov 14, 2025
Merged

refactor: split module_graph into ModuleGraphRef and ModuleGraphMut#12199
hardfist merged 2 commits intomainfrom
yj/split-module-graph

Conversation

@hardfist
Copy link
Copy Markdown
Contributor

@hardfist hardfist commented Nov 14, 2025

Summary

split ModuleGraph into ModuleGraphRef and ModuleGraphMut so it can disable call mutable method on readonlyGraph

  • before
let mut mg = ModuleGraph::new([mg,None],None);
mg.add_dependency(xxx); // runtime error
  • current
let mut mg = ModuleGraph::new_ref([mg,None],None);
mg.add_dependency(xxx); // compile error

Related links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link
Copy Markdown

netlify bot commented Nov 14, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit ed8b1e2
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6916da543aebd0000835af0f

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: refactor labels Nov 14, 2025
@github-actions
Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing ed8b1e2 to fix: triple with windows-msvc doesn't support -Cforce-unwind-tables=no (#12196) by Fy

🙈 Size remains the same at 47.45MB

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Nov 14, 2025

CodSpeed Performance Report

Merging #12199 will not alter performance

Comparing yj/split-module-graph (ed8b1e2) with main (7d4a1a3)

Summary

✅ 17 untouched

@hardfist hardfist marked this pull request as ready for review November 14, 2025 08:00
Copilot AI review requested due to automatic review settings November 14, 2025 08:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the ModuleGraph type by introducing two wrapper types: ModuleGraphRef (read-only) and ModuleGraphMut (mutable). This change enforces compile-time safety by preventing mutable operations on read-only module graphs, converting what were previously runtime errors into compile-time errors.

Key changes:

  • Introduced ModuleGraphRef and ModuleGraphMut wrapper types with appropriate Deref/DerefMut implementations
  • Split the new() constructor into new_ref() and new_mut() factory methods
  • Updated all call sites throughout the codebase to use the new API consistently

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/rspack_core/src/module_graph/mod.rs Core refactoring: added ModuleGraphRef and ModuleGraphMut wrapper types with deref implementations and new constructor methods new_ref() and new_mut()
crates/rspack_core/src/compilation/mod.rs Updated get_module_graph() to return ModuleGraphRef and get_module_graph_mut() to return ModuleGraphMut; migrated from new() to new_ref()/new_mut()
crates/rspack_core/src/compilation/build_module_graph/artifact.rs Updated return types and method calls to use ModuleGraphRef/ModuleGraphMut and new constructor methods
crates/rspack_core/src/compilation/build_module_graph/graph_updater/repair/context.rs Updated get_module_graph_mut() return type to ModuleGraphMut and migrated to new_mut()
crates/rspack_core/src/compilation/build_module_graph/graph_updater/cutout/fix_issuers.rs Migrated all ModuleGraph::new() calls to ModuleGraph::new_mut() with unwrapped active parameter
crates/rspack_core/src/cache/persistent/occasion/make/module_graph.rs Migrated to new_ref() for read-only graphs and new_mut() for mutable graphs
crates/rspack_core/src/cache/persistent/occasion/make/mod.rs Migrated to new_ref() for read-only module graph creation
crates/rspack_binding_api/src/module_graph_connection.rs Updated as_ref() method to return ModuleGraphRef<'static>
crates/rspack_binding_api/src/module_graph.rs Updated as_ref() method to return ModuleGraphRef<'static>
crates/rspack_binding_api/src/exports_info.rs Updated as_ref() to return ModuleGraphRef and as_mut() to return ModuleGraphMut
crates/rspack_plugin_library/src/modern_module_library_plugin.rs Removed redundant type annotation, relying on type inference
crates/rspack_plugin_esm_library/src/link.rs Removed redundant type annotations, relying on type inference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hardfist hardfist enabled auto-merge (squash) November 14, 2025 08:04
@hardfist hardfist merged commit 711cb55 into main Nov 14, 2025
50 checks passed
@hardfist hardfist deleted the yj/split-module-graph branch November 14, 2025 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants