Skip to content

Commit

Permalink
Kill 'computeEscaped' since only 'computeEscapedEs6' is used now.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=177492372
  • Loading branch information
tbreisacher authored and brad4d committed Dec 1, 2017
1 parent f590a5f commit 8196374
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 62 deletions.
62 changes: 7 additions & 55 deletions src/com/google/javascript/jscomp/DataFlowAnalysis.java
Expand Up @@ -215,9 +215,9 @@ final void analyze(int maxSteps) {
if (flow(curNode)) { if (flow(curNode)) {
// If there is a change in the current node, we want to grab the list // If there is a change in the current node, we want to grab the list
// of nodes that this node affects. // of nodes that this node affects.
List<DiGraphNode<N, Branch>> nextNodes = isForward() ? List<DiGraphNode<N, Branch>> nextNodes =
cfg.getDirectedSuccNodes(curNode) : isForward() ? cfg.getDirectedSuccNodes(curNode) : cfg.getDirectedPredNodes(curNode);
cfg.getDirectedPredNodes(curNode);
for (DiGraphNode<N, Branch> nextNode : nextNodes) { for (DiGraphNode<N, Branch> nextNode : nextNodes) {
if (nextNode != cfg.getImplicitReturn()) { if (nextNode != cfg.getImplicitReturn()) {
orderedWorkSet.add(nextNode); orderedWorkSet.add(nextNode);
Expand Down Expand Up @@ -544,64 +544,16 @@ public int hashCode() {


/** /**
* Compute set of escaped variables. When a variable is escaped in a dataflow analysis, it can be * Compute set of escaped variables. When a variable is escaped in a dataflow analysis, it can be
* reference outside of the code that we are analyzing. A variable is escaped if any of the * referenced outside of the code that we are analyzing. A variable is escaped if any of the
* following is true: * following is true:
* *
* <p>
*
* <ol>
* <li>It is defined as the exception name in CATCH clause so it became a variable local not to
* our definition of scope.
* <li>Exported variables as they can be needed after the script terminates.
* <li>Names of named functions because in JavaScript, <i>function foo(){}</i> does not kill
* <i>foo</i> in the dataflow.
*/
static void computeEscaped(
final Scope jsScope,
final Set<Var> escaped,
AbstractCompiler compiler,
ScopeCreator scopeCreator) {
// TODO(user): Very good place to store this information somewhere.

AbstractPostOrderCallback finder = new AbstractPostOrderCallback() {
@Override
public void visit(NodeTraversal t, Node n, Node parent) {
if (jsScope == t.getScope() || !n.isName()
|| parent.isFunction()) {
return;
}
String name = n.getString();
Var var = t.getScope().getVar(name);
if (var != null && var.scope == jsScope) {
escaped.add(jsScope.getVar(name));
}
}
};

NodeTraversal t = new NodeTraversal(compiler, finder, scopeCreator);
t.traverseAtScope(jsScope);

// 1: Remove the exception name in CATCH which technically isn't local to
// begin with.
for (Var var : jsScope.getVarIterable()) {
if (var.getParentNode().isCatch() ||
compiler.getCodingConvention().isExported(var.getName())) {
escaped.add(var);
}
}
}

/**
* Alternate implementation of compute escaped for ES6.
*
* It should only be run when the jsScope is a function scope.
*
* The definition of escaped are
* 1. Exported variables as they can be needed after the script terminates. * 1. Exported variables as they can be needed after the script terminates.
* 2. Names of named functions because in JavaScript, function foo(){} does not kill * 2. Names of named functions because in JavaScript, function foo(){} does not kill
* foo in the dataflow. * foo in the dataflow.
*
* @param jsScope Must be a function scope
*/ */
static void computeEscapedEs6( static void computeEscaped(
final Scope jsScope, final Scope jsScope,
final Set<Var> escaped, final Set<Var> escaped,
AbstractCompiler compiler, AbstractCompiler compiler,
Expand Down
Expand Up @@ -154,7 +154,7 @@ public int hashCode() {
this.allVarsInFn = new HashMap<>(); this.allVarsInFn = new HashMap<>();
this.orderedVars = new ArrayList<>(); this.orderedVars = new ArrayList<>();


computeEscapedEs6(jsScope, escaped, compiler, scopeCreator); computeEscaped(jsScope, escaped, compiler, scopeCreator);


NodeUtil.getAllVarsDeclaredInFunction( NodeUtil.getAllVarsDeclaredInFunction(
allVarsInFn, orderedVars, compiler, scopeCreator, jsScope); allVarsInFn, orderedVars, compiler, scopeCreator, jsScope);
Expand Down
Expand Up @@ -64,7 +64,7 @@ class MaybeReachingVariableUse extends


// TODO(user): Maybe compute it somewhere else and re-use the escape // TODO(user): Maybe compute it somewhere else and re-use the escape
// local set here. // local set here.
computeEscapedEs6(jsScope.getParent(), escaped, compiler, scopeCreator); computeEscaped(jsScope.getParent(), escaped, compiler, scopeCreator);
NodeUtil.getAllVarsDeclaredInFunction( NodeUtil.getAllVarsDeclaredInFunction(
allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent()); allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent());
} }
Expand Down Expand Up @@ -110,8 +110,8 @@ public ReachingUses(ReachingUses other) {


@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return (other instanceof ReachingUses) && return (other instanceof ReachingUses)
((ReachingUses) other).mayUseMap.equals(this.mayUseMap); && ((ReachingUses) other).mayUseMap.equals(this.mayUseMap);
} }


@Override @Override
Expand Down
Expand Up @@ -61,7 +61,7 @@ final class MustBeReachingVariableDef extends
this.escaped = new HashSet<>(); this.escaped = new HashSet<>();
this.allVarsInFn = new HashMap<>(); this.allVarsInFn = new HashMap<>();
this.orderedVars = new ArrayList<>(); this.orderedVars = new ArrayList<>();
computeEscapedEs6(jsScope.getParent(), escaped, compiler, scopeCreator); computeEscaped(jsScope.getParent(), escaped, compiler, scopeCreator);
NodeUtil.getAllVarsDeclaredInFunction( NodeUtil.getAllVarsDeclaredInFunction(
allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent()); allVarsInFn, orderedVars, compiler, scopeCreator, jsScope.getParent());
} }
Expand Down Expand Up @@ -152,8 +152,7 @@ public MustDef(MustDef other) {


@Override @Override
public boolean equals(Object other) { public boolean equals(Object other) {
return (other instanceof MustDef) && return (other instanceof MustDef) && ((MustDef) other).reachingDef.equals(this.reachingDef);
((MustDef) other).reachingDef.equals(this.reachingDef);
} }


@Override @Override
Expand Down

0 comments on commit 8196374

Please sign in to comment.