From cda5b66af3da31c74df73a8a19f67691d5d9454f Mon Sep 17 00:00:00 2001 From: Janak Ramakrishnan Date: Thu, 18 Jun 2015 23:46:36 +0000 Subject: Clean up AllPathsFunction and get rid of getFwdDeps(Target) and getReverseDeps(Target) from the QueryEnvironment interface, since they're no longer needed by any query functions, and also WalkableGraph#get{Direct,Reverse}Deps(SkyKey). -- MOS_MIGRATED_REVID=96361760 --- .../build/lib/query2/BlazeQueryEnvironment.java | 14 ++----------- .../build/lib/query2/SkyQueryEnvironment.java | 21 ++------------------ .../build/lib/query2/engine/AllPathsFunction.java | 13 ++++++------ .../build/lib/query2/engine/QueryEnvironment.java | 6 ------ .../build/skyframe/DelegatingWalkableGraph.java | 10 ---------- .../devtools/build/skyframe/WalkableGraph.java | 23 ++++++---------------- 6 files changed, 17 insertions(+), 70 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java index e7992f43a9..a5c6d1da1a 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/BlazeQueryEnvironment.java @@ -194,30 +194,20 @@ public class BlazeQueryEnvironment extends AbstractBlazeQueryEnvironment return getNode(target).getLabel(); } - @Override - public Collection getFwdDeps(Target target) { - return getTargetsFromNodes(getNode(target).getSuccessors()); - } - @Override public Collection getFwdDeps(Iterable targets) { Set result = new HashSet<>(); for (Target target : targets) { - result.addAll(getFwdDeps(target)); + result.addAll(getTargetsFromNodes(getNode(target).getSuccessors())); } return result; } - @Override - public Collection getReverseDeps(Target target) { - return getTargetsFromNodes(getNode(target).getPredecessors()); - } - @Override public Collection getReverseDeps(Iterable targets) { Set result = new HashSet<>(); for (Target target : targets) { - result.addAll(getReverseDeps(target)); + result.addAll(getTargetsFromNodes(getNode(target).getPredecessors())); } return result; } diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java index 00ddd2b8b1..473c69dedc 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java @@ -19,6 +19,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.base.Supplier; import com.google.common.collect.Collections2; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -126,10 +127,6 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment { return TransitiveTargetValue.key(value.getLabel()); } - private Collection getRawFwdDeps(Target target) { - return makeTargets(graph.getDirectDeps(makeKey(target))); - } - private Map> makeTargetsMap(Map> input) { ImmutableMap.Builder> result = ImmutableMap.builder(); @@ -143,10 +140,6 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment { return makeTargetsMap(graph.getDirectDeps(makeKeys(targets))); } - private Collection getRawReverseDeps(Target target) { - return makeTargets(graph.getReverseDeps(makeKey(target))); - } - private Map> getRawReverseDeps(Iterable targets) { return makeTargetsMap(graph.getReverseDeps(makeKeys(targets))); } @@ -173,11 +166,6 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment { }); } - @Override - public Collection getFwdDeps(Target target) { - return filterFwdDeps(target, getRawFwdDeps(target)); - } - @Override public Collection getFwdDeps(Iterable targets) { Set result = new HashSet<>(); @@ -199,11 +187,6 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment { } - @Override - public Collection getReverseDeps(Target target) { - return filterReverseDeps(target, getRawReverseDeps(target)); - } - @Override public Collection getReverseDeps(Iterable targets) { Set result = new HashSet<>(); @@ -240,7 +223,7 @@ public class SkyQueryEnvironment extends AbstractBlazeQueryEnvironment { if (to.equals(current)) { return ImmutableSet.copyOf(Digraph.getPathToTreeNode(nodeToParent, to)); } - for (Target dep : getFwdDeps(current)) { + for (Target dep : getFwdDeps(ImmutableList.of(current))) { if (!nodeToParent.containsKey(dep)) { nodeToParent.put(dep, current); toVisit.addFirst(dep); diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java b/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java index d2d5f05f9c..4920298bfb 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/AllPathsFunction.java @@ -19,8 +19,9 @@ import com.google.devtools.build.lib.query2.engine.QueryEnvironment.Argument; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.ArgumentType; import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryFunction; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Set; @@ -65,11 +66,11 @@ public class AllPathsFunction implements QueryFunction { Set reachableFromX = env.getTransitiveClosure(fromValue); Set result = intersection(reachableFromX, toValue); - LinkedList worklist = new LinkedList<>(result); - - T n; - while ((n = worklist.poll()) != null) { - for (T np : env.getReverseDeps(n)) { + Collection worklist = result; + while (!worklist.isEmpty()) { + Collection reverseDeps = env.getReverseDeps(worklist); + worklist = new ArrayList<>(); + for (T np : reverseDeps) { if (reachableFromX.contains(np)) { if (result.add(np)) { worklist.add(np); diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java index a6d6156050..78812cc11a 100644 --- a/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java @@ -152,15 +152,9 @@ public interface QueryEnvironment { // be possible to remove it. T getOrCreate(T target); - /** Returns the direct forward dependencies of the specified target. */ - Collection getFwdDeps(T target); - /** Returns the direct forward dependencies of the specified targets. */ Collection getFwdDeps(Iterable targets); - /** Returns the direct reverse dependencies of the specified target. */ - Collection getReverseDeps(T target); - /** Returns the direct reverse dependencies of the specified targets. */ Collection getReverseDeps(Iterable targets); diff --git a/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java b/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java index fee4f9c579..b88b890300 100644 --- a/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java +++ b/src/main/java/com/google/devtools/build/skyframe/DelegatingWalkableGraph.java @@ -82,11 +82,6 @@ public class DelegatingWalkableGraph implements WalkableGraph { return errorInfo == null ? null : errorInfo.getException(); } - @Override - public Iterable getDirectDeps(SkyKey key) { - return getEntry(key).getDirectDeps(); - } - private static final Function> GET_DIRECT_DEPS_FUNCTION = new Function>() { @Override @@ -100,11 +95,6 @@ public class DelegatingWalkableGraph implements WalkableGraph { return Maps.transformValues(getEntries(keys), GET_DIRECT_DEPS_FUNCTION); } - @Override - public Iterable getReverseDeps(SkyKey key) { - return getEntry(key).getReverseDeps(); - } - private static final Function> GET_REVERSE_DEPS_FUNCTION = new Function>() { @Override diff --git a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java index e020a26ba7..be68248b29 100644 --- a/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java +++ b/src/main/java/com/google/devtools/build/skyframe/WalkableGraph.java @@ -48,31 +48,20 @@ public interface WalkableGraph { /** * Returns the exception thrown when computing the node with the given key, if any. If the node - * was computed successfully, returns null. A node with this key must exist in the graph. + * was computed successfully, returns null. A node with this key must exist and be done in the + * graph. */ @Nullable Exception getException(SkyKey key); /** - * Returns the direct dependencies of the node with the given key. A node with this key must exist - * in the graph. - */ - Iterable getDirectDeps(SkyKey key); - - /** - * Returns a map giving the direct dependencies of the nodes with the given keys. Same semantics - * as {@link #getDirectDeps(SkyKey)}. + * Returns a map giving the direct dependencies of the nodes with the given keys. A node for each + * given key must exist and be done in the graph. */ Map> getDirectDeps(Iterable keys); - /** - * Returns the reverse dependencies of the node with the given key. A node with this key must - * exist in the graph. - */ - Iterable getReverseDeps(SkyKey key); - /** - * Returns a map giving the reverse dependencies of the nodes with the given keys. Same semantics - * as {@link #getReverseDeps(SkyKey)}. + * Returns a map giving the reverse dependencies of the nodes with the given keys. A node for each + * given key must exist and be done in the graph. */ Map> getReverseDeps(Iterable keys); -- cgit v1.2.3