aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.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/LetExpression.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/LetExpression.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java25
1 files changed, 18 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java b/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
index 64d94da19a..a7c3abeb62 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/engine/LetExpression.java
@@ -13,6 +13,8 @@
// limitations under the License.
package com.google.devtools.build.lib.query2.engine;
+import com.google.common.base.Function;
+import com.google.devtools.build.lib.query2.engine.QueryEnvironment.QueryTaskFuture;
import java.util.Collection;
import java.util.Set;
import java.util.regex.Pattern;
@@ -64,15 +66,24 @@ class LetExpression extends QueryExpression {
}
@Override
- protected <T> void evalImpl(
- QueryEnvironment<T> env, VariableContext<T> context, Callback<T> callback)
- throws QueryException, InterruptedException {
+ public <T> QueryTaskFuture<Void> eval(
+ final QueryEnvironment<T> env,
+ final VariableContext<T> context,
+ final Callback<T> callback) {
if (!NAME_PATTERN.matcher(varName).matches()) {
- throw new QueryException(this, "invalid variable name '" + varName + "' in let expression");
+ return env.immediateFailedFuture(
+ new QueryException(this, "invalid variable name '" + varName + "' in let expression"));
}
- Set<T> varValue = QueryUtil.evalAll(env, context, varExpr);
- VariableContext<T> bodyContext = VariableContext.with(context, varName, varValue);
- env.eval(bodyExpr, bodyContext, callback);
+ QueryTaskFuture<Set<T>> varValueFuture = QueryUtil.evalAll(env, context, varExpr);
+ Function<Set<T>, QueryTaskFuture<Void>> evalBodyAsyncFunction =
+ new Function<Set<T>, QueryTaskFuture<Void>>() {
+ @Override
+ public QueryTaskFuture<Void> apply(Set<T> varValue) {
+ VariableContext<T> bodyContext = VariableContext.with(context, varName, varValue);
+ return env.eval(bodyExpr, bodyContext, callback);
+ }
+ };
+ return env.transformAsync(varValueFuture, evalBodyAsyncFunction);
}
@Override