Re-implement variables in the blaze query language. Instead of using a mutable global context of variable bindings, pass around immutable local contexts.
The motivation is so we can safely evaluate all blaze query expressions concurrently under the hood. A global context is hostile to this goal.
--
MOS_MIGRATED_REVID=127324600
diff --git a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
index 0292f08..07df0c6 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/AbstractBlazeQueryEnvironment.java
@@ -31,13 +31,12 @@
import com.google.devtools.build.lib.query2.engine.QueryException;
import com.google.devtools.build.lib.query2.engine.QueryExpression;
import com.google.devtools.build.lib.query2.engine.QueryUtil.AggregateAllCallback;
+import com.google.devtools.build.lib.query2.engine.VariableContext;
import com.google.devtools.build.lib.util.Preconditions;
import java.util.Collection;
-import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Logger;
@@ -49,7 +48,6 @@
public abstract class AbstractBlazeQueryEnvironment<T>
implements QueryEnvironment<T>, AutoCloseable {
protected final ErrorSensingEventHandler eventHandler;
- private final Map<String, Set<T>> letBindings = new HashMap<>();
protected final boolean keepGoing;
protected final boolean strictScope;
@@ -117,7 +115,7 @@
throw new QueryException(expr, e.getMessage());
}
try {
- this.eval(expr, new Callback<T>() {
+ this.eval(expr, VariableContext.<T>empty(), new Callback<T>() {
@Override
public void process(Iterable<T> partialResult)
throws QueryException, InterruptedException {
@@ -169,16 +167,6 @@
public abstract Target getTarget(Label label) throws TargetNotFoundException, QueryException;
- @Override
- public Set<T> getVariable(String name) {
- return letBindings.get(name);
- }
-
- @Override
- public Set<T> setVariable(String name, Set<T> value) {
- return letBindings.put(name, value);
- }
-
protected boolean validateScope(Label label, boolean strict) throws QueryException {
if (!labelFilter.apply(label)) {
String error = String.format("target '%s' is not within the scope of the query", label);