Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: inner graph part one #4176

Merged
merged 43 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
ffd9a5f
feat: inner graph
underfin Sep 11, 2023
40d84a1
chore: 🤖 lint
IWANABETHATGUY Sep 12, 2023
2c15cae
chore: 🤖 ck point
IWANABETHATGUY Sep 21, 2023
49beb0a
chore: 🤖 ckpoint
IWANABETHATGUY Sep 22, 2023
0570eea
chore: 🤖 ck point
IWANABETHATGUY Sep 22, 2023
8edf50a
test: 💍 chore
IWANABETHATGUY Sep 23, 2023
d4337c6
chore: 🤖 add usage
IWANABETHATGUY Sep 23, 2023
fae3000
chore: 🤖 refactor
IWANABETHATGUY Sep 24, 2023
0ac7322
chore: 🤖 add usage
IWANABETHATGUY Sep 24, 2023
b5cdeb1
chore: 🤖 add usage
IWANABETHATGUY Sep 24, 2023
28363d5
chore: 🤖 remove temp file
IWANABETHATGUY Sep 24, 2023
a58927a
chore: 🤖 add rewrite usage span to record usage to rewrite
IWANABETHATGUY Sep 24, 2023
f2f535a
chore: 🤖 update toplevel
IWANABETHATGUY Sep 26, 2023
02bf23a
chore: 🤖 add scope level
IWANABETHATGUY Sep 27, 2023
5a28b47
chore: 🤖 ck point
IWANABETHATGUY Sep 27, 2023
78c9c85
chore: 🤖 update
IWANABETHATGUY Oct 3, 2023
dadabfd
chore: 🤖 update
IWANABETHATGUY Oct 3, 2023
f9ff746
chore: 🤖 refactor
IWANABETHATGUY Oct 11, 2023
2f8a5a1
feat: 🎸 finalize_usage
IWANABETHATGUY Oct 11, 2023
4481a73
chore: 🤖 refactor error span
IWANABETHATGUY Oct 11, 2023
85d0691
feat: 🎸 import specifier on usage
IWANABETHATGUY Oct 11, 2023
def95b6
fix: 🐛 compile issue
IWANABETHATGUY Oct 12, 2023
e0557ff
chore: 🤖 add inner graph options
IWANABETHATGUY Oct 12, 2023
35ed203
chore: 🤖 lint
IWANABETHATGUY Oct 12, 2023
135fefb
chore: 🤖 update
IWANABETHATGUY Oct 12, 2023
914647e
chore: 🤖 update
IWANABETHATGUY Oct 12, 2023
83f6202
chore: 🤖 update
IWANABETHATGUY Oct 12, 2023
331e988
chore: 🤖 update
IWANABETHATGUY Oct 12, 2023
b8225b3
chore: 🤖 update snapshot
IWANABETHATGUY Oct 12, 2023
8355237
chore: 🤖 update
IWANABETHATGUY Oct 13, 2023
2b4575d
chore: 🤖 lint
IWANABETHATGUY Oct 13, 2023
b08fcc2
chore: 🤖 update check
IWANABETHATGUY Oct 13, 2023
2b4b02a
chore: 🤖 default js
IWANABETHATGUY Oct 13, 2023
be24ac7
chore: 🤖 recover
IWANABETHATGUY Oct 13, 2023
5adcd1e
chore: 🤖 update display
IWANABETHATGUY Oct 13, 2023
4191370
chore: 🤖 update add variable usage
IWANABETHATGUY Oct 16, 2023
be0d8c5
chore: 🤖 update add variable usage
IWANABETHATGUY Oct 16, 2023
c94ba9e
chore: 🤖 fix var decl inner graph
IWANABETHATGUY Oct 16, 2023
bc1da54
chore: 🤖 update more test case
IWANABETHATGUY Oct 16, 2023
cd0e5d7
chore: 🤖 update snap
IWANABETHATGUY Oct 16, 2023
f17e750
chore: 🤖 update snap
IWANABETHATGUY Oct 17, 2023
9c811b5
chore: 🤖 lint
IWANABETHATGUY Oct 17, 2023
bcb607d
chore: 🤖 update snapshot
IWANABETHATGUY Oct 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,7 @@ export interface RawOptimizationOptions {
sideEffects: string
usedExports: string
providedExports: boolean
innerGraph: boolean
realContentHash: boolean
}

Expand Down
59 changes: 43 additions & 16 deletions crates/rspack/tests/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ const fs = require("fs");

const currentDir = path.resolve(__dirname, "./tree-shaking");
const dirList = fs.readdirSync(currentDir);
const excludeList = ["node_modules"]

const excludeList = ["node_modules"];

const filteredList = dirList.filter((dir) => {
if (dir.startsWith(".")) {
Expand All @@ -17,19 +16,47 @@ const filteredList = dirList.filter((dir) => {
return true;
});

console.log(`total: ${filteredList.length}`)
console.log(`total: ${filteredList.length}`);

const falsePositiveList = [
'cjs-export-computed-property', // This one is false positive because webpack will not counted a esm export as unsed in an entry module, the previous implementation follows the esbuild behavior , see https://gist.github.com/IWANABETHATGUY/b41d0f80a558580010276a44b310a473
]
const failedList = filteredList.filter(item => {
if (falsePositiveList.includes(item)) {
return false;
}
const abPath = path.join(currentDir, item, "snapshot", "snap.diff")
return fs.existsSync(abPath)
})
const falsePositiveMap = {
"cjs-export-computed-property":
"This one is false positive because webpack will not counted a esm export as unsed in an entry module, the previous implementation follows the esbuild behavior , see https://gist.github.com/IWANABETHATGUY/b41d0f80a558580010276a44b310a473",
basic: "align webpack unused binding behavior",
"context-module-elimated": "align webpack unused binding behavior",
"rollup-unused-called-import": "align webpack unused binding behavior",
"var-function-expr": "align webpack unused binding behavior",
"webpack-innergraph-no-side-effects": "align webpack unused binding behavior",
"side-effects-export-default-expr": "align webpack unused binding behavior"
};

const normalizedList = filteredList.map((item) => {
const abPath = path.join(currentDir, item, "snapshot", "snap.diff");
let status = fs.existsSync(abPath);
return {
name: item,
reason: falsePositiveMap[item],
passed: !status,
};
});

let successedCount = normalizedList.filter((item) => {
return item.passed || !!item.reason;
}).length;

let fasePositiveCases = normalizedList
.filter((item) => {
return !!item.reason;
})
.map((item) => {
return `${item.name}: ${item.reason}`;
});
let failedCases = normalizedList
.filter((item) => !item.passed && !item.reason)
.map((item) => {
return item.name;
});

console.log(`failed: ${failedList.length}`)
console.log(`passed: ${filteredList.length - failedList.length}`)
console.log('failed list:\n', failedList)
console.log(`failed: ${filteredList.length - successedCount}`);
console.log(`passed: ${successedCount}`);
console.log(`fasePositiveCases: ${fasePositiveCases.length}\n`, fasePositiveCases);
console.log(`failedCases: ${failedCases.length}\n`, failedCases);
3 changes: 2 additions & 1 deletion crates/rspack/tests/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,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
IS_NEW_TREESHAKING.store(true, Ordering::SeqCst);
test_fixture(
Expand All @@ -34,6 +34,7 @@ fn tree_shaking(fixture_path: PathBuf) {
|plugins: &mut Vec<BoxPlugin>, options: &mut CompilerOptions| {
options.experiments.rspack_future.new_treeshaking = true;
options.optimization.provided_exports = true;
options.optimization.inner_graph = true;
options.optimization.used_exports = UsedExportsOption::True;
options.builtins.tree_shaking = TreeShaking::False;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ setTimeout(()=>{
function render() {
function test() {
const container = document.getElementById("root");
container.innerHTML = `adddd333:${_lib__WEBPACK_IMPORTED_MODULE_0_.secret}:${_lib__WEBPACK_IMPORTED_MODULE_0_.myanswer}`;
container.innerHTML = `adddd333:${secret}:${myanswer}`;
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
Expand All @@ -39,7 +39,6 @@ __webpack_require__.r(__webpack_exports__);
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'secret': function() { return secret; },
'myanswer': function() { return myanswer; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js");
Expand Down
10 changes: 1 addition & 9 deletions crates/rspack/tests/tree-shaking/basic/snapshot/snap.diff
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@
function test() {
const container = document.getElementById("root");
- container.innerHTML = `adddd333:${/* "./lib" unused */null}:${_lib__WEBPACK_IMPORTED_MODULE_0_.myanswer}`;
+ container.innerHTML = `adddd333:${_lib__WEBPACK_IMPORTED_MODULE_0_.secret}:${_lib__WEBPACK_IMPORTED_MODULE_0_.myanswer}`;
+ container.innerHTML = `adddd333:${secret}:${myanswer}`;
IWANABETHATGUY marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (module.hot?.accept) module.hot.accept((module1)=>{
@@ -39,6 +39,7 @@
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
+ 'secret': function() { return secret; },
'myanswer': function() { return myanswer; }
});
/* harmony import */var _answer__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./answer */"./answer.js");
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ __webpack_require__.d(__webpack_exports__, {
}
function foo() {
return {
OriginLib: _lib__WEBPACK_IMPORTED_MODULE_0_.Lib
OriginLib
};
}
const v = _lib__WEBPACK_IMPORTED_MODULE_0_.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
function foo() {
return {
- OriginLib: /* "./lib" unused */null
+ OriginLib: _lib__WEBPACK_IMPORTED_MODULE_0_.Lib
+ OriginLib
};
}
const v = _lib__WEBPACK_IMPORTED_MODULE_0_.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,14 @@ source: crates/rspack_testing/src/run_fixture.rs
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
"./child/child/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'value': function() { return value; }
});
const value = "dynamic";
},
"./child/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'value': function() { return value; }
});
const value = "dynamic";
},
"./child Sync recursive ^\\.\\/.*\\.js$": function (module, exports, __webpack_require__) {
var map = {"./child/index.js": "./child/child/index.js","./index.js": "./child/index.js",};
function webpackContext(req) {
var id = webpackContextResolve(req);

return __webpack_require__(id);

}
function webpackContextResolve(req) {

if(!__webpack_require__.o(map, req)) {
var e = new Error("Cannot find module '" + req + "'");
e.code = 'MODULE_NOT_FOUND';
throw e;
}
return map[req];

}
webpackContext.id = '"./child Sync recursive ^\\.\\/.*\\.js$"';

webpackContext.keys = function webpackContextKeys() {
return Object.keys(map);
};
webpackContext.resolve = webpackContextResolve;
module.exports = webpackContext;
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
/* harmony import */var _lib_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib.js */"./lib.js");

function test() {
_lib_js__WEBPACK_IMPORTED_MODULE_0_.a;
a;
}
},
"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'a': function() { return a; }
});
const a = "";
__webpack_require__(/* ./child */"./child Sync recursive ^\\.\\/.*\\.js$")((`./child/${a}.js`).replace('./child/', './'));
},

},function(__webpack_require__) {
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,11 @@
--- expected
+++ actual
@@ -3,14 +3,66 @@
---
```js title=main.js
(self['webpackChunkwebpack'] = self['webpackChunkwebpack'] || []).push([["main"], {
+"./child/child/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'value': function() { return value; }
+});
+ const value = "dynamic";
+},
+"./child/index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'value': function() { return value; }
+});
+ const value = "dynamic";
+},
+"./child Sync recursive ^\\.\\/.*\\.js$": function (module, exports, __webpack_require__) {
+var map = {"./child/index.js": "./child/child/index.js","./index.js": "./child/index.js",};
+function webpackContext(req) {
+var id = webpackContextResolve(req);
+
+return __webpack_require__(id);
+
+}
+function webpackContextResolve(req) {
+
+ if(!__webpack_require__.o(map, req)) {
+ var e = new Error("Cannot find module '" + req + "'");
+ e.code = 'MODULE_NOT_FOUND';
+ throw e;
+ }
+ return map[req];
+
+}
+webpackContext.id = '"./child Sync recursive ^\\.\\/.*\\.js$"';
+
+ webpackContext.keys = function webpackContextKeys() {
+ return Object.keys(map);
+ };
+ webpackContext.resolve = webpackContextResolve;
+ module.exports = webpackContext;
+ },
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
@@ -8,7 +8,7 @@
__webpack_require__.r(__webpack_exports__);
+/* harmony import */var _lib_js__WEBPACK_IMPORTED_MODULE_0_ = __webpack_require__(/* ./lib.js */"./lib.js");

function test() {
- /* "./lib.js" unused */null;
+ _lib_js__WEBPACK_IMPORTED_MODULE_0_.a;
+ a;
IWANABETHATGUY marked this conversation as resolved.
Show resolved Hide resolved
}
},
+"./lib.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
+'use strict';
+__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'a': function() { return a; }
+});
+ const a = "";
+__webpack_require__(/* ./child */"./child Sync recursive ^\\.\\/.*\\.js$")((`./child/${a}.js`).replace('./child/', './'));
+},

},function(__webpack_require__) {
var __webpack_exec__ = function(moduleId) { return __webpack_require__(__webpack_require__.s = moduleId) }
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ source: crates/rspack_testing/src/run_fixture.rs
"./dead.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }
});
function __WEBPACK_DEFAULT_EXPORT__(){
return "dead";
}
Expand All @@ -25,7 +22,7 @@ function __WEBPACK_DEFAULT_EXPORT__(){
return "foo";
}
function foodead() {
return "foo" + (0, _dead__WEBPACK_IMPORTED_MODULE_0_["default"])();
return "foo" + dead();
}
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
--- expected
+++ actual
@@ -6,6 +6,9 @@
"./dead.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
'use strict';
__webpack_require__.r(__webpack_exports__);
+__webpack_require__.d(__webpack_exports__, {
+ 'default': function() { return __WEBPACK_DEFAULT_EXPORT__; }
+});
function __WEBPACK_DEFAULT_EXPORT__(){
return "dead";
}
@@ -22,7 +25,7 @@
@@ -22,7 +22,7 @@
return "foo";
}
function foodead() {
- return "foo" + /* "./dead" unused */null();
+ return "foo" + (0, _dead__WEBPACK_IMPORTED_MODULE_0_["default"])();
+ return "foo" + dead();
IWANABETHATGUY marked this conversation as resolved.
Show resolved Hide resolved
}
},
"./index.js": function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
Loading
Loading