feat(compiler): Implement constant folding for more binary expressions#29650
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There are already most arithmetic operators in constant propagation: `+`, `-`, `*`, `/`.
We could add more, namely: `|`, `&`, `^`, `<<`, `>>`, `>>>` and `%`:
Input:
```js
function f() {
return [
123.45 | 0,
123.45 & 0,
123.45 ^ 0,
123 << 0,
123 >> 0,
123 >>> 0,
123.45 | 1,
123.45 & 1,
123.45 ^ 1,
123 << 1,
123 >> 1,
123 >>> 1,
3 ** 2,
3 ** 2.5,
3.5 ** 2,
2 ** 3 ** 0.5,
4 % 2,
4 % 2.5,
4 % 3,
4.5 % 2,
];
}
```
Output:
```js
function f() {
return [
123, 0, 123, 123, 123, 123, 123, 1, 122, 246, 61, 61, 9,
15.588457268119896, 12.25, 3.3219970854839125, 0, 1.5, 1, 0.5,
];
}
```
Resolves facebook#29649
|
Comparing: 867edc6...5d54a9a Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: Expand to show
|
josephsavona
approved these changes
May 29, 2024
Member
|
Thanks again for contributing to the compiler! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
There are already most arithmetic operators in constant propagation:
+,-,*,/.We could add more, namely:
|,&,^,<<,>>,>>>and%:Input:
Output:
Resolves #29649
How did you test this change?
See tests.
Note:
This PR was done without waiting for approval in #29649, so feel free to just close it without any comment.