aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/engine
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2016-11-14 19:55:50 +0000
committerGravatar Damien Martin-Guillerez <dmarting@google.com>2016-11-15 15:59:08 +0000
commit5bd26b24a643432c962b6256876b6729199c03d9 (patch)
tree9475e4cbc373a57504c41812e4cd593a7cc7d84e /src/main/java/com/google/devtools/build/lib/query2/engine
parentb7eeaa37705c7f4282d0c9bd654fb2540c361d7a (diff)
Make TargetPattern evaluation during query evaluation more parallel-friendly by introducing TargetPattern#parEval, which allows TargetPatterns' evaluations to explicitly have parallel implementations (no need to secretly use a FJP).
-- MOS_MIGRATED_REVID=139101922
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/QueryEnvironment.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java32
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/ThreadSafeCallback.java4
3 files changed, 39 insertions, 7 deletions
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 5cf7c6efbc..9245a68972 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
@@ -159,6 +159,16 @@ public interface QueryEnvironment<T> {
void getTargetsMatchingPattern(QueryExpression owner, String pattern, Callback<T> callback)
throws QueryException, InterruptedException;
+ /**
+ * Same as {@link #getTargetsMatchingPattern}, but optionally making use of the given
+ * {@link ForkJoinPool} to achieve parallelism.
+ */
+ void getTargetsMatchingPatternPar(
+ QueryExpression owner,
+ String pattern,
+ ThreadSafeCallback<T> callback,
+ ForkJoinPool forkJoinPool) throws QueryException, InterruptedException;
+
/** Ensures the specified target exists. */
// NOTE(bazel-team): this method is left here as scaffolding from a previous refactoring. It may
// be possible to remove it.
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java b/src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java
index 8b718ab01a..aeace9aa70 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java
@@ -17,6 +17,7 @@ import com.google.devtools.build.lib.util.Preconditions;
import java.util.Collection;
import java.util.Set;
+import java.util.concurrent.ForkJoinPool;
/**
* A literal set of targets, using 'blaze build' syntax. Or, a reference to a
@@ -44,23 +45,42 @@ public final class TargetLiteral extends QueryExpression {
return LetExpression.isValidVarReference(pattern);
}
+ private <T> void evalVarReference(VariableContext<T> context, Callback<T> callback)
+ throws QueryException, InterruptedException {
+ String varName = LetExpression.getNameFromReference(pattern);
+ Set<T> value = context.get(varName);
+ if (value == null) {
+ throw new QueryException(this, "undefined variable '" + varName + "'");
+ }
+ callback.process(value);
+ }
+
@Override
protected <T> void evalImpl(
QueryEnvironment<T> env, VariableContext<T> context, Callback<T> callback)
throws QueryException, InterruptedException {
if (isVariableReference()) {
- String varName = LetExpression.getNameFromReference(pattern);
- Set<T> value = context.get(varName);
- if (value == null) {
- throw new QueryException(this, "undefined variable '" + varName + "'");
- }
- callback.process(value);
+ evalVarReference(context, callback);
} else {
env.getTargetsMatchingPattern(this, pattern, callback);
}
}
@Override
+ protected <T> void parEvalImpl(
+ QueryEnvironment<T> env,
+ VariableContext<T> context,
+ ThreadSafeCallback<T> callback,
+ ForkJoinPool forkJoinPool)
+ throws QueryException, InterruptedException {
+ if (isVariableReference()) {
+ evalVarReference(context, callback);
+ } else {
+ env.getTargetsMatchingPatternPar(this, pattern, callback, forkJoinPool);
+ }
+ }
+
+ @Override
public void collectTargetPatterns(Collection<String> literals) {
if (!isVariableReference()) {
literals.add(pattern);
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/ThreadSafeCallback.java b/src/main/java/com/google/devtools/build/lib/query2/engine/ThreadSafeCallback.java
index d39172819f..950335e38a 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/ThreadSafeCallback.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/ThreadSafeCallback.java
@@ -14,8 +14,10 @@
package com.google.devtools.build.lib.query2.engine;
import com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadSafe;
+import com.google.devtools.build.lib.util.ThreadSafeBatchCallback;
/** Marker interface for a {@link Callback} that is {@link ThreadSafe}. */
@ThreadSafe
-public interface ThreadSafeCallback<T> extends Callback<T> {
+public interface ThreadSafeCallback<T>
+ extends Callback<T>, ThreadSafeBatchCallback<T, QueryException> {
}