Revision: 7880
Author: [email protected]
Date: Mon Apr 5 14:44:40 2010
Log: Rolling back r7776, because it can cause an InternalCompilerException
trying to replace a this expression with thisExp when thisExp is null.
The command is:
svn merge --ignore-ancestry -r 7776:7775
https://google-web-toolkit.googlecode.com/svn/trunk
http://code.google.com/p/google-web-toolkit/source/detail?r=7880
Modified:
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsHoister.java
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsInliner.java
=======================================
---
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsHoister.java
Tue Mar 23 14:56:21 2010
+++
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsHoister.java
Mon Apr 5 14:44:40 2010
@@ -221,9 +221,16 @@
stack.push(x);
}
+ /**
+ * A "this" reference can only effectively be hoisted if the call site
is
+ * qualified by a JsNameRef, so we'll ignore this for now.
+ */
@Override
public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
- stack.push(new JsThisRef(x.getSourceInfo()));
+ // Set a flag to indicate that we cannot continue, and push a null so
+ // we don't run out of elements on the stack.
+ successful = false;
+ stack.push(null);
}
public JsExpression getExpression() {
=======================================
---
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsInliner.java
Tue Mar 23 14:56:21 2010
+++
/branches/snapshot-2010.03.29-r7809/dev/core/src/com/google/gwt/dev/js/JsInliner.java
Mon Apr 5 14:44:40 2010
@@ -136,7 +136,7 @@
*/
affectedBySideEffects = true;
}
-
+
@Override
public void endVisit(JsObjectLiteral x, JsContext<JsExpression> ctx) {
affectedBySideEffects = true;
@@ -600,9 +600,6 @@
* invocations occur.
*/
private static class EvaluationOrderVisitor extends JsVisitor {
- public static final JsName THIS_NAME = (new JsScope("fake scope") {
- }).declareName("this");
-
private boolean maintainsOrder = true;
private final List<JsName> toEvaluate;
private final List<JsName> unevaluated;
@@ -676,19 +673,8 @@
@Override
public void endVisit(JsNameRef x, JsContext<JsExpression> ctx) {
- checkName(x.getName());
- }
-
- @Override
- public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
- checkName(THIS_NAME);
- }
-
- public boolean maintainsOrder() {
- return maintainsOrder && unevaluated.size() == 0;
- }
-
- private void checkName(JsName name) {
+ JsName name = x.getName();
+
if (!toEvaluate.contains(name)) {
return;
}
@@ -697,6 +683,10 @@
maintainsOrder = false;
}
}
+
+ public boolean maintainsOrder() {
+ return maintainsOrder && unevaluated.size() == 0;
+ }
/**
* Determine if an expression contains a reference to a strict
parameter.
@@ -923,7 +913,6 @@
}
inlining.push(invokedFunction);
- x = tryToUnravelExplicitCall(x);
JsExpression op = process(x, callerFunction, invokedFunction);
if (x != op) {
@@ -1041,7 +1030,6 @@
List<JsExpression> hoisted = new ArrayList<JsExpression>(
statements.size());
- JsExpression thisExpr = ((JsNameRef)
x.getQualifier()).getQualifier();
List<JsName> localVariableNames = new ArrayList<JsName>();
boolean sawReturnStatement = false;
@@ -1114,14 +1102,13 @@
}
// Confirm that the expression conforms to the desired heuristics
- if (!isInlinable(program, callerFunction, invokedFunction, thisExpr,
+ if (!isInlinable(program, callerFunction, invokedFunction,
x.getArguments(), op)) {
return x;
}
// Perform the name replacement
- NameRefReplacerVisitor v = new NameRefReplacerVisitor(thisExpr,
- x.getArguments(), invokedFunction.getParameters());
+ NameRefReplacerVisitor v = new NameRefReplacerVisitor(x,
invokedFunction);
for (ListIterator<JsName> nameIterator =
localVariableNames.listIterator(); nameIterator.hasNext();) {
JsName name = nameIterator.next();
@@ -1193,30 +1180,7 @@
@Override
public void endVisit(JsInvocation x, JsContext<JsExpression> ctx) {
- checkFunctionCall(x.getQualifier());
- }
-
- @Override
- public void endVisit(JsNew x, JsContext<JsExpression> ctx) {
- checkFunctionCall(x.getConstructorExpression());
- }
-
- public Integer invocationCount(JsFunction f) {
- return invocationCount.get(f);
- }
-
- /**
- * Like accept(), but remove counts for all invocations in expr.
- */
- public void removeCountsFor(JsExpression expr) {
- assert (!removingCounts);
- removingCounts = true;
- accept(expr);
- removingCounts = false;
- }
-
- private void checkFunctionCall(JsExpression qualifier) {
- JsFunction function = isFunction(qualifier);
+ JsFunction function = isFunction(x.getQualifier());
if (function != null) {
Integer count = invocationCount.get(function);
if (count == null) {
@@ -1232,6 +1196,20 @@
invocationCount.put(function, count);
}
}
+
+ public Integer invocationCount(JsFunction f) {
+ return invocationCount.get(f);
+ }
+
+ /**
+ * Like accept(), but remove counts for all invocations in expr.
+ */
+ public void removeCountsFor(JsExpression expr) {
+ assert (!removingCounts);
+ removingCounts = true;
+ accept(expr);
+ removingCounts = false;
+ }
}
/**
@@ -1250,13 +1228,15 @@
final Map<JsName, JsExpression> paramsToArgsMap = new
IdentityHashMap<JsName, JsExpression>();
/**
- * A replacement expression for this references.
+ * Constructor.
+ *
+ * @param invocation The call site
+ * @param function The function that encloses the inlined statement
*/
- private JsExpression thisExpr;
-
- public NameRefReplacerVisitor(JsExpression thisExpr,
- List<JsExpression> arguments, List<JsParameter> parameters) {
- this.thisExpr = thisExpr;
+ public NameRefReplacerVisitor(JsInvocation invocation, JsFunction
function) {
+ List<JsParameter> parameters = function.getParameters();
+ List<JsExpression> arguments = invocation.getArguments();
+
if (parameters.size() != arguments.size()) {
// This shouldn't happen if the cloned JsInvocation has been
properly
// configured
@@ -1289,12 +1269,6 @@
ctx.replaceMe(replacement);
}
}
-
- @Override
- public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
- assert thisExpr != null;
- ctx.replaceMe(thisExpr);
- }
/**
* Set a replacement JsName for all references to a JsName.
@@ -1779,13 +1753,6 @@
private static JsFunction isFunction(JsExpression e) {
if (e instanceof JsNameRef) {
JsNameRef ref = (JsNameRef) e;
-
- // Unravel foo.call(...).
- if (!ref.getName().isObfuscatable()
&& "call".equals(ref.getIdent())) {
- if (ref.getQualifier() instanceof JsNameRef) {
- ref = (JsNameRef) ref.getQualifier();
- }
- }
JsNode staticRef = ref.getName().getStaticRef();
if (staticRef instanceof JsFunction) {
@@ -1800,8 +1767,7 @@
* Determine if a statement can be inlined into a call site.
*/
private static boolean isInlinable(JsProgram program, JsFunction caller,
- JsFunction callee, JsExpression thisExpr, List<JsExpression>
arguments,
- JsNode<?> toInline) {
+ JsFunction callee, List<JsExpression> arguments, JsNode<?> toInline)
{
/*
* This will happen with varargs-style JavaScript functions that rely
on the
@@ -1843,31 +1809,19 @@
if (hasCommonIdents(arguments, toInline, parameterIdents)) {
return false;
}
-
- List<JsExpression> evalArgs;
- if (thisExpr == null) {
- evalArgs = arguments;
- } else {
- evalArgs = new ArrayList<JsExpression>(1 + arguments.size());
- evalArgs.add(thisExpr);
- evalArgs.addAll(arguments);
- }
/*
* Determine if the evaluation of the invocation's arguments may
create side
* effects. This will determine how aggressively the parameters may be
* reordered.
*/
- if (isVolatile(program, evalArgs, caller)) {
+ if (isVolatile(program, arguments, caller)) {
/*
* Determine the order in which the parameters must be evaluated.
This
* will vary between call sites, based on whether or not the
invocation's
* arguments can be repeated without ill effect.
*/
List<JsName> requiredOrder = new ArrayList<JsName>();
- if (thisExpr != null && isVolatile(program, thisExpr, callee)) {
- requiredOrder.add(EvaluationOrderVisitor.THIS_NAME);
- }
for (int i = 0; i < arguments.size(); i++) {
JsExpression e = arguments.get(i);
JsParameter p = callee.getParameters().get(i);
@@ -1933,34 +1887,6 @@
return hasSideEffects(list)
|| affectedBySideEffects(program, list, context);
}
-
- /**
- * Transforms any <code>foo.call(this)</code> into
<code>this.foo()</code> to
- * be compatible with our inlining algorithm.
- */
- private static JsInvocation tryToUnravelExplicitCall(JsInvocation x) {
- if (!(x.getQualifier() instanceof JsNameRef)) {
- return x;
- }
- JsNameRef ref = (JsNameRef) x.getQualifier();
- if (ref.getName().isObfuscatable() || !"call".equals(ref.getIdent())) {
- return x;
- }
- List<JsExpression> oldArgs = x.getArguments();
- if (oldArgs.size() < 1) {
- return x;
- }
-
- JsNameRef oldTarget = (JsNameRef) ref.getQualifier();
- JsNameRef newTarget = new JsNameRef(oldTarget.getSourceInfo(),
- oldTarget.getName());
- newTarget.setQualifier(oldArgs.get(0));
- JsInvocation newCall = new JsInvocation(x.getSourceInfo());
- newCall.setQualifier(newTarget);
- // Don't have to clone because the returned invocation is transient.
- newCall.getArguments().addAll(oldArgs.subList(1, oldArgs.size()));
- return newCall;
- }
/**
* Utility class.
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe, reply using "remove me" as the subject.