Removed the problem where literal initializers could trigger a clinit.  The correct (old) behavior is that literal initialzers do not trigger a clinit; instead they initialize during top-level execution.

Also, roll-back of Impl since the other change is not really needed.

Review by: knorton

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@2254 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
index 5a319f4..42c3c98 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JField.java
@@ -42,6 +42,13 @@
     return enclosingType;
   }
 
+  public JValueLiteral getLiteralInitializer() {
+    if (initializer instanceof JValueLiteral) {
+      return (JValueLiteral) initializer;
+    }
+    return null;
+  }
+
   public boolean isCompileTimeConstant() {
     return isCompileTimeConstant;
   }
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
index b6837c9..2d24c1f 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/DeadCodeElimination.java
@@ -257,7 +257,19 @@
 
     @Override
     public void endVisit(JDeclarationStatement x, Context ctx) {
-      lvalues.remove(x.getVariableRef());
+      JVariableRef variableRef = x.getVariableRef();
+      lvalues.remove(variableRef);
+
+      /*
+       * If the field (now) has a literal initializer, remove the unneeded
+       * declaration, which can remove the need for a clinit.
+       */
+      if (variableRef instanceof JFieldRef) {
+        JFieldRef fieldRef = (JFieldRef) variableRef;
+        if (fieldRef.getField().getLiteralInitializer() != null) {
+          removeMe(x, ctx);
+        }
+      }
     }
 
     /**
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
index 6e1215c..fe12346 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaAST.java
@@ -1362,11 +1362,15 @@
 
         if (initializer != null) {
           SourceInfo info = makeSourceInfo(declaration);
+          // JDeclarationStatement's ctor sets up the field's initializer.
           JStatement decl = new JDeclarationStatement(program, info,
               createVariableRef(info, field), initializer);
 
-          // will either be init or clinit
-          currentMethodBody.getStatements().add(decl);
+          // A field with a non-literal initializer needs a declaration.
+          if (field.getLiteralInitializer() == null) {
+            // will either be init or clinit
+            currentMethodBody.getStatements().add(decl);
+          }
         }
       } catch (Throwable e) {
         throw translateException(field, e);
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
index b11ff60..ab2c8eb 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/GenerateJavaScriptAST.java
@@ -565,7 +565,8 @@
       JsNameRef localRef = (JsNameRef) pop(); // localRef
 
       JVariable target = x.getVariableRef().getTarget();
-      if (target instanceof JField && target.getConstInitializer() != null) {
+      if (target instanceof JField
+          && ((JField) target).getLiteralInitializer() != null) {
         // Will initialize at top scope; no need to double-initialize.
         push(null);
         return;
@@ -598,9 +599,9 @@
     @Override
     public void endVisit(JField x, Context ctx) {
       // if we need an initial value, create an assignment
-      if (x.getConstInitializer() != null) {
+      if (x.getLiteralInitializer() != null) {
         // setup the constant value
-        accept(x.getConstInitializer());
+        accept(x.getLiteralInitializer());
       } else if (x == program.getIndexedField("Cast.typeIdArray")) {
         // magic: setup the type id table
         push(generateTypeTable());
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
index 92ec3a0..4d0c755 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/TypeTightener.java
@@ -217,9 +217,9 @@
 
     @Override
     public void endVisit(JField x, Context ctx) {
-      if (x.getConstInitializer() != null) {
+      if (x.getLiteralInitializer() != null) {
         // TODO: do I still need this?
-        addAssignment(x, x.getConstInitializer());
+        addAssignment(x, x.getLiteralInitializer());
       }
       currentMethod = null;
     }
diff --git a/user/src/com/google/gwt/core/client/Impl.java b/user/src/com/google/gwt/core/client/Impl.java
index aa8a0c0..8cb8903 100644
--- a/user/src/com/google/gwt/core/client/Impl.java
+++ b/user/src/com/google/gwt/core/client/Impl.java
@@ -17,7 +17,7 @@
 
 final class Impl {
 
-  private static int sNextHashId;
+  private static int sNextHashId = 0;
 
   protected static int getNextHashId() {
     return ++sNextHashId;