Skip to content

Commit

Permalink
fix: use cgm hash to verify rename inline modules cache (#8820)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk authored Dec 24, 2024
1 parent 4da33a8 commit c99e882
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
Vec<DependencyId>,
> = IndexMap::default();

for dep_id in module_graph.get_ordered_all_dependencies(&module) {
for dep_id in module_graph.get_ordered_outgoing_connections(&module) {
let dep = module_graph
.dependency_by_id(dep_id)
.expect("should have dep");
Expand Down
9 changes: 7 additions & 2 deletions crates/rspack_core/src/chunk_graph/chunk_graph_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ impl ChunkGraph {
let mg = compilation.get_module_graph();
let mut visited_modules = IdentifierSet::default();
visited_modules.insert(module.identifier());
for connection in mg.get_outgoing_connections(&module.identifier()) {
for connection in mg
.get_ordered_outgoing_connections(&module.identifier())
.filter_map(|c| mg.connection_by_dependency_id(c))
{
let module_identifier = connection.module_identifier();
if visited_modules.contains(module_identifier) {
continue;
Expand All @@ -284,7 +287,9 @@ impl ChunkGraph {
.expect("should have module")
.as_ref();
module.get_exports_type(&mg, strict).hash(&mut hasher);
self.get_module_graph_hash_without_connections(module, compilation, runtime);
self
.get_module_graph_hash_without_connections(module, compilation, runtime)
.hash(&mut hasher);
}
hasher.finish()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ impl<'a> ModuleGraph<'a> {
exports_info.get_export_info(self, export_name)
}

pub(crate) fn get_ordered_all_dependencies(
pub(crate) fn get_ordered_outgoing_connections(
&self,
module_identifier: &ModuleIdentifier,
) -> impl Iterator<Item = &DependencyId> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn esm_import_dependency_apply<T: ModuleDependency>(
} = code_generatable_context;
let ref_module = module_graph.module_identifier_by_dependency_id(module_dependency.id());
let import_var = compilation.get_import_var(module_dependency.id());
//

// https://github.com/webpack/webpack/blob/ac7e531436b0d47cd88451f497cdfd0dad41535d/lib/dependencies/HarmonyImportDependency.js#L282-L285
let module_key = ref_module
.map(|i| i.as_str())
Expand Down
7 changes: 5 additions & 2 deletions crates/rspack_plugin_javascript/src/plugin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,11 +912,12 @@ impl JsPlugin {
module_scope_idents,
used_in_non_inlined: Vec::new(),
};
let runtime = compilation.chunk_by_ukey.expect_get(chunk_ukey).runtime();

self.rename_module_cache.inlined_modules_to_info.insert(
ident,
WithHash {
hash: m.build_info().and_then(|i| i.hash.clone()),
hash: ChunkGraph::get_module_hash(compilation, ident, runtime).cloned(),
value: info.clone(),
},
);
Expand All @@ -925,6 +926,7 @@ impl JsPlugin {
} else {
let mut idents_vec = vec![];
let module_ident = m.identifier();
let runtime = compilation.chunk_by_ukey.expect_get(chunk_ukey).runtime();

for ident in collector.ids {
if ident.id.ctxt == global_ctxt {
Expand All @@ -940,7 +942,8 @@ impl JsPlugin {
.insert(
module_ident,
WithHash {
hash: m.build_info().and_then(|i| i.hash.clone()),
hash: ChunkGraph::get_module_hash(compilation, module_ident, runtime)
.cloned(),
value: idents_vec.clone(),
},
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const v = 'foo'
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {value} from "./module";

it("should have correct export from re-exports", function () {
expect(value).toBe("foo");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {v} from './reexports'
export const value = '' + v;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import {v} from './foo';
export {v};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { v } from "./reexports-deep";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { v as value } from "./reexports";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @type {import("@rspack/core").Configuration} */
module.exports = {
optimization: {
sideEffects: true,
providedExports: true,
}
};

0 comments on commit c99e882

Please sign in to comment.