Improve duplicate clinit removal - #10383
Draft
niloc132 wants to merge 14 commits into
Draft
Conversation
This reverts commit 47ca169.
Member
Author
|
Marked as draft for now, some additional tests are required, and some text blocks can be used in place of separate string vararg params. Showcase improves by about 0.1%, or about 300 bytes over 300-400kb permutations. |
niloc132
commented
Jul 22, 2026
| List<JsCatch> catches = x.getCatches(); | ||
| for (int i = 0; i < catches.size(); i++) { | ||
| JsCatch aCatch = catches.get(i); | ||
| JsCatch c = accept(aCatch); |
Member
Author
There was a problem hiding this comment.
this should almost certainly be a branch(), we can't guarantee a catch runs.
| public void test2() throws Exception { | ||
| // Don't coalesces cases 0 and 2 since 2 can be reached via fallthrough from 1 | ||
| String input = "function a(x){var y;switch(x){case 0:return 17;case 1:y=18;case 2:return 17;case 3:y=18;}return y}"; | ||
| String expected = "function a(x){var y;switch(x){case 0:return 17;case 1:y=18;case 2:return 17;case 3:y=18;}return y}\n"; |
Member
Author
There was a problem hiding this comment.
In this PR or another, these would all make good text blocks.
| * Several tests use an expression like "x + (clinit_A(), y) > 0" to avoid short-circuiting but | ||
| * still allow for side effects so the clinit won't be moved out before the for condition. | ||
| */ | ||
| public class JsDuplicateClinitRemoverTest extends OptimizerTestBase { |
Member
Author
There was a problem hiding this comment.
Possibly rename the DuplicateClinitRemover to have a Js prefix like this does? that seems to be the convention for other passes.
| "alert(cond1 && (clinit_A(), cond2));" | ||
| ) | ||
| .into(CLINIT_DECL, | ||
| "clinit_A();", |
Member
Author
There was a problem hiding this comment.
Text blocks all through here for sure.
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.
Explore comma expression contents when finding class initializers, and mark them as seen to avoid their inclusion later in method bodies. Also improved try block handling when there are no catches or finallys, and left notes for how this can be later improved when control flow is more structured (#10248, #10381)
Moved this pass into the main JS optimization loop - inlining methods tends to produce grouped clinits, and clinit removal can leave behind dead code that needs to be simplified away. In some cases, clinit removal make also make a method eligible for inlining.
This code previously had no tests, so added a test class, and improved the JS OptimizerTestBase to allow for minor changes (newlines, etc) between input and expected contents, as well as asserting for "no change" when appropriate. This more closely mirrors the Java version of this test base.
Also cleans up some "XO" references ("eXactly Once") in favor of "clinit" as referenced elsewhere.
Fixes #9731