Revision: 9682
Author: [email protected]
Date: Mon Feb  7 12:59:41 2011
Log: Make SOYC produce consistent output.

http://gwt-code-reviews.appspot.com/1338805/show

Review by: [email protected]
http://code.google.com/p/google-web-toolkit/source/detail?r=9682

Modified:
 /trunk/dev/core/src/com/google/gwt/core/ext/soyc/impl/SizeMapRecorder.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java
 /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java

=======================================
--- /trunk/dev/core/src/com/google/gwt/core/ext/soyc/impl/SizeMapRecorder.java Tue Jun 22 06:26:45 2010 +++ /trunk/dev/core/src/com/google/gwt/core/ext/soyc/impl/SizeMapRecorder.java Mon Feb 7 12:59:41 2011
@@ -29,8 +29,10 @@
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.util.Comparator;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.TreeMap;
 import java.util.zip.GZIPOutputStream;

 /**
@@ -38,6 +40,16 @@
  * then read to produce a Story of Your Compile.
  */
 public class SizeMapRecorder {
+
+  /**
+   * Sorts by JsName.getIdent().
+   */
+ private static final Comparator<JsName> JSNAME_SORT = new Comparator<JsName>() {
+    public int compare(JsName o1, JsName o2) {
+      return o1.getIdent().compareTo(o2.getIdent());
+    }
+  };
+
   /**
* A human-accessible type and description of a program reference. These are
    * produced by
@@ -72,7 +84,7 @@
     return toReturn;
   }

-  /**
+/**
    * Escapes '&', '<', '>', '"', and '\'' to their XML entity equivalents.
    */
   public static String escapeXml(String unescaped) {
@@ -81,7 +93,7 @@
     return builder.toString();
   }

-  /**
+/**
    * Escapes '&', '<', '>', '"', and optionally ''' to their XML entity
* equivalents. The portion of the input string between start (inclusive) and
    * end (exclusive) is scanned.  The output is appended to the given
@@ -95,7 +107,7 @@
    * @param builder a StringBuilder to be appended with the output.
    */
   public static void escapeXml(String code, int start, int end,
-    boolean quoteApostrophe, StringBuilder builder) {
+      boolean quoteApostrophe, StringBuilder builder) {
     // See http://www.w3.org/TR/2006/REC-xml11-20060816/#charsets.
     int lastIndex = 0;
     int len = end - start;
@@ -156,7 +168,7 @@
     }
     builder.append(c, lastIndex, len - lastIndex);
   }
-
+
   /**
    * @param logger a TreeLogger
    */
@@ -172,7 +184,9 @@
     for (int i = 0; i < sizeBreakdowns.length; i++) {
       writer.append("<sizemap fragment=\"" + i + "\" " + "size=\""
           + sizeBreakdowns[i].getSize() + "\">\n");
- for (Entry<JsName, Integer> sizeMapEntry : sizeBreakdowns[i].getSizeMap().entrySet()) { + Map<JsName, Integer> sizeMap = new TreeMap<JsName, Integer>(JSNAME_SORT);
+      sizeMap.putAll(sizeBreakdowns[i].getSizeMap());
+      for (Entry<JsName, Integer> sizeMapEntry : sizeMap.entrySet()) {
         JsName name = sizeMapEntry.getKey();
         int size = sizeMapEntry.getValue();
TypedProgramReference typedRef = typedProgramReference(name, jjsmap,
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Sat Jan 22 17:19:44 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/ast/JTypeOracle.java Mon Feb 7 12:59:41 2011
@@ -16,9 +16,11 @@
 package com.google.gwt.dev.jjs.ast;

 import com.google.gwt.dev.jjs.ast.js.JMultiExpression;
+import com.google.gwt.dev.jjs.impl.HasNameSort;
 import com.google.gwt.dev.util.collect.IdentityHashMap;
 import com.google.gwt.dev.util.collect.IdentityHashSet;
 import com.google.gwt.dev.util.collect.IdentitySets;
+import com.google.gwt.dev.util.collect.Lists;

 import java.io.Serializable;
 import java.util.ArrayList;
@@ -462,10 +464,11 @@
      * building the full maps.
      */
     JClassType jsoType = program.getJavaScriptObject();
-    Set<JClassType> jsoSubTypes = Collections.emptySet();
+    List<JClassType> jsoSubTypes = Lists.create();
     if (jsoType != null) {
       assert jsoType.getImplements().size() == 0;
-      jsoSubTypes = get(subClassMap, jsoType);
+      jsoSubTypes = new ArrayList<JClassType>(get(subClassMap, jsoType));
+      Collections.sort(jsoSubTypes, new HasNameSort());
       for (JClassType jsoSubType : jsoSubTypes) {
         for (JInterfaceType intf : jsoSubType.getImplements()) {
           jsoType.addImplements(intf);
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Wed Feb 2 13:13:58 2011 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/ControlFlowAnalyzer.java Mon Feb 7 12:59:41 2011
@@ -205,7 +205,9 @@
       rescue(type.getSuperClass(), true, isInstantiated);

       // Rescue my clinit (it won't ever be explicitly referenced)
-      rescue(type.getMethods().get(0));
+      if (type.hasClinit()) {
+        rescue(type.getMethods().get(0));
+      }

// JLS 12.4.1: don't rescue my super interfaces just because I'm rescued.
       // However, if I'm instantiated, let's mark them as instantiated.
@@ -273,7 +275,9 @@
       assert (isReferenced || isInstantiated);

       // Rescue my clinit (it won't ever be explicitly referenced
-      rescue(type.getMethods().get(0));
+      if (type.hasClinit()) {
+        rescue(type.getMethods().get(0));
+      }

// JLS 12.4.1: don't rescue my super interfaces just because I'm rescued.
       // However, if I'm instantiated, let's mark them as instantiated.
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Tue Oct 12 13:20:21 2010 +++ /trunk/dev/core/src/com/google/gwt/dev/jjs/impl/Pruner.java Mon Feb 7 12:59:41 2011
@@ -361,9 +361,12 @@
         JMethod method = type.getMethods().get(i);
         if (!methodIsReferenced(method)
             || pruneViaNoninstantiability(isInstantiated, method)) {
-          type.removeMethod(i);
-          madeChanges();
-          --i;
+          // Never prune clinit directly out of the class.
+          if (i > 0) {
+            type.removeMethod(i);
+            madeChanges();
+            --i;
+          }
         } else {
           accept(method);
         }

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to