Skip to content

Commit

Permalink
chore: 🤖 opt
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Sep 21, 2023
1 parent 19a2ec3 commit d45cf93
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 32 deletions.
2 changes: 1 addition & 1 deletion crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn samples(fixture_path: PathBuf) {
fn tree_shaking(fixture_path: PathBuf) {
// For each test case
// First test is old version tree shaking snapshot test
test_fixture(&fixture_path, Box::new(|_, _| {}), None);
// test_fixture(&fixture_path, Box::new(|_, _| {}), None);
// second test is webpack based tree shaking
test_fixture(
&fixture_path,
Expand Down
11 changes: 6 additions & 5 deletions crates/rspack/tests/tree-shaking/bb/a.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { d, c } from "./b.js";
// import { d, c } from "./b.js";
export * from "./c.js";
export const a = 3;

d;
export { c };
export * from './b.js'
// export const a = 3;
//
// d;
// export { c };
22 changes: 9 additions & 13 deletions crates/rspack/tests/tree-shaking/bb/snapshot/new_treeshaking.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ source: crates/rspack_testing/src/run_fixture.rs
"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'c': function() { return _b_js__WEBPACK_IMPORTED_MODULE_0_.c; }
});
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");
/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js");
__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);
const a = 3;
_b_js__WEBPACK_IMPORTED_MODULE_0_.d;
/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./c.js */"./c.js");
__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_0_, __webpack_exports__);
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./b.js */"./b.js");
__webpack_require__.es(_b_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);
// import { d, c } from "./b.js";
// export const a = 3;
//
// d;
// export { c };
},
"./b.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'd': function() { return d; }
});
const d = 3;
const c = 100;
},
Expand Down
12 changes: 11 additions & 1 deletion crates/rspack/tests/tree-shaking/bb/snapshot/snap.diff
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- expected
+++ actual
@@ -6,6 +6,9 @@
@@ -6,30 +6,26 @@
"./a.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
Expand All @@ -10,3 +10,13 @@
/* harmony import */var _b_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./b.js */"./b.js");
/* harmony import */var _c_js__WEBPACK_IMPORTED_MODULE_1_ = __webpack_require__(/* ./c.js */"./c.js");
__webpack_require__.es(_c_js__WEBPACK_IMPORTED_MODULE_1_, __webpack_exports__);
@@ -27,9 +30,6 @@
"./c.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
-__webpack_require__.d(__webpack_exports__, {
- 'ccc': function() { return ccc; }
-});
const ccc = 30;
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
17 changes: 12 additions & 5 deletions crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,18 @@ impl ChunkGraph {
.module_by_identifier(&module)
.expect("should exist");
for connection in module_graph.get_outgoing_connections(module) {
// TODO: consider activeState
// if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) {
// add_dependencies(connection.module_identifier, set, module_graph);
// continue;
// }
// TODO: add runtime after runtime opt
let active_state = connection.get_active_state(module_graph, None);
match active_state {
crate::ConnectionState::Bool(false) => {
continue;
}
crate::ConnectionState::TransitiveOnly => {
add_dependencies(connection.module_identifier, set, module_graph);
continue;
}
_ => {}
}
set.insert(connection.module_identifier);
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_core/src/chunk_graph/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rspack_identifier::IdentifierMap;
use rustc_hash::FxHashMap as HashMap;

use crate::{ChunkGroupUkey, ChunkUkey};
use crate::{ChunkGroupUkey, ChunkUkey, CompilerOptions};

pub mod chunk_graph_chunk;
pub mod chunk_graph_module;
Expand Down
11 changes: 8 additions & 3 deletions crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,14 @@ impl Compilation {
while plugin_driver.optimize_dependencies(self).await?.is_some() {}
logger.time_end(start);

// if self.options.is_new_tree_shaking() {
// debug_exports_info(&self.module_graph);
// }
if self.options.is_new_tree_shaking() {
// self
// .module_graph
// .module_graph_modules()
// .values()
// .foreach(|item| {});
// debug_exports_info(&self.module_graph);
}

let start = logger.time("create chunks");
use_code_splitting_cache(self, |compilation| async {
Expand Down
29 changes: 26 additions & 3 deletions crates/rspack_core/src/module_graph_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ impl ModuleGraphModule {

pub fn depended_modules<'a>(&self, module_graph: &'a ModuleGraph) -> Vec<&'a ModuleIdentifier> {
self
.dependencies
.iter()
.outgoing_connections_unordered(module_graph)
.unwrap()
.filter_map(|con: &ModuleGraphConnection| {
// TODO: runtime opt
let active_state = con.get_active_state(module_graph, None);
match active_state {
crate::ConnectionState::Bool(false) => None,
_ => Some(con.dependency_id),
}
})
.filter(|id| {
if let Some(dep) = module_graph
.dependency_by_id(id)
Expand All @@ -136,8 +144,23 @@ impl ModuleGraphModule {
}
false
})
.filter_map(|id| module_graph.module_identifier_by_dependency_id(id))
.filter_map(|id| module_graph.module_identifier_by_dependency_id(&id))
.collect()
// self
// .dependencies
// .iter()
// .filter(|id| {
// if let Some(dep) = module_graph
// .dependency_by_id(id)
// .expect("should have id")
// .as_module_dependency()
// {
// return !is_async_dependency(dep) && !dep.weak();
// }
// false
// })
// .filter_map(|id| module_graph.module_identifier_by_dependency_id(id))
// .collect()
}

pub fn dynamic_depended_modules<'a>(
Expand Down

0 comments on commit d45cf93

Please sign in to comment.