Skip to content

Commit

Permalink
Rename RemoveUnusedVars to RemoveUnusedCode
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178251024
  • Loading branch information
brad4d authored and blickly committed Dec 7, 2017
1 parent c14fe3f commit 39f80ea
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
18 changes: 9 additions & 9 deletions src/com/google/javascript/jscomp/DefaultPassConfig.java
Expand Up @@ -815,7 +815,7 @@ protected List<PassFactory> getOptimizations() {
// After inlining some of the variable uses, some variables are unused. // After inlining some of the variable uses, some variables are unused.
// Re-run remove unused vars to clean it up. // Re-run remove unused vars to clean it up.
if (options.removeUnusedVars || options.removeUnusedLocalVars) { if (options.removeUnusedVars || options.removeUnusedLocalVars) {
passes.add(lastRemoveUnusedVars()); passes.add(getRemoveUnusedCodeOnce());
} }
} }


Expand Down Expand Up @@ -1002,7 +1002,7 @@ private List<PassFactory> getMainOptimizationLoop() {
} }


if (options.removeUnusedVars || options.removeUnusedLocalVars) { if (options.removeUnusedVars || options.removeUnusedLocalVars) {
passes.add(getRemoveUnusedVars()); passes.add(getRemoveUnusedCode());
} }


if (options.j2clPassMode.shouldAddJ2clPasses()) { if (options.j2clPassMode.shouldAddJ2clPasses()) {
Expand Down Expand Up @@ -2496,7 +2496,7 @@ protected CompilerPass create(AbstractCompiler compiler) {


/** /**
* Optimizes unused function arguments, unused return values, and inlines constant parameters. * Optimizes unused function arguments, unused return values, and inlines constant parameters.
* Also runs RemoveUnusedVars. * Also runs RemoveUnusedCode.
*/ */
private final PassFactory optimizeCalls = private final PassFactory optimizeCalls =
new PassFactory(PassNames.OPTIMIZE_CALLS, false) { new PassFactory(PassNames.OPTIMIZE_CALLS, false) {
Expand Down Expand Up @@ -2775,23 +2775,23 @@ protected CompilerPass create(AbstractCompiler compiler) {
} }
}; };


private PassFactory getRemoveUnusedVars() { private PassFactory getRemoveUnusedCode() {
return getRemoveUnusedVars(false /* isOneTimePass */); return getRemoveUnusedCode(false /* isOneTimePass */);
} }


private PassFactory lastRemoveUnusedVars() { private PassFactory getRemoveUnusedCodeOnce() {
return getRemoveUnusedVars(true /* isOneTimePass */); return getRemoveUnusedCode(true /* isOneTimePass */);
} }


private PassFactory getRemoveUnusedVars(boolean isOneTimePass) { private PassFactory getRemoveUnusedCode(boolean isOneTimePass) {
/** Removes variables that are never used. */ /** Removes variables that are never used. */
return new PassFactory(PassNames.REMOVE_UNUSED_VARS, isOneTimePass) { return new PassFactory(PassNames.REMOVE_UNUSED_VARS, isOneTimePass) {
@Override @Override
protected CompilerPass create(AbstractCompiler compiler) { protected CompilerPass create(AbstractCompiler compiler) {
boolean removeOnlyLocals = options.removeUnusedLocalVars && !options.removeUnusedVars; boolean removeOnlyLocals = options.removeUnusedLocalVars && !options.removeUnusedVars;
boolean preserveAnonymousFunctionNames = boolean preserveAnonymousFunctionNames =
options.anonymousFunctionNaming != AnonymousFunctionNamingPolicy.OFF; options.anonymousFunctionNaming != AnonymousFunctionNamingPolicy.OFF;
return new RemoveUnusedVars.Builder(compiler) return new RemoveUnusedCode.Builder(compiler)
.removeGlobals(!removeOnlyLocals) .removeGlobals(!removeOnlyLocals)
.preserveFunctionExpressionNames(preserveAnonymousFunctionNames) .preserveFunctionExpressionNames(preserveAnonymousFunctionNames)
.removeUnusedPrototypeProperties(options.removeUnusedPrototypeProperties) .removeUnusedPrototypeProperties(options.removeUnusedPrototypeProperties)
Expand Down
2 changes: 1 addition & 1 deletion src/com/google/javascript/jscomp/OptimizeParameters.java
Expand Up @@ -191,7 +191,7 @@ void tryEliminateUnusedArgs(ArrayList<Node> refs) {
return; return;
} }


// NOTE: RemoveUnusedVars removes any trailing unused formals, so we don't need to // NOTE: RemoveUnusedCode removes any trailing unused formals, so we don't need to
// do for that case. // do for that case.


BitSet unremovable = ((BitSet) used.clone()); BitSet unremovable = ((BitSet) used.clone());
Expand Down
Expand Up @@ -266,7 +266,7 @@ public boolean shouldTraverse(NodeTraversal nodeTraversal, Node n, Node parent)
// is first referenced, so that the reference lists are in the right order. // is first referenced, so that the reference lists are in the right order.
// //
// TODO(nicksantos): Maybe generalize this to a continuation mechanism // TODO(nicksantos): Maybe generalize this to a continuation mechanism
// like in RemoveUnusedVars. // like in RemoveUnusedCode.
if (NodeUtil.isHoistedFunctionDeclaration(n)) { if (NodeUtil.isHoistedFunctionDeclaration(n)) {
Node nameNode = n.getFirstChild(); Node nameNode = n.getFirstChild();
Var functionVar = nodeTraversal.getScope().getVar(nameNode.getString()); Var functionVar = nodeTraversal.getScope().getVar(nameNode.getString());
Expand Down
Expand Up @@ -86,7 +86,7 @@
* *
* @author nicksantos@google.com (Nick Santos) * @author nicksantos@google.com (Nick Santos)
*/ */
class RemoveUnusedVars implements CompilerPass { class RemoveUnusedCode implements CompilerPass {


// Properties that are implicitly used as part of the JS language. // Properties that are implicitly used as part of the JS language.
private static final ImmutableSet<String> IMPLICITLY_USED_PROPERTIES = private static final ImmutableSet<String> IMPLICITLY_USED_PROPERTIES =
Expand Down Expand Up @@ -130,7 +130,7 @@ class RemoveUnusedVars implements CompilerPass {
private final boolean removeUnusedPrototypeProperties; private final boolean removeUnusedPrototypeProperties;
private final boolean allowRemovalOfExternProperties; private final boolean allowRemovalOfExternProperties;


RemoveUnusedVars(Builder builder) { RemoveUnusedCode(Builder builder) {
this.compiler = builder.compiler; this.compiler = builder.compiler;
this.codingConvention = builder.compiler.getCodingConvention(); this.codingConvention = builder.compiler.getCodingConvention();
this.removeGlobals = builder.removeGlobals; this.removeGlobals = builder.removeGlobals;
Expand Down Expand Up @@ -176,8 +176,8 @@ Builder allowRemovalOfExternProperties(boolean value) {
return this; return this;
} }


RemoveUnusedVars build() { RemoveUnusedCode build() {
return new RemoveUnusedVars(this); return new RemoveUnusedCode(this);
} }
} }


Expand Down
Expand Up @@ -24,7 +24,7 @@
/** /**
* Test for {@link DefinitionsRemover}. Basically test for the simple removal cases. More * Test for {@link DefinitionsRemover}. Basically test for the simple removal cases. More
* complicated cases are tested by the clients of {@link DefinitionsRemover} such as {@link * complicated cases are tested by the clients of {@link DefinitionsRemover} such as {@link
* PureFunctionIdentifierTest} and {@link RemoveUnusedVarsTest}. * PureFunctionIdentifierTest} and {@link RemoveUnusedCodeTest}.
* *
*/ */
public final class DefinitionsRemoverTest extends CompilerTestCase { public final class DefinitionsRemoverTest extends CompilerTestCase {
Expand Down
2 changes: 1 addition & 1 deletion test/com/google/javascript/jscomp/MultiPassTest.java
Expand Up @@ -387,7 +387,7 @@ private void addRemoveUnusedVars() {
new PassFactory("removeUnusedVars", false) { new PassFactory("removeUnusedVars", false) {
@Override @Override
protected CompilerPass create(AbstractCompiler compiler) { protected CompilerPass create(AbstractCompiler compiler) {
return new RemoveUnusedVars.Builder(compiler).build(); return new RemoveUnusedCode.Builder(compiler).build();
} }
}); });
} }
Expand Down
4 changes: 2 additions & 2 deletions test/com/google/javascript/jscomp/OptimizeCallsTest.java
Expand Up @@ -50,7 +50,7 @@ public void process(Node externs, Node root) {
defFinder.process(externs, root); defFinder.process(externs, root);


new PureFunctionIdentifier(compiler, defFinder).process(externs, root); new PureFunctionIdentifier(compiler, defFinder).process(externs, root);
new RemoveUnusedVars.Builder(compiler).removeGlobals(true).build().process(externs, root); new RemoveUnusedCode.Builder(compiler).removeGlobals(true).build().process(externs, root);


final OptimizeCalls passes = new OptimizeCalls(compiler); final OptimizeCalls passes = new OptimizeCalls(compiler);
passes.addPass(new OptimizeReturns(compiler)); passes.addPass(new OptimizeReturns(compiler));
Expand Down Expand Up @@ -204,7 +204,7 @@ public void testCallSiteInteraction_constructors0() {


public void testCallSiteInteraction_constructors1() { public void testCallSiteInteraction_constructors1() {
// NOTE: Ctor1 used trailing parameter is removed by // NOTE: Ctor1 used trailing parameter is removed by
// RemoveUnusedVars // RemoveUnusedCode


// For now, goog.inherits prevents optimizations // For now, goog.inherits prevents optimizations
test( test(
Expand Down
Expand Up @@ -18,7 +18,7 @@
package com.google.javascript.jscomp; package com.google.javascript.jscomp;


/** /**
* Tests for {@link OptimizeParameters}. Note: interaction with {@link RemoveUnusedVars} is * Tests for {@link OptimizeParameters}. Note: interaction with {@link RemoveUnusedCode} is
* tested in {@link OptimizeCallsTest}. * tested in {@link OptimizeCallsTest}.
*/ */
public final class OptimizeParametersTest extends CompilerTestCase { public final class OptimizeParametersTest extends CompilerTestCase {
Expand Down
Expand Up @@ -20,17 +20,17 @@
import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;


/** /**
* Tests for {@link RemoveUnusedVars} that cover functionality originally in * Tests for {@link RemoveUnusedCode} that cover functionality originally in
* {@link RemoveUnusedPrototypeProperties}. * {@link RemoveUnusedPrototypeProperties}.
*/ */
public final class RemoveUnusedVarsPrototypePropertiesTest extends CompilerTestCase { public final class RemoveUnusedCodePrototypePropertiesTest extends CompilerTestCase {
private static final String EXTERNS = private static final String EXTERNS =
MINIMAL_EXTERNS + "IFoo.prototype.bar; var mExtern; mExtern.bExtern; mExtern['cExtern'];"; MINIMAL_EXTERNS + "IFoo.prototype.bar; var mExtern; mExtern.bExtern; mExtern['cExtern'];";


private boolean keepGlobals = false; private boolean keepGlobals = false;
private boolean allowRemovalOfExternProperties = false; private boolean allowRemovalOfExternProperties = false;


public RemoveUnusedVarsPrototypePropertiesTest() { public RemoveUnusedCodePrototypePropertiesTest() {
super(EXTERNS); super(EXTERNS);
} }


Expand All @@ -44,7 +44,7 @@ protected CompilerPass getProcessor(Compiler compiler) {
return new CompilerPass() { return new CompilerPass() {
@Override @Override
public void process(Node externs, Node root) { public void process(Node externs, Node root) {
new RemoveUnusedVars.Builder(compiler) new RemoveUnusedCode.Builder(compiler)
.removeGlobals(!keepGlobals) .removeGlobals(!keepGlobals)
.removeUnusedPrototypeProperties(true) .removeUnusedPrototypeProperties(true)
.allowRemovalOfExternProperties(allowRemovalOfExternProperties) .allowRemovalOfExternProperties(allowRemovalOfExternProperties)
Expand Down
Expand Up @@ -18,12 +18,12 @@


import com.google.javascript.rhino.Node; import com.google.javascript.rhino.Node;


public final class RemoveUnusedVarsTest extends CompilerTestCase { public final class RemoveUnusedCodeTest extends CompilerTestCase {


private boolean removeGlobal; private boolean removeGlobal;
private boolean preserveFunctionExpressionNames; private boolean preserveFunctionExpressionNames;


public RemoveUnusedVarsTest() { public RemoveUnusedCodeTest() {
// Set up externs to be used in the test cases. // Set up externs to be used in the test cases.
super("function alert() {} var externVar;"); super("function alert() {} var externVar;");
} }
Expand All @@ -46,7 +46,7 @@ protected CompilerPass getProcessor(final Compiler compiler) {
return new CompilerPass() { return new CompilerPass() {
@Override @Override
public void process(Node externs, Node root) { public void process(Node externs, Node root) {
new RemoveUnusedVars.Builder(compiler) new RemoveUnusedCode.Builder(compiler)
.removeGlobals(removeGlobal) .removeGlobals(removeGlobal)
.preserveFunctionExpressionNames(preserveFunctionExpressionNames) .preserveFunctionExpressionNames(preserveFunctionExpressionNames)
.build() .build()
Expand Down

0 comments on commit 39f80ea

Please sign in to comment.