bazel syntax: delete unused BaseFunction.unconfiguredDefaultValues
PiperOrigin-RevId: 270967691
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
index 5f0fcdc..6866b97 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BaseFunction.java
@@ -82,22 +82,6 @@
// or those displayed to the user in the documentation.
@Nullable protected List<SkylarkType> enforcedArgumentTypes;
- // Defaults to be used when configure(annotation) is called (after the function is constructed).
- @Nullable private Iterable<Object> unconfiguredDefaultValues;
- // The configure(annotation) function will include these defaults in the function signature.
- // We need to supply these defaultValues to the constructor, that will store them here, because
- // they can't be supplied via Java annotations, due to the limitations in the annotation facility.
- // (For extra brownies, we could supply them as Skylark expression strings, to be evaluated by our
- // evaluator without the help of any unconfigured functions, or to be processed at compile-time;
- // but we resolve annotations at runtime for now.)
- // Limitations in Java annotations mean we can't express them in the SkylarkSignature annotation.
- // (In the future, we could parse and evaluate simple Skylark expression strings, but then
- // we'd have to be very careful of circularities during initialization).
- // Note that though we want this list to be immutable, we don't use ImmutableList,
- // because that can't store nulls and nulls are essential for some BuiltinFunction-s.
- // We trust the user not to modify the list behind our back.
-
-
/**
* Returns the name of this function.
*
@@ -124,7 +108,7 @@
}
/**
- * Creates an unconfigured BaseFunction with the given name.
+ * Creates an unconfigured (signature-less) BaseFunction with the given name.
*
* <p>The name must be null if called from a subclass constructor where the subclass overrides
* {@link #getName}; otherwise it must be non-null.
@@ -171,17 +155,6 @@
this(name, FunctionSignature.WithValues.create(signature), null);
}
- /**
- * Constructs a BaseFunction with a given name and list of unconfigured defaults.
- *
- * @param name the function name; null iff this is a subclass overriding {@link #getName}
- * @param defaultValues a list of default values for the optional arguments to be configured.
- */
- public BaseFunction(@Nullable String name, @Nullable Iterable<Object> defaultValues) {
- this(name);
- this.unconfiguredDefaultValues = defaultValues;
- }
-
/** Get parameter documentation as a list corresponding to each parameter */
public List<String> getParamDoc() {
return paramDoc;
@@ -489,8 +462,9 @@
Preconditions.checkState(!isConfigured()); // must not be configured yet
this.paramDoc = new ArrayList<>();
- this.signature = SkylarkSignatureProcessor.getSignatureForCallable(
- getName(), annotation, unconfiguredDefaultValues, paramDoc, getEnforcedArgumentTypes());
+ this.signature =
+ SkylarkSignatureProcessor.getSignatureForCallable(
+ getName(), annotation, paramDoc, getEnforcedArgumentTypes());
this.objectType = annotation.objectType().equals(Object.class)
? null : annotation.objectType();
configure();
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
index d8d87d5..8af2052 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/BuiltinFunction.java
@@ -74,16 +74,11 @@
// True if the function is a rule class
private boolean isRule;
- /** Create unconfigured function from its name */
+ /** Create unconfigured (signature-less) function from its name */
public BuiltinFunction(String name) {
super(name);
}
- /** Creates an unconfigured BuiltinFunction with the given name and defaultValues */
- public BuiltinFunction(String name, Iterable<Object> defaultValues) {
- super(name, defaultValues);
- }
-
/** Creates a BuiltinFunction with the given name and signature */
public BuiltinFunction(String name, FunctionSignature signature) {
super(name, signature);
@@ -356,11 +351,6 @@
super(name);
}
- /** Creates an unconfigured function Factory with the given name and defaultValues */
- public Factory(String name, Iterable<Object> defaultValues) {
- super(name, defaultValues);
- }
-
@Override
public void configure() {
if (createMethod != null) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
index 2989221..1d041c3 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/CallUtils.java
@@ -443,8 +443,7 @@
if (param.isDisabledInCurrentSemantics()) {
value =
- SkylarkSignatureProcessor.getDefaultValue(
- param.getName(), param.getValueOverride(), null);
+ SkylarkSignatureProcessor.getDefaultValue(param.getName(), param.getValueOverride());
builder.add(value);
continue;
}
@@ -484,8 +483,7 @@
throw unspecifiedParameterException(call, param, method, objClass, kwargs);
}
value =
- SkylarkSignatureProcessor.getDefaultValue(
- param.getName(), param.getDefaultValue(), null);
+ SkylarkSignatureProcessor.getDefaultValue(param.getName(), param.getDefaultValue());
}
}
if (!param.isNoneable() && value instanceof NoneType) {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
index 250625b..45b536c 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSignatureProcessor.java
@@ -22,7 +22,6 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -70,7 +69,6 @@
annotation.parameters(),
annotation.extraPositionals(),
annotation.extraKeywords(),
- /*defaultValues=*/ null,
paramDoc,
enforcedTypesList);
}
@@ -82,7 +80,6 @@
*
* @param name the name of the function
* @param annotation the annotation
- * @param defaultValues an optional list of default values
* @param paramDoc an optional list into which to store documentation strings
* @param enforcedTypesList an optional list into which to store effective types to enforce
*/
@@ -91,7 +88,6 @@
// TODO(bazel-team): use AutoValue to declare a value type to use as return value?
public static FunctionSignature.WithValues<Object, SkylarkType> getSignatureForCallable(
String name, SkylarkSignature annotation,
- @Nullable Iterable<Object> defaultValues,
@Nullable List<String> paramDoc, @Nullable List<SkylarkType> enforcedTypesList) {
Preconditions.checkArgument(name.equals(annotation.name()),
@@ -100,10 +96,14 @@
if (annotation.doc().isEmpty() && documented) {
throw new RuntimeException(String.format("function %s is undocumented", name));
}
- return getSignatureForCallable(name, documented,
+ return getSignatureForCallable(
+ name,
+ documented,
annotation.parameters(),
annotation.extraPositionals(),
- annotation.extraKeywords(), defaultValues, paramDoc, enforcedTypesList);
+ annotation.extraKeywords(),
+ paramDoc,
+ enforcedTypesList);
}
private static boolean isParamNamed(Param param) {
@@ -114,21 +114,17 @@
String name, boolean documented,
Param[] parameters,
@Nullable Param extraPositionals, @Nullable Param extraKeywords,
- @Nullable Iterable<Object> defaultValues,
@Nullable List<String> paramDoc, @Nullable List<SkylarkType> enforcedTypesList) {
ArrayList<Parameter<Object, SkylarkType>> paramList = new ArrayList<>();
HashMap<String, SkylarkType> enforcedTypes =
enforcedTypesList == null ? null : new HashMap<>();
HashMap<String, String> doc = new HashMap<>();
-
- Iterator<Object> defaultValuesIterator = defaultValues == null
- ? null : defaultValues.iterator();
try {
boolean named = false;
for (Param param : parameters) {
boolean mandatory = param.defaultValue() != null && param.defaultValue().isEmpty();
- Object defaultValue = mandatory ? null : getDefaultValue(param, defaultValuesIterator);
+ Object defaultValue = mandatory ? null : getDefaultValue(param);
if (isParamNamed(param) && !param.positional() && !named) {
named = true;
@Nullable Param starParam = null;
@@ -233,15 +229,12 @@
return new Parameter.Optional<>(Identifier.of(param.name()), officialType, defaultValue);
}
- static Object getDefaultValue(Param param, Iterator<Object> iterator) {
- return getDefaultValue(param.name(), param.defaultValue(), iterator);
+ static Object getDefaultValue(Param param) {
+ return getDefaultValue(param.name(), param.defaultValue());
}
- static Object getDefaultValue(
- String paramName, String paramDefaultValue, Iterator<Object> iterator) {
- if (iterator != null) {
- return iterator.next();
- } else if (paramDefaultValue.isEmpty()) {
+ static Object getDefaultValue(String paramName, String paramDefaultValue) {
+ if (paramDefaultValue.isEmpty()) {
return Runtime.NONE;
} else {
try {
@@ -333,7 +326,6 @@
}
Class<?> nameSpace = function.getObjectType();
if (nameSpace != null) {
- Preconditions.checkState(!(function instanceof BuiltinFunction.Factory));
builtins.registerFunction(nameSpace, function);
}
}