aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java
diff options
context:
space:
mode:
authorGravatar Nathan Harmata <nharmata@google.com>2017-02-27 21:55:56 +0000
committerGravatar Yue Gan <yueg@google.com>2017-02-28 11:33:08 +0000
commit822c37816ac669e51bec3853b41849a19ec5e230 (patch)
treea12e1f438342aa9ec1846089fc255bf2abb18ad3 /src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java
parentfb64609c3f1d3492f4d80807f5d91894fa147172 (diff)
Reimplement blaze query using an async evaluation model. Use a concurrent backend for SkyQueryEnvironment's implementation in order to achieve parallelism.
Advantages: -New design has no flaws that the old design had. -Code is structured so that deadlocks due to thread starvation are impossible (yup!). Disadvantages: -The meat of this change needs to all be in a single CL because every single QueryFunction and QueryExpression needs to be rewritten in the async style. Still TODO: -Fully embrace the async model in all QueryFunctions (e.g. 'rdeps', 'allpaths'). -Use concurrency in BlazeQueryEnvironment to achieve parallel evaluation for (non SkyQuery) 'blaze query' and genquery. -- PiperOrigin-RevId: 148690279 MOS_MIGRATED_REVID=148690279
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/TargetLiteral.java40
1 files changed, 16 insertions, 24 deletions
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 aeace9aa70..733bffb065 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
@@ -13,11 +13,10 @@
// limitations under the License.
package com.google.devtools.build.lib.query2.engine;
+import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryTaskFuture;
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
@@ -45,38 +44,31 @@ public final class TargetLiteral extends QueryExpression {
return LetExpression.isValidVarReference(pattern);
}
- private <T> void evalVarReference(VariableContext<T> context, Callback<T> callback)
- throws QueryException, InterruptedException {
+ private <T> QueryTaskFuture<Void> evalVarReference(
+ QueryEnvironment<T> env, VariableContext<T> context, Callback<T> callback) {
String varName = LetExpression.getNameFromReference(pattern);
Set<T> value = context.get(varName);
if (value == null) {
- throw new QueryException(this, "undefined variable '" + varName + "'");
+ return env.immediateFailedFuture(
+ 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()) {
- evalVarReference(context, callback);
- } else {
- env.getTargetsMatchingPattern(this, pattern, callback);
+ try {
+ callback.process(value);
+ return env.immediateSuccessfulFuture(null);
+ } catch (QueryException e) {
+ return env.immediateFailedFuture(e);
+ } catch (InterruptedException e) {
+ return env.immediateCancelledFuture();
}
}
@Override
- protected <T> void parEvalImpl(
- QueryEnvironment<T> env,
- VariableContext<T> context,
- ThreadSafeCallback<T> callback,
- ForkJoinPool forkJoinPool)
- throws QueryException, InterruptedException {
+ public <T> QueryTaskFuture<Void> eval(
+ QueryEnvironment<T> env, VariableContext<T> context, Callback<T> callback) {
if (isVariableReference()) {
- evalVarReference(context, callback);
+ return evalVarReference(env, context, callback);
} else {
- env.getTargetsMatchingPatternPar(this, pattern, callback, forkJoinPool);
+ return env.getTargetsMatchingPattern(this, pattern, callback);
}
}