aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-08-10 19:15:15 +0000
committerGravatar Yue Gan <yueg@google.com>2016-08-11 09:14:33 +0000
commit33faf91356e0b9d0326f5d0330c2cf7189cf4da1 (patch)
tree4557d47ca3d098343acc2b94d63f5c48c56cdedc
parent8a07a959e10040642cdf2e6fa21edcd6a1e9212b (diff)
Get rid of InvalidatableGraph. This explicit concept is no longer needed.
-- MOS_MIGRATED_REVID=129895423
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/EagerInvalidator.java10
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/InMemoryGraph.java5
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/InMemoryGraphImpl.java9
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/InvalidatableGraph.java34
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/InvalidatingNodeVisitor.java18
-rw-r--r--src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java2
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java15
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/DeterministicInMemoryGraph.java5
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/NotifyingHelper.java52
-rw-r--r--src/test/java/com/google/devtools/build/skyframe/NotifyingInMemoryGraph.java5
10 files changed, 51 insertions, 104 deletions
diff --git a/src/main/java/com/google/devtools/build/skyframe/EagerInvalidator.java b/src/main/java/com/google/devtools/build/skyframe/EagerInvalidator.java
index b7c1ee9545..5dba03dc28 100644
--- a/src/main/java/com/google/devtools/build/skyframe/EagerInvalidator.java
+++ b/src/main/java/com/google/devtools/build/skyframe/EagerInvalidator.java
@@ -75,7 +75,7 @@ public final class EagerInvalidator {
@Nullable
static DirtyingNodeVisitor createInvalidatingVisitorIfNeeded(
- InvalidatableGraph graph,
+ QueryableGraph graph,
Iterable<SkyKey> diff,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
@@ -89,7 +89,7 @@ public final class EagerInvalidator {
@Nullable
private static DirtyingNodeVisitor createInvalidatingVisitorIfNeeded(
- InvalidatableGraph graph,
+ QueryableGraph graph,
Iterable<SkyKey> diff,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
@@ -115,7 +115,7 @@ public final class EagerInvalidator {
* an executor constructed with the provided factory.
*/
public static void invalidate(
- InvalidatableGraph graph,
+ QueryableGraph graph,
Iterable<SkyKey> diff,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
@@ -135,7 +135,7 @@ public final class EagerInvalidator {
* the provided {@link ForkJoinPool}.
*/
public static void invalidate(
- InvalidatableGraph graph,
+ QueryableGraph graph,
Iterable<SkyKey> diff,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
@@ -161,7 +161,7 @@ public final class EagerInvalidator {
/** Invalidates given values and their upward transitive closure in the graph. */
public static void invalidate(
- InvalidatableGraph graph,
+ QueryableGraph graph,
Iterable<SkyKey> diff,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
diff --git a/src/main/java/com/google/devtools/build/skyframe/InMemoryGraph.java b/src/main/java/com/google/devtools/build/skyframe/InMemoryGraph.java
index 9eee52e581..02735c0e8e 100644
--- a/src/main/java/com/google/devtools/build/skyframe/InMemoryGraph.java
+++ b/src/main/java/com/google/devtools/build/skyframe/InMemoryGraph.java
@@ -16,10 +16,7 @@ package com.google.devtools.build.skyframe;
import java.util.Map;
/** {@link ProcessableGraph} that exposes the contents of the entire graph. */
-interface InMemoryGraph extends ProcessableGraph, InvalidatableGraph {
- @Override
- Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys);
-
+interface InMemoryGraph extends ProcessableGraph {
/**
* Returns a read-only live view of the nodes in the graph. All node are included. Dirty values
* include their Node value. Values in error have a null value.
diff --git a/src/main/java/com/google/devtools/build/skyframe/InMemoryGraphImpl.java b/src/main/java/com/google/devtools/build/skyframe/InMemoryGraphImpl.java
index ff5ce57b69..eca58b3b06 100644
--- a/src/main/java/com/google/devtools/build/skyframe/InMemoryGraphImpl.java
+++ b/src/main/java/com/google/devtools/build/skyframe/InMemoryGraphImpl.java
@@ -55,10 +55,10 @@ public class InMemoryGraphImpl implements InMemoryGraph {
}
@Override
- public Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys) {
+ public Map<SkyKey, NodeEntry> getBatch(SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
ImmutableMap.Builder<SkyKey, NodeEntry> builder = ImmutableMap.builder();
for (SkyKey key : keys) {
- NodeEntry entry = get(null, Reason.OTHER, key);
+ NodeEntry entry = get(null, reason, key);
if (entry != null) {
builder.put(key, entry);
}
@@ -66,11 +66,6 @@ public class InMemoryGraphImpl implements InMemoryGraph {
return builder.build();
}
- @Override
- public Map<SkyKey, NodeEntry> getBatch(SkyKey requestor, Reason reason, Iterable<SkyKey> keys) {
- return getBatchForInvalidation(keys);
- }
-
protected NodeEntry createIfAbsent(SkyKey key) {
NodeEntry newval = keepEdges ? new InMemoryNodeEntry() : new EdgelessInMemoryNodeEntry();
NodeEntry oldval = nodeMap.putIfAbsent(key, newval);
diff --git a/src/main/java/com/google/devtools/build/skyframe/InvalidatableGraph.java b/src/main/java/com/google/devtools/build/skyframe/InvalidatableGraph.java
deleted file mode 100644
index 8abdae6263..0000000000
--- a/src/main/java/com/google/devtools/build/skyframe/InvalidatableGraph.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-package com.google.devtools.build.skyframe;
-
-import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
-
-import java.util.Map;
-
-/**
- * A graph that exposes thin representations of its entries and structure, for use during
- * invalidation.
- *
- * <p>Public only for use in alternative graph implementations.
- */
-@ThreadSafe
-public interface InvalidatableGraph {
- /**
- * Fetches all the given thin nodes. Returns a map {@code m} such that, for all {@code k} in
- * {@code keys}, {@code m.get(k).equals(e)} iff {@code get(k) == e} and {@code e != null}, and
- * {@code !m.containsKey(k)} iff {@code get(k) == null}.
- */
- Map<SkyKey, ? extends ThinNodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys);
-}
diff --git a/src/main/java/com/google/devtools/build/skyframe/InvalidatingNodeVisitor.java b/src/main/java/com/google/devtools/build/skyframe/InvalidatingNodeVisitor.java
index c8dd68a0fe..543ccf4c42 100644
--- a/src/main/java/com/google/devtools/build/skyframe/InvalidatingNodeVisitor.java
+++ b/src/main/java/com/google/devtools/build/skyframe/InvalidatingNodeVisitor.java
@@ -29,6 +29,7 @@ import com.google.devtools.build.lib.concurrent.QuiescingExecutor;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
import com.google.devtools.build.lib.util.Pair;
import com.google.devtools.build.lib.util.Preconditions;
+import com.google.devtools.build.skyframe.QueryableGraph.Reason;
import com.google.devtools.build.skyframe.ThinNodeEntry.MarkedDirtyResult;
import java.util.ArrayList;
@@ -62,7 +63,7 @@ import javax.annotation.Nullable;
*
* <p>This is intended only for use in alternative {@code MemoizingEvaluator} implementations.
*/
-public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph> {
+public abstract class InvalidatingNodeVisitor<TGraph extends QueryableGraph> {
// Default thread count is equal to the number of cores to exploit
// that level of hardware parallelism, since invalidation should be CPU-bound.
@@ -269,7 +270,8 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
for (SkyKey key : unvisitedKeys) {
pendingVisitations.add(Pair.of(key, InvalidationType.DELETED));
}
- final Map<SkyKey, NodeEntry> entries = graph.getBatchForInvalidation(unvisitedKeys);
+ final Map<SkyKey, NodeEntry> entries =
+ graph.getBatch(null, Reason.INVALIDATION, unvisitedKeys);
for (final SkyKey key : unvisitedKeys) {
executor.execute(
new Runnable() {
@@ -305,7 +307,8 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
entry.isDone()
? entry.getDirectDeps()
: entry.getAllDirectDepsForIncompleteNode();
- Map<SkyKey, NodeEntry> depMap = graph.getBatchForInvalidation(directDeps);
+ Map<SkyKey, NodeEntry> depMap =
+ graph.getBatch(key, Reason.INVALIDATION, directDeps);
for (Map.Entry<SkyKey, NodeEntry> directDepEntry : depMap.entrySet()) {
NodeEntry dep = directDepEntry.getValue();
if (dep != null) {
@@ -338,7 +341,7 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
}
/** A node-dirtying implementation. */
- static class DirtyingNodeVisitor extends InvalidatingNodeVisitor<InvalidatableGraph> {
+ static class DirtyingNodeVisitor extends InvalidatingNodeVisitor<QueryableGraph> {
private final Set<SkyKey> changed =
Collections.newSetFromMap(
@@ -351,7 +354,7 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
private final boolean supportInterruptions;
protected DirtyingNodeVisitor(
- InvalidatableGraph graph,
+ QueryableGraph graph,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
DirtyKeyTracker dirtyKeyTracker,
@@ -365,7 +368,7 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
* passing {@code false} for {@param supportInterruptions}.
*/
protected DirtyingNodeVisitor(
- InvalidatableGraph graph,
+ QueryableGraph graph,
EvaluationProgressReceiver invalidationReceiver,
InvalidationState state,
DirtyKeyTracker dirtyKeyTracker,
@@ -432,7 +435,8 @@ public abstract class InvalidatingNodeVisitor<TGraph extends InvalidatableGraph>
pendingVisitations.add(Pair.of(key, invalidationType));
}
}
- final Map<SkyKey, ? extends ThinNodeEntry> entries = graph.getBatchForInvalidation(keysToGet);
+ final Map<SkyKey, ? extends ThinNodeEntry> entries =
+ graph.getBatch(null, Reason.INVALIDATION, keysToGet);
if (enqueueingKeyForExistenceCheck != null && entries.size() != keysToGet.size()) {
Set<SkyKey> missingKeys = Sets.difference(ImmutableSet.copyOf(keysToGet), entries.keySet());
throw new IllegalStateException(
diff --git a/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java b/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
index 4d5d21c5de..cfbff0a447 100644
--- a/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
+++ b/src/main/java/com/google/devtools/build/skyframe/MemoizingEvaluator.java
@@ -133,7 +133,7 @@ public interface MemoizingEvaluator {
interface GraphTransformerForTesting {
InMemoryGraph transform(InMemoryGraph graph);
- InvalidatableGraph transform(InvalidatableGraph graph);
+ QueryableGraph transform(QueryableGraph graph);
ProcessableGraph transform(ProcessableGraph graph);
}
diff --git a/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java b/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
index e27cab4790..f2a1560f54 100644
--- a/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
+++ b/src/test/java/com/google/devtools/build/skyframe/DeterministicHelper.java
@@ -41,8 +41,8 @@ public class DeterministicHelper extends NotifyingHelper {
}
@Override
- public InvalidatableGraph transform(InvalidatableGraph graph) {
- return new DeterministicInvalidatableGraph(graph, listener);
+ public QueryableGraph transform(QueryableGraph graph) {
+ return new DeterministicQueryableGraph(graph, listener);
}
@Override
@@ -83,14 +83,17 @@ public class DeterministicHelper extends NotifyingHelper {
return result;
}
- private static class DeterministicInvalidatableGraph extends NotifyingInvalidatableGraph {
- DeterministicInvalidatableGraph(InvalidatableGraph delegate, Listener graphListener) {
+ private static class DeterministicQueryableGraph extends NotifyingQueryableGraph {
+ DeterministicQueryableGraph(QueryableGraph delegate, Listener graphListener) {
super(delegate, new DeterministicHelper(graphListener));
}
@Override
- public Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys) {
- return makeDeterministic(super.getBatchForInvalidation(keys));
+ public Map<SkyKey, NodeEntry> getBatch(
+ @Nullable SkyKey requestor,
+ Reason reason,
+ Iterable<SkyKey> keys) {
+ return makeDeterministic(super.getBatch(requestor, reason, keys));
}
}
diff --git a/src/test/java/com/google/devtools/build/skyframe/DeterministicInMemoryGraph.java b/src/test/java/com/google/devtools/build/skyframe/DeterministicInMemoryGraph.java
index fda230ead1..a0233838ec 100644
--- a/src/test/java/com/google/devtools/build/skyframe/DeterministicInMemoryGraph.java
+++ b/src/test/java/com/google/devtools/build/skyframe/DeterministicInMemoryGraph.java
@@ -27,11 +27,6 @@ class DeterministicInMemoryGraph extends DeterministicHelper.DeterministicProces
}
@Override
- public Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys) {
- return getBatch(null, Reason.INVALIDATION, keys);
- }
-
- @Override
public Map<SkyKey, SkyValue> getValues() {
return ((InMemoryGraph) delegate).getValues();
}
diff --git a/src/test/java/com/google/devtools/build/skyframe/NotifyingHelper.java b/src/test/java/com/google/devtools/build/skyframe/NotifyingHelper.java
index 655b7f8276..ad9a591eb8 100644
--- a/src/test/java/com/google/devtools/build/skyframe/NotifyingHelper.java
+++ b/src/test/java/com/google/devtools/build/skyframe/NotifyingHelper.java
@@ -40,8 +40,8 @@ public class NotifyingHelper {
}
@Override
- public InvalidatableGraph transform(InvalidatableGraph graph) {
- return new NotifyingInvalidatableGraph(graph, listener);
+ public QueryableGraph transform(QueryableGraph graph) {
+ return new NotifyingQueryableGraph(graph, listener);
}
@Override
@@ -72,39 +72,47 @@ public class NotifyingHelper {
return entry == null ? null : new NotifyingNodeEntry(key, entry);
}
- static class NotifyingInvalidatableGraph implements InvalidatableGraph {
- private final InvalidatableGraph delegate;
- private final NotifyingHelper notifyingHelper;
+ static class NotifyingQueryableGraph implements QueryableGraph {
+ private final QueryableGraph delegate;
+ protected final NotifyingHelper notifyingHelper;
- NotifyingInvalidatableGraph(InvalidatableGraph delegate, Listener graphListener) {
+ NotifyingQueryableGraph(QueryableGraph delegate, Listener graphListener) {
this.notifyingHelper = new NotifyingHelper(graphListener);
this.delegate = delegate;
}
- NotifyingInvalidatableGraph(InvalidatableGraph delegate, NotifyingHelper helper) {
+ NotifyingQueryableGraph(QueryableGraph delegate, NotifyingHelper helper) {
this.notifyingHelper = helper;
this.delegate = delegate;
}
@Override
- public Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys) {
+ public Map<SkyKey, NodeEntry> getBatch(
+ @Nullable SkyKey requestor,
+ Reason reason,
+ Iterable<SkyKey> keys) {
return Maps.transformEntries(
- delegate.getBatchForInvalidation(keys),
+ delegate.getBatch(requestor, reason, keys),
notifyingHelper.wrapEntry);
}
+
+ @Nullable
+ @Override
+ public NodeEntry get(@Nullable SkyKey requestor, Reason reason, SkyKey key) {
+ return notifyingHelper.wrapEntry(key, delegate.get(requestor, reason, key));
+ }
}
- static class NotifyingProcessableGraph implements ProcessableGraph {
+ static class NotifyingProcessableGraph
+ extends NotifyingQueryableGraph implements ProcessableGraph {
protected final ProcessableGraph delegate;
- protected final NotifyingHelper notifyingHelper;
NotifyingProcessableGraph(ProcessableGraph delegate, Listener graphListener) {
- this.notifyingHelper = new NotifyingHelper(graphListener);
- this.delegate = delegate;
+ this(delegate, new NotifyingHelper(graphListener));
}
NotifyingProcessableGraph(ProcessableGraph delegate, NotifyingHelper helper) {
- this.notifyingHelper = helper;
+ super(delegate, helper);
this.delegate = delegate;
}
@@ -123,22 +131,6 @@ public class NotifyingHelper {
delegate.createIfAbsentBatch(requestor, reason, keys),
notifyingHelper.wrapEntry);
}
-
- @Override
- public Map<SkyKey, NodeEntry> getBatch(
- @Nullable SkyKey requestor,
- Reason reason,
- Iterable<SkyKey> keys) {
- return Maps.transformEntries(
- delegate.getBatch(requestor, reason, keys),
- notifyingHelper.wrapEntry);
- }
-
- @Nullable
- @Override
- public NodeEntry get(@Nullable SkyKey requestor, Reason reason, SkyKey key) {
- return notifyingHelper.wrapEntry(key, delegate.get(requestor, reason, key));
- }
}
/**
diff --git a/src/test/java/com/google/devtools/build/skyframe/NotifyingInMemoryGraph.java b/src/test/java/com/google/devtools/build/skyframe/NotifyingInMemoryGraph.java
index 1aa32cebdb..752dac7001 100644
--- a/src/test/java/com/google/devtools/build/skyframe/NotifyingInMemoryGraph.java
+++ b/src/test/java/com/google/devtools/build/skyframe/NotifyingInMemoryGraph.java
@@ -23,11 +23,6 @@ class NotifyingInMemoryGraph extends NotifyingHelper.NotifyingProcessableGraph
}
@Override
- public Map<SkyKey, NodeEntry> getBatchForInvalidation(Iterable<SkyKey> keys) {
- return getBatch(null, Reason.INVALIDATION, keys);
- }
-
- @Override
public Map<SkyKey, SkyValue> getValues() {
return ((InMemoryGraph) delegate).getValues();
}