diff --git a/src/com/google/javascript/jscomp/AbstractPeepholeOptimization.java b/src/com/google/javascript/jscomp/AbstractPeepholeOptimization.java index fe5f788f3a6..b20d1a42efc 100644 --- a/src/com/google/javascript/jscomp/AbstractPeepholeOptimization.java +++ b/src/com/google/javascript/jscomp/AbstractPeepholeOptimization.java @@ -29,7 +29,6 @@ */ abstract class AbstractPeepholeOptimization { - private NodeTraversal traversal; protected AbstractCompiler compiler; /** @@ -60,7 +59,7 @@ protected void report(DiagnosticType diagnostic, Node n) { * Subclasses must call these if they have changed the AST. */ protected void reportCodeChange() { - traversal.reportCodeChange(); + compiler.reportCodeChange(); } /** @@ -85,25 +84,11 @@ protected boolean isASTNormalized() { return compiler.getLifeCycleStage().isNormalized(); } - /** - * Informs the optimization that a traversal will begin. - */ - void beginTraversal(NodeTraversal traversal) { - this.traversal = traversal; - this.compiler = traversal.getCompiler(); + /** Informs the optimization that a traversal will begin. */ + void beginTraversal(AbstractCompiler compiler) { + this.compiler = compiler; } - /** - * Informs the optimization that a traversal has completed. - */ - void endTraversal() { - this.traversal = null; - this.compiler = null; - } - - // NodeUtil's mayEffectMutableState and mayHaveSideEffects need access to the - // compiler object, route them through here to give them access. - /** * @return Whether the node may create new mutable state, or change existing * state. diff --git a/src/com/google/javascript/jscomp/DefaultPassConfig.java b/src/com/google/javascript/jscomp/DefaultPassConfig.java index 0c8ffbc3aed..404ef165d52 100644 --- a/src/com/google/javascript/jscomp/DefaultPassConfig.java +++ b/src/com/google/javascript/jscomp/DefaultPassConfig.java @@ -1640,12 +1640,11 @@ protected FeatureSet featureSet() { private final PassFactory earlyPeepholeOptimizations = new PassFactory("earlyPeepholeOptimizations", true) { - @Override - protected CompilerPass create(AbstractCompiler compiler) { - return new PeepholeOptimizationsPass(compiler, - new PeepholeRemoveDeadCode()); - } - }; + @Override + protected CompilerPass create(AbstractCompiler compiler) { + return new PeepholeOptimizationsPass(compiler, getName(), new PeepholeRemoveDeadCode()); + } + }; private final PassFactory earlyInlineVariables = new PassFactory("earlyInlineVariables", true) { @@ -1669,54 +1668,59 @@ protected FeatureSet featureSet() { }; /** Various peephole optimizations. */ - private static CompilerPass createPeepholeOptimizationsPass(AbstractCompiler compiler) { + private static CompilerPass createPeepholeOptimizationsPass( + AbstractCompiler compiler, String passName) { final boolean late = false; final boolean useTypesForOptimization = compiler.getOptions().useTypesForLocalOptimization; - return new PeepholeOptimizationsPass(compiler, - new MinimizeExitPoints(compiler), - new PeepholeMinimizeConditions(late, useTypesForOptimization), - new PeepholeSubstituteAlternateSyntax(late), - new PeepholeReplaceKnownMethods(late, useTypesForOptimization), - new PeepholeRemoveDeadCode(), - new PeepholeFoldConstants(late, useTypesForOptimization), - new PeepholeCollectPropertyAssignments()); + return new PeepholeOptimizationsPass( + compiler, + passName, + new MinimizeExitPoints(compiler), + new PeepholeMinimizeConditions(late, useTypesForOptimization), + new PeepholeSubstituteAlternateSyntax(late), + new PeepholeReplaceKnownMethods(late, useTypesForOptimization), + new PeepholeRemoveDeadCode(), + new PeepholeFoldConstants(late, useTypesForOptimization), + new PeepholeCollectPropertyAssignments()); } /** Various peephole optimizations. */ private final PassFactory peepholeOptimizations = new PassFactory(Compiler.PEEPHOLE_PASS_NAME, false /* oneTimePass */) { - @Override - protected CompilerPass create(AbstractCompiler compiler) { - return createPeepholeOptimizationsPass(compiler); - } - }; + @Override + protected CompilerPass create(AbstractCompiler compiler) { + return createPeepholeOptimizationsPass(compiler, getName()); + } + }; /** Various peephole optimizations. */ private final PassFactory peepholeOptimizationsOnce = new PassFactory(Compiler.PEEPHOLE_PASS_NAME, true /* oneTimePass */) { - @Override - protected CompilerPass create(AbstractCompiler compiler) { - return createPeepholeOptimizationsPass(compiler); - } - }; + @Override + protected CompilerPass create(AbstractCompiler compiler) { + return createPeepholeOptimizationsPass(compiler, getName()); + } + }; /** Same as peepholeOptimizations but aggressively merges code together */ private final PassFactory latePeepholeOptimizations = new PassFactory("latePeepholeOptimizations", true) { - @Override - protected CompilerPass create(AbstractCompiler compiler) { - final boolean late = true; - final boolean useTypesForOptimization = options.useTypesForLocalOptimization; - return new PeepholeOptimizationsPass(compiler, - new StatementFusion(options.aggressiveFusion), - new PeepholeRemoveDeadCode(), - new PeepholeMinimizeConditions(late, useTypesForOptimization), - new PeepholeSubstituteAlternateSyntax(late), - new PeepholeReplaceKnownMethods(late, useTypesForOptimization), - new PeepholeFoldConstants(late, useTypesForOptimization), - new ReorderConstantExpression()); - } - }; + @Override + protected CompilerPass create(AbstractCompiler compiler) { + final boolean late = true; + final boolean useTypesForOptimization = options.useTypesForLocalOptimization; + return new PeepholeOptimizationsPass( + compiler, + getName(), + new StatementFusion(options.aggressiveFusion), + new PeepholeRemoveDeadCode(), + new PeepholeMinimizeConditions(late, useTypesForOptimization), + new PeepholeSubstituteAlternateSyntax(late), + new PeepholeReplaceKnownMethods(late, useTypesForOptimization), + new PeepholeFoldConstants(late, useTypesForOptimization), + new ReorderConstantExpression()); + } + }; /** Checks that all variables are defined. */ private final HotSwapPassFactory checkVars = @@ -2689,17 +2693,14 @@ protected CompilerPass create(AbstractCompiler compiler) { } }; - /** - * Some simple, local collapses (e.g., {@code var x; var y;} becomes - * {@code var x,y;}. - */ - private final PassFactory exploitAssign = new PassFactory("exploitAssign", true) { - @Override - protected CompilerPass create(AbstractCompiler compiler) { - return new PeepholeOptimizationsPass(compiler, - new ExploitAssigns()); - } - }; + /** Some simple, local collapses (e.g., {@code var x; var y;} becomes {@code var x,y;}. */ + private final PassFactory exploitAssign = + new PassFactory("exploitAssign", true) { + @Override + protected CompilerPass create(AbstractCompiler compiler) { + return new PeepholeOptimizationsPass(compiler, getName(), new ExploitAssigns()); + } + }; /** * Some simple, local collapses (e.g., {@code var x; var y;} becomes diff --git a/src/com/google/javascript/jscomp/MinimizeExitPoints.java b/src/com/google/javascript/jscomp/MinimizeExitPoints.java index 1d362afb885..f2f933fc779 100644 --- a/src/com/google/javascript/jscomp/MinimizeExitPoints.java +++ b/src/com/google/javascript/jscomp/MinimizeExitPoints.java @@ -40,7 +40,7 @@ class MinimizeExitPoints extends AbstractPeepholeOptimization { @VisibleForTesting final CompilerPass asCompilerPass() { - return new PeepholeOptimizationsPass(compiler, this); + return new PeepholeOptimizationsPass(compiler, this.getClass().getSimpleName(), this); } @Override diff --git a/src/com/google/javascript/jscomp/PeepholeOptimizationsPass.java b/src/com/google/javascript/jscomp/PeepholeOptimizationsPass.java index 453f5f856ca..90f5c6e8ff0 100644 --- a/src/com/google/javascript/jscomp/PeepholeOptimizationsPass.java +++ b/src/com/google/javascript/jscomp/PeepholeOptimizationsPass.java @@ -16,9 +16,10 @@ package com.google.javascript.jscomp; -import com.google.javascript.jscomp.NodeTraversal.AbstractShallowCallback; -import com.google.javascript.jscomp.NodeTraversal.FunctionCallback; +import com.google.common.annotations.VisibleForTesting; +import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback; import com.google.javascript.rhino.Node; +import java.util.List; /** * A compiler pass to run various peephole optimizations (e.g. constant folding, @@ -27,93 +28,61 @@ * @author dcc@google.com (Devin Coughlin) */ class PeepholeOptimizationsPass implements CompilerPass { - private AbstractCompiler compiler; - // Use an array here for faster iteration compared to ImmutableSet + private final AbstractCompiler compiler; + private final String passName; private final AbstractPeepholeOptimization[] peepholeOptimizations; - private boolean retraverseOnChange; - private RecentChange handler; - private FunctionCallback fnCallback; - private PeepCallback peepCallback; - private NodeTraversal traversal; - /** - * Creates a peephole optimization pass that runs the given - * optimizations. - */ - PeepholeOptimizationsPass(AbstractCompiler compiler, - AbstractPeepholeOptimization... optimizations) { + /** Creates a peephole optimization pass that runs the given optimizations. */ + PeepholeOptimizationsPass( + AbstractCompiler compiler, String passName, AbstractPeepholeOptimization... optimizations) { this.compiler = compiler; + this.passName = passName; this.peepholeOptimizations = optimizations; this.retraverseOnChange = true; - this.handler = new RecentChange(); - this.peepCallback = new PeepCallback(); - this.traversal = new NodeTraversal( - compiler, peepCallback, new Es6SyntacticScopeCreator(compiler)); - this.fnCallback = new ChangedFunctionCallback(); } + @VisibleForTesting void setRetraverseOnChange(boolean retraverse) { this.retraverseOnChange = retraverse; } @Override public void process(Node externs, Node root) { - compiler.addChangeHandler(handler); - beginTraversal(traversal); - NodeTraversal.traverseChangedFunctions(compiler, fnCallback); - endTraversal(); - compiler.removeChangeHandler(handler); - } + beginTraversal(); - private class ChangedFunctionCallback implements FunctionCallback { - @Override - public void enterFunction(AbstractCompiler compiler, Node root) { - if (root.isFunction()) { - root = root.getLastChild(); + // Repeat to an internal fixed point. + for (List changedScopeNodes = compiler.getChangedScopeNodesForPass(passName); + changedScopeNodes == null || !changedScopeNodes.isEmpty(); + changedScopeNodes = compiler.getChangedScopeNodesForPass(passName)) { + NodeTraversal.traverseEs6ScopeRoots( + compiler, root, changedScopeNodes, new PeepCallback(), false); + + // Cancel the fixed point if requested. + if (!retraverseOnChange) { + break; } - do { - handler.reset(); - traversal.traverse(root); - } while (retraverseOnChange && handler.hasCodeChanged()); } } - private class PeepCallback extends AbstractShallowCallback { + private class PeepCallback extends AbstractPostOrderCallback { @Override public void visit(NodeTraversal t, Node n, Node parent) { - Node currentNode = n, newNode; - boolean codeChanged = false; - do { - codeChanged = false; - for (AbstractPeepholeOptimization optim : peepholeOptimizations) { - newNode = optim.optimizeSubtree(currentNode); - if (newNode != currentNode) { - codeChanged = true; - currentNode = newNode; - } - if (currentNode == null) { - return; - } + Node currentNode = n; + for (AbstractPeepholeOptimization optim : peepholeOptimizations) { + currentNode = optim.optimizeSubtree(currentNode); + if (currentNode == null) { + return; } - } while(codeChanged); - } - } - - /** - * Make sure that all the optimizations have the current traversal so they - * can report errors. - */ - private void beginTraversal(NodeTraversal traversal) { - for (AbstractPeepholeOptimization optimization : peepholeOptimizations) { - optimization.beginTraversal(traversal); + } } } - private void endTraversal() { + /** Make sure that all the optimizations have the current compiler so they can report errors. */ + private void beginTraversal() { for (AbstractPeepholeOptimization optimization : peepholeOptimizations) { - optimization.endTraversal(); + optimization.beginTraversal(compiler); } } } diff --git a/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java b/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java index fcdaf98c9a3..d5358a04c68 100644 --- a/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java +++ b/src/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntax.java @@ -95,6 +95,7 @@ public Node optimizeSubtree(Node node) { return tryReduceReturn(node); case COMMA: + // TODO(b/63630312): should flatten an entire comma expression in a single pass. return trySplitComma(node); case NAME: @@ -313,8 +314,8 @@ private Node trySplitComma(Node n) { Node newStatement = IR.exprResult(right); newStatement.useSourceInfoIfMissingFrom(n); - //This modifies outside the subtree, which is not - //desirable in a peephole optimization. + // This modifies outside the subtree, which is not + // desirable in a peephole optimization. parent.getParent().addChildAfter(newStatement, parent); reportCodeChange(); return left; diff --git a/test/com/google/javascript/jscomp/CreateSyntheticBlocksTest.java b/test/com/google/javascript/jscomp/CreateSyntheticBlocksTest.java index 31f18e87bb5..901bde1da5c 100644 --- a/test/com/google/javascript/jscomp/CreateSyntheticBlocksTest.java +++ b/test/com/google/javascript/jscomp/CreateSyntheticBlocksTest.java @@ -41,13 +41,14 @@ protected CompilerPass getProcessor(final Compiler compiler) { return new CompilerPass() { @Override public void process(Node externs, Node js) { - new CreateSyntheticBlocks(compiler, START_MARKER, END_MARKER).process( - externs, js); + new CreateSyntheticBlocks(compiler, START_MARKER, END_MARKER).process(externs, js); new MinimizeExitPoints(compiler).asCompilerPass().process(externs, js); - new PeepholeOptimizationsPass(compiler, - new PeepholeRemoveDeadCode(), - new PeepholeMinimizeConditions(true /* late */, false /* useTypes */), - new PeepholeFoldConstants(true, false)) + new PeepholeOptimizationsPass( + compiler, + getName(), + new PeepholeRemoveDeadCode(), + new PeepholeMinimizeConditions(true /* late */, false /* useTypes */), + new PeepholeFoldConstants(true, false)) .process(externs, js); new MinimizeExitPoints(compiler).asCompilerPass().process(externs, js); new Denormalize(compiler).process(externs, js); diff --git a/test/com/google/javascript/jscomp/ExploitAssignsTest.java b/test/com/google/javascript/jscomp/ExploitAssignsTest.java index 85a5a6f41a2..60948bdbeed 100644 --- a/test/com/google/javascript/jscomp/ExploitAssignsTest.java +++ b/test/com/google/javascript/jscomp/ExploitAssignsTest.java @@ -184,6 +184,6 @@ public void testIssue1017() { @Override protected CompilerPass getProcessor(Compiler compiler) { - return new PeepholeOptimizationsPass(compiler,new ExploitAssigns()); + return new PeepholeOptimizationsPass(compiler, getName(), new ExploitAssigns()); } } diff --git a/test/com/google/javascript/jscomp/MultiPassTest.java b/test/com/google/javascript/jscomp/MultiPassTest.java index 23615794968..86ec3aaf531 100644 --- a/test/com/google/javascript/jscomp/MultiPassTest.java +++ b/test/com/google/javascript/jscomp/MultiPassTest.java @@ -359,7 +359,9 @@ private void addPeephole() { @Override protected CompilerPass create(AbstractCompiler compiler) { final boolean late = false; - return new PeepholeOptimizationsPass(compiler, + return new PeepholeOptimizationsPass( + compiler, + getName(), new PeepholeMinimizeConditions(late, false /* useTypes */), new PeepholeSubstituteAlternateSyntax(late), new PeepholeReplaceKnownMethods(late, false), diff --git a/test/com/google/javascript/jscomp/PeepholeCollectPropertyAssignmentsTest.java b/test/com/google/javascript/jscomp/PeepholeCollectPropertyAssignmentsTest.java index cc9b8ff28b6..01a29a632a0 100644 --- a/test/com/google/javascript/jscomp/PeepholeCollectPropertyAssignmentsTest.java +++ b/test/com/google/javascript/jscomp/PeepholeCollectPropertyAssignmentsTest.java @@ -21,7 +21,7 @@ public final class PeepholeCollectPropertyAssignmentsTest extends CompilerTestCa @Override protected CompilerPass getProcessor(final Compiler compiler) { return new PeepholeOptimizationsPass( - compiler, new PeepholeCollectPropertyAssignments()); + compiler, getName(), new PeepholeCollectPropertyAssignments()); } public void test36122565a() { diff --git a/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java b/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java index 4020968b1df..7ef9d58a6c5 100644 --- a/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java +++ b/test/com/google/javascript/jscomp/PeepholeFoldConstantsTest.java @@ -39,26 +39,29 @@ public PeepholeFoldConstantsTest() { private boolean late; private boolean useTypes = true; + private int numRepetitions; @Override protected void setUp() throws Exception { super.setUp(); late = false; useTypes = true; - this.mode = TypeInferenceMode.NEITHER; + // Reduce this to 1 if we get better expression evaluators. + numRepetitions = 2; + mode = TypeInferenceMode.NEITHER; } @Override protected CompilerPass getProcessor(final Compiler compiler) { CompilerPass peepholePass = - new PeepholeOptimizationsPass(compiler, new PeepholeFoldConstants(late, useTypes)); + new PeepholeOptimizationsPass( + compiler, getName(), new PeepholeFoldConstants(late, useTypes)); return peepholePass; } @Override protected int getNumRepetitions() { - // Reduce this to 1 if we get better expression evaluators. - return 2; + return numRepetitions; } @Override @@ -453,6 +456,10 @@ public void testObjectComparison1() { } public void testUnaryOps() { + // Running on just changed code results in an exception on only the first invocation. Don't + // repeat because it confuses the exception verification. + numRepetitions = 1; + // These cases are handled by PeepholeRemoveDeadCode. foldSame("!foo()"); foldSame("~foo()"); @@ -671,6 +678,10 @@ public void testFoldBitwiseOpStringCompare() { } public void testFoldBitShifts() { + // Running on just changed code results in an exception on only the first invocation. Don't + // repeat because it confuses the exception verification. + numRepetitions = 1; + fold("x = 1 << 0", "x = 1"); fold("x = -1 << 0", "x = -1"); fold("x = 1 << 1", "x = 2"); @@ -940,6 +951,10 @@ public void testFoldComparison4() { } public void testFoldGetElem1() { + // Running on just changed code results in an exception on only the first invocation. Don't + // repeat because it confuses the exception verification. + numRepetitions = 1; + fold("x = [,10][0]", "x = void 0"); fold("x = [10, 20][0]", "x = 10"); fold("x = [10, 20][1]", "x = 20"); @@ -958,6 +973,10 @@ public void testFoldGetElem1() { } public void testFoldGetElem2() { + // Running on just changed code results in an exception on only the first invocation. Don't + // repeat because it confuses the exception verification. + numRepetitions = 1; + fold("x = 'string'[5]", "x = 'g'"); fold("x = 'string'[0]", "x = 's'"); fold("x = 's'[0]", "x = 's'"); diff --git a/test/com/google/javascript/jscomp/PeepholeIntegrationTest.java b/test/com/google/javascript/jscomp/PeepholeIntegrationTest.java index 625471e1dd7..d849c7d3324 100644 --- a/test/com/google/javascript/jscomp/PeepholeIntegrationTest.java +++ b/test/com/google/javascript/jscomp/PeepholeIntegrationTest.java @@ -34,12 +34,13 @@ protected void setUp() throws Exception { @Override protected CompilerPass getProcessor(final Compiler compiler) { PeepholeOptimizationsPass peepholePass = - new PeepholeOptimizationsPass(compiler, - new PeepholeMinimizeConditions(late, false /* useTypes */), - new PeepholeSubstituteAlternateSyntax(late), - new PeepholeRemoveDeadCode(), - new PeepholeFoldConstants(late, false) - ); + new PeepholeOptimizationsPass( + compiler, + getName(), + new PeepholeMinimizeConditions(late, false /* useTypes */), + new PeepholeSubstituteAlternateSyntax(late), + new PeepholeRemoveDeadCode(), + new PeepholeFoldConstants(late, false)); return peepholePass; } diff --git a/test/com/google/javascript/jscomp/PeepholeMinimizeConditionsTest.java b/test/com/google/javascript/jscomp/PeepholeMinimizeConditionsTest.java index 3e20821f4b6..d727feb0270 100644 --- a/test/com/google/javascript/jscomp/PeepholeMinimizeConditionsTest.java +++ b/test/com/google/javascript/jscomp/PeepholeMinimizeConditionsTest.java @@ -42,8 +42,9 @@ protected void setUp() throws Exception { @Override protected CompilerPass getProcessor(final Compiler compiler) { - PeepholeOptimizationsPass peepholePass = new PeepholeOptimizationsPass( - compiler, new PeepholeMinimizeConditions(late, useTypes)); + PeepholeOptimizationsPass peepholePass = + new PeepholeOptimizationsPass( + compiler, getName(), new PeepholeMinimizeConditions(late, useTypes)); peepholePass.setRetraverseOnChange(false); return peepholePass; } @@ -380,8 +381,9 @@ public void testMinimizeComma() { public void testMinimizeExprResult() { fold("!x||!y", "x&&y"); - fold("if(!(x&&!y)) foo()", "x&&!y||!foo()"); - fold("if(!x||y) foo()", "x&&!y||!foo()"); + fold("if(!(x&&!y)) foo()", "(!x||y)&&foo()"); + fold("if(!x||y) foo()", "(!x||y)&&foo()"); + fold("(!x||y)&&foo()", "x&&!y||!foo()"); } public void testMinimizeDemorgan21() { diff --git a/test/com/google/javascript/jscomp/PeepholeOptimizationsPassTest.java b/test/com/google/javascript/jscomp/PeepholeOptimizationsPassTest.java index a09dee42960..d320d8b1c17 100644 --- a/test/com/google/javascript/jscomp/PeepholeOptimizationsPassTest.java +++ b/test/com/google/javascript/jscomp/PeepholeOptimizationsPassTest.java @@ -37,7 +37,7 @@ public final class PeepholeOptimizationsPassTest extends CompilerTestCase { @Override protected CompilerPass getProcessor(final Compiler compiler) { return new PeepholeOptimizationsPass( - compiler, currentPeepholePasses.toArray(new AbstractPeepholeOptimization[0])); + compiler, getName(), currentPeepholePasses.toArray(new AbstractPeepholeOptimization[0])); } @Override diff --git a/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java b/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java index 4f2d30acd2f..45380393cfb 100644 --- a/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java +++ b/test/com/google/javascript/jscomp/PeepholeRemoveDeadCodeTest.java @@ -40,14 +40,11 @@ protected CompilerPass getProcessor(final Compiler compiler) { return new CompilerPass() { @Override public void process(Node externs, Node root) { - DefinitionUseSiteFinder definitionFinder = - new DefinitionUseSiteFinder(compiler); + DefinitionUseSiteFinder definitionFinder = new DefinitionUseSiteFinder(compiler); definitionFinder.process(externs, root); - new PureFunctionIdentifier(compiler, definitionFinder) - .process(externs, root); + new PureFunctionIdentifier(compiler, definitionFinder).process(externs, root); PeepholeOptimizationsPass peepholePass = - new PeepholeOptimizationsPass( - compiler, new PeepholeRemoveDeadCode()); + new PeepholeOptimizationsPass(compiler, getName(), new PeepholeRemoveDeadCode()); peepholePass.process(externs, root); } }; diff --git a/test/com/google/javascript/jscomp/PeepholeReplaceKnownMethodsTest.java b/test/com/google/javascript/jscomp/PeepholeReplaceKnownMethodsTest.java index 9fe7609a115..b793c7c3f1c 100644 --- a/test/com/google/javascript/jscomp/PeepholeReplaceKnownMethodsTest.java +++ b/test/com/google/javascript/jscomp/PeepholeReplaceKnownMethodsTest.java @@ -49,7 +49,8 @@ protected void setUp() throws Exception { @Override protected CompilerPass getProcessor(final Compiler compiler) { - return new PeepholeOptimizationsPass(compiler, new PeepholeReplaceKnownMethods(late, useTypes)); + return new PeepholeOptimizationsPass( + compiler, getName(), new PeepholeReplaceKnownMethods(late, useTypes)); } public void testStringIndexOf() { diff --git a/test/com/google/javascript/jscomp/PeepholeSimplifyRegExpTest.java b/test/com/google/javascript/jscomp/PeepholeSimplifyRegExpTest.java index 4bb452ee0a3..d1e5f7bb579 100644 --- a/test/com/google/javascript/jscomp/PeepholeSimplifyRegExpTest.java +++ b/test/com/google/javascript/jscomp/PeepholeSimplifyRegExpTest.java @@ -317,8 +317,8 @@ public final void testMalformedRegularExpressions() { @Override protected CompilerPass getProcessor(Compiler compiler) { - final CompilerPass simplifier = new PeepholeOptimizationsPass( - compiler, new PeepholeSimplifyRegExp()); + final CompilerPass simplifier = + new PeepholeOptimizationsPass(compiler, getName(), new PeepholeSimplifyRegExp()); final CompilerPass checker = new CheckRegExp(compiler); return new CompilerPass() { diff --git a/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java b/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java index b8a781e9718..664a50c01df 100644 --- a/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java +++ b/test/com/google/javascript/jscomp/PeepholeSubstituteAlternateSyntaxTest.java @@ -52,8 +52,9 @@ protected void setUp() throws Exception { @Override protected CompilerPass getProcessor(final Compiler compiler) { - PeepholeOptimizationsPass peepholePass = new PeepholeOptimizationsPass( - compiler, new PeepholeSubstituteAlternateSyntax(late)); + PeepholeOptimizationsPass peepholePass = + new PeepholeOptimizationsPass( + compiler, getName(), new PeepholeSubstituteAlternateSyntax(late)); peepholePass.setRetraverseOnChange(retraverseOnChange); return peepholePass; } @@ -357,7 +358,7 @@ public void testSplitCommaExpressions() { fold("(x=2), foo()", "x=2; foo()"); fold("foo(), boo();", "foo(); boo()"); - fold("(a(), b()), (c(), d());", "a(); b(); (c(), d());"); + fold("(a(), b()), (c(), d());", "a(), b(); c(), d()"); fold("a(); b(); (c(), d());", "a(); b(); c(); d();"); fold("foo(), true", "foo();true"); foldSame("foo();true"); @@ -381,7 +382,7 @@ public void testComma2() { public void testComma3() { late = false; - test("1, a(), b()", "1; a(); b()"); + test("1, a(), b()", "1, a(); b()"); late = true; foldSame("1, a(), b()"); } @@ -395,7 +396,7 @@ public void testComma4() { public void testComma5() { late = false; - test("a(), b(), 1", "a();b();1"); + test("a(), b(), 1", "a(), b(); 1"); late = true; foldSame("a(), b(), 1"); } diff --git a/test/com/google/javascript/jscomp/ReorderConstantExpressionTest.java b/test/com/google/javascript/jscomp/ReorderConstantExpressionTest.java index 5ed4a385deb..4742284f241 100644 --- a/test/com/google/javascript/jscomp/ReorderConstantExpressionTest.java +++ b/test/com/google/javascript/jscomp/ReorderConstantExpressionTest.java @@ -24,8 +24,7 @@ public final class ReorderConstantExpressionTest extends CompilerTestCase { @Override protected CompilerPass getProcessor(final Compiler compiler) { - return new PeepholeOptimizationsPass(compiler, - new ReorderConstantExpression()); + return new PeepholeOptimizationsPass(compiler, getName(), new ReorderConstantExpression()); } @Override diff --git a/test/com/google/javascript/jscomp/StatementFusionTest.java b/test/com/google/javascript/jscomp/StatementFusionTest.java index b585c6ca462..deceea87abe 100644 --- a/test/com/google/javascript/jscomp/StatementFusionTest.java +++ b/test/com/google/javascript/jscomp/StatementFusionTest.java @@ -34,8 +34,7 @@ protected void setUp() throws Exception { @Override protected CompilerPass getProcessor(final Compiler compiler) { PeepholeOptimizationsPass peepholePass = - new PeepholeOptimizationsPass( - compiler, new StatementFusion(favorsCommas)); + new PeepholeOptimizationsPass(compiler, getName(), new StatementFusion(favorsCommas)); return peepholePass; }