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

$clinit_Boolean is not always optimized out when empty #10055

Open
niloc132 opened this issue Dec 11, 2024 · 0 comments
Open

$clinit_Boolean is not always optimized out when empty #10055

niloc132 opened this issue Dec 11, 2024 · 0 comments

Comments

@niloc132
Copy link
Member

GWT version: 2.12.1, latest
Browser (with version): any
Operating System: any


Description

While most empty clinits seem to be correctly optimized out, sometimes they unnecessarily remain in the compiled output.

As an example, if you build https://github.com/gwtproject/gwt-site-webapp/ but change turn draft mode off, $clinit_Object is correctly removed, but $clinit_Boolean is not, despite being empty:

function $clinit_Boolean(){
  $clinit_Boolean = emptyMethod;
}

A Java lambda of type elemental2.core.ReadonlyArray.FindPredicateFn

(el, index, parent) -> !"none".equals(((HTMLElement) el).style.display)

is translated as

function GWTProjectEntryPoint$lambda$9$Type(){
}

defineClass(81, $wnd.Function, {}, GWTProjectEntryPoint$lambda$9$Type);
_.onInvoke_2 = function onInvoke_5(arg0, arg1, arg2){
  return $clinit_GWTProjectEntryPoint() , $clinit_Boolean() , $equals('none', castToNative(arg0, $wnd.HTMLElement).style.display)?false:true;
}
;

which looks like boxing of boolean to Boolean via inlining Boolean.valueOf(boolean) gone a bit wrong:

public static Boolean valueOf(boolean b) {
return b ? $create(true) : $create(false);
}

  private boolean shouldEnhanceLink(Element link) {
    return
        // Enhance only local links
        isSameOriginRexp.test(link.getAttribute("href"))
        // Do not load links that are marked as full page reload
        && !Boolean.parseBoolean(link.getAttribute("data-full-load"));
  }

is inlined into two different places, bringing Boolean.parseBoolean with it:

function $lambda$16(this$static, evt_0){
  //...
  if ($test(isSameOriginRexp, target.getAttribute('href')) && ($clinit_Boolean() , !$equalsIgnoreCase('true', target.getAttribute('data-full-load'))) && $handleAsClick(castToNative(evt_0, $wnd.MouseEvent))) {
    //...
  }
}
function $lambda$19(el_0){
  //...
  if ($test(isSameOriginRexp, el_0.getAttribute('href')) && ($clinit_Boolean() , !$equalsIgnoreCase('true', el_0.getAttribute('data-full-load')))) {
    //...
  }
}

public static boolean parseBoolean(String s) {
return "true".equalsIgnoreCase(s);
}

Steps to reproduce

Check out gwt-site-webapp @ 27070768ae49c048535358a03c70a5b9d84ddf98

git clone [email protected]:gwtproject/gwt-site-webapp.git
cd gwt-site-webapp
git checkout 27070768ae49c048535358a03c70a5b9d84ddf98

Change draft compile to false

diff --git a/pom.xml b/pom.xml
index 747c5b2..f8fc02e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,7 @@
                     <compilerArgs>
                         <arg>-saveSource</arg>
                     </compilerArgs>
-                    <draftCompile>true</draftCompile>
+                    <draftCompile>false</draftCompile>
                     <style>PRETTY</style>
                     <failOnError>true</failOnError>
                     <launcherDir>${project.build.directory}/www</launcherDir>

Build the project, with mvn clean verify

Expected: If $clinit_Boolean is present, it is non-empty.
Actual: $clinit_Boolean is present, and only reassigns itself to emptyMethod

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant