bazel syntax: remove Location parameters
Remove Location parameter from SkylarkIndexable.getIndex
(and thread parameter from SkylarkQueryable).
Also, make SkylarkIndexable and SkylarkQueryable
consistently take a StarlarkSemantics.
Eval: don't pass Locations down into evaluation;
obtain them only after an error, on the way up.
(This is a prerequisite for compilation, and for
finer-grained syntax locations. This CL addresses only
the easy cases.)
Also:
- Dict.get2: avoid duplicate hash lookup in success case.
- EvalUtils.index: pass mutability and semantics, not thread
- remove unnecessary parameters to binary operators.
- improvements to error messages
PiperOrigin-RevId: 289523719
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupInfo.java b/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupInfo.java
index c226c3a..a8c31f7 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/OutputGroupInfo.java
@@ -35,9 +35,10 @@
import com.google.devtools.build.lib.syntax.Depset;
import com.google.devtools.build.lib.syntax.Dict;
import com.google.devtools.build.lib.syntax.EvalException;
-import com.google.devtools.build.lib.syntax.EvalUtils;
import com.google.devtools.build.lib.syntax.SkylarkIndexable;
+import com.google.devtools.build.lib.syntax.Starlark;
import com.google.devtools.build.lib.syntax.StarlarkIterable;
+import com.google.devtools.build.lib.syntax.StarlarkSemantics;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -240,25 +241,22 @@
}
@Override
- public Object getIndex(Object key, Location loc) throws EvalException {
+ public Object getIndex(StarlarkSemantics semantics, Object key) throws EvalException {
if (!(key instanceof String)) {
- throw new EvalException(loc, String.format(
- "Output grout names must be strings, got %s instead",
- EvalUtils.getDataTypeName(key)));
+ throw Starlark.errorf(
+ "Output group names must be strings, got %s instead", Starlark.type(key));
}
NestedSet<Artifact> result = outputGroups.get(key);
if (result != null) {
return Depset.of(Artifact.TYPE, result);
} else {
- throw new EvalException(loc, String.format(
- "Output group %s not present", key
- ));
+ throw Starlark.errorf("Output group %s not present", key);
}
}
@Override
- public boolean containsKey(Object key, Location loc) throws EvalException {
+ public boolean containsKey(StarlarkSemantics semantics, Object key) throws EvalException {
return outputGroups.containsKey(key);
}