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
Tree shake parameter defaults #4498
Conversation
ae3658b
to
df42bb5
Compare
Thank you for your contribution! ❤️You can try out this pull request locally by installing Rollup via npm install rollup/rollup#tree-shake-parameter-defaults or load it into the REPL: |
4406233
to
115d3b2
Compare
* Use an inclusion parameter instead of separate methods to handle this * Make call argument inclusion path aware so that in the future, we can use this mechanism to determine possible values for parameters for deoptimization * Support parameter default treeshaking for functions, object and class methods, functions in array tuples and template tags * Use full CallExpression logic for TaggedTemplateExpression
115d3b2
to
f450178
Compare
f450178
to
1888f1e
Compare
Codecov Report
@@ Coverage Diff @@
## master #4498 +/- ##
==========================================
+ Coverage 98.74% 98.76% +0.01%
==========================================
Files 207 208 +1
Lines 7357 7433 +76
Branches 2084 2118 +34
==========================================
+ Hits 7265 7341 +76
- Misses 33 34 +1
+ Partials 59 58 -1
Continue to review full report at Codecov.
|
and improve coverage
This is ready for review now |
This reverts commit 4624917.
For anyone else following – this seems to be the issue behind the revert: #4505 |
There were actually two more issues. So far so I identified the causes but could not find time to fix stuff yet du to family things, so I reverted to get more time without people reporting the same issues again. |
There is a new attempt that does this more conservatively at #4510 |
* Recreate parameter tree-shaking but keep boolean return values * Properly include parameters when tree-shaking is disabled Also improve side effect detection for unused parameter defaults * Make null checks more compact * Include super class parameter defaults * Include return value parameter defaults * Limit feature to top-level functions * Remove path from deoptimization signature * Ensure class methods are deoptimized * Add comment * Class fields need Node 12 * Improve coverage * Improve coverage
To everyone following this, I decided to roll back the feature for good as it turned out to be far too brittle with far too much overhead for my liking at the moment, see #4520 |
* Recreate parameter tree-shaking but keep boolean return values * Properly include parameters when tree-shaking is disabled Also improve side effect detection for unused parameter defaults * Make null checks more compact * Include super class parameter defaults * Include return value parameter defaults * Limit feature to top-level functions * Remove path from deoptimization signature * Ensure class methods are deoptimized * Add comment * Class fields need Node 12 * Improve coverage * Improve coverage
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Resolves #4466
Description
This allows tree-shaking for unnecessary default parameters in functions. This includes arrow functions but does not include nested defaults in destructuring patterns REPL
While the feature may sound simple at first glance, it was actually quite complex. The main problem is that JavaScript does not make a difference between not passing a parameter to a function and passing the value
undefined
: In both cases, the default value will be used.Therefore, there are quite some subtleties involved which in the end I resolved by extending the mechanism I created for omitting unneeded parameters. This mechanism was removing arguments from function calls if the corresponding parameter was unused. Now, it will also see if parameter defaults need to be included. Care was taken to ensure no side effects are omitted REPL
It is very important to track the instance where we "lose track" of how a function is used, e.g. because it is exported, passed to an unknown function etc. In those cases, all necessary defaults are included REPL