Repository navigation
Find live toplevel bindings in Js_shake with a worklist #8773
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
Merged
+139
−46
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Generated by ReScript, PLEASE EDIT WITH CARE | ||
|
|
||
| import * as Mocha from "mocha"; | ||
| import * as Test_utils from "./test_utils.mjs"; | ||
|
|
||
| let counter = { | ||
| contents: 0 | ||
| }; | ||
|
|
||
| function chain0(x) { | ||
| return ((x * 3 | 0) + (x * x | 0) | 0) + 1 | 0; | ||
| } | ||
|
|
||
| function chain1(x) { | ||
| return ((chain0(x) * 3 | 0) + chain0(x + 1 | 0) | 0) - (x << 1) | 0; | ||
| } | ||
|
|
||
| function chain2(x) { | ||
| return ((chain1(x) * 3 | 0) + chain1(x + 1 | 0) | 0) - (x << 1) | 0; | ||
| } | ||
|
|
||
| function chainEnd(x) { | ||
| return chain2(x) + chain2(x + 1 | 0) | 0; | ||
| } | ||
|
|
||
| function effectHelper(x) { | ||
| return (((x * x | 0) * 7 | 0) + (x * 3 | 0) | 0) + 5 | 0; | ||
| } | ||
|
|
||
| function bump(x) { | ||
| counter.contents = counter.contents + effectHelper(x) | 0; | ||
| return counter.contents; | ||
| } | ||
|
|
||
| bump(1); | ||
|
|
||
| function statementHelper(x) { | ||
| return (((x * x | 0) * 5 | 0) + (x * 11 | 0) | 0) + 2 | 0; | ||
| } | ||
|
|
||
| counter.contents = counter.contents + statementHelper(2) | 0; | ||
|
|
||
| Mocha.describe("File \"shake_liveness_test.res\", line 36, characters 9-16", () => { | ||
| Mocha.test("kept bindings work", () => { | ||
| Test_utils.eq("File \"shake_liveness_test.res\", line 39, characters 7-14", counter.contents, 59); | ||
| Test_utils.eq("File \"shake_liveness_test.res\", line 40, characters 7-14", chainEnd(1), 338); | ||
| }); | ||
| }); | ||
|
|
||
| export { | ||
| counter, | ||
| chainEnd, | ||
| } | ||
| /* Not a pure module */ |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // Which toplevel bindings Js_shake keeps: exports, bindings with side effects, | ||
| // bindings used by statements with side effects, and transitively whatever | ||
| // they use. The generated JS shows that only the `dead*` bindings are removed. | ||
| open Mocha | ||
| open Test_utils | ||
|
|
||
| let counter = ref(0) | ||
|
|
||
| // A chain that runs backwards through the module: each binding is only needed | ||
| // because a later one uses it, and only the last one is exported. | ||
| %%private(let chain0 = (x: int) => x * 3 + x * x + 1) | ||
| %%private(let chain1 = (x: int) => chain0(x) * 3 + chain0(x + 1) - 2 * x) | ||
| %%private(let chain2 = (x: int) => chain1(x) * 3 + chain1(x + 1) - 2 * x) | ||
| let chainEnd = (x: int) => chain2(x) + chain2(x + 1) | ||
|
|
||
| // Unused, but its initializer has a side effect: it compiles to the statement | ||
| // `bump(1)`, which keeps `bump` and, through it, `effectHelper`. | ||
| %%private(let effectHelper = (x: int) => x * x * 7 + x * 3 + 5) | ||
| %%private( | ||
| let bump = (x: int) => { | ||
| counter := counter.contents + effectHelper(x) | ||
| counter.contents | ||
| } | ||
| ) | ||
| %%private(let effectful = bump(1)) | ||
|
|
||
| // Only used by a toplevel statement with a side effect. | ||
| %%private(let statementHelper = (x: int) => x * x * 5 + x * 11 + 2) | ||
| counter := counter.contents + statementHelper(2) | ||
|
|
||
| // Unused chain without side effects: removed. | ||
| %%private(let deadUsedByDead = (x: int) => x * x * 9 + x * 13 + 4) | ||
| %%private(let dead0 = (x: int) => deadUsedByDead(x) * 3 + deadUsedByDead(x + 1)) | ||
| %%private(let dead1 = (x: int) => dead0(x) * 3 + dead0(x + 1) - x) | ||
|
|
||
| describe(__LOC__, () => { | ||
| test("kept bindings work", () => { | ||
| // effectHelper(1) = 15, statementHelper(2) = 44 | ||
| eq(__LOC__, counter.contents, 59) | ||
| eq(__LOC__, chainEnd(1), 338) | ||
| }) | ||
| }) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.