refactor: split module_graph into ModuleGraphRef and ModuleGraphMut#12199
refactor: split module_graph into ModuleGraphRef and ModuleGraphMut#12199
Conversation
✅ Deploy Preview for rspack canceled.
|
📦 Binary Size-limit
🙈 Size remains the same at 47.45MB |
CodSpeed Performance ReportMerging #12199 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
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
ModuleGraphRefandModuleGraphMutwrapper types with appropriateDeref/DerefMutimplementations - Split the
new()constructor intonew_ref()andnew_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.
Summary
split ModuleGraph into ModuleGraphRef and ModuleGraphMut so it can disable call mutable method on readonlyGraph
Related links
Checklist