Skip to content

$clinit_Boolean is not always optimized out when empty #10055

@niloc132

Description

@niloc132

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions