Remove throwing of InterruptedException from LabelVisitor. We never actually have any interruptible methods here.
PiperOrigin-RevId: 214648875
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
index 747bfd5..09b5173 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/constraints/ConstraintSemantics.java
@@ -923,20 +923,9 @@
*/
private static void addSelectValuesToSet(BuildType.Selector<?> select, final Set<Label> set) {
Type<?> type = select.getOriginalType();
- LabelVisitor<?> visitor = new LabelVisitor<Object>() {
- @Override
- public void visit(Label label, Object dummy) {
- set.add(label);
- }
- };
+ LabelVisitor<?> visitor = (label, dummy) -> set.add(label);
for (Object value : select.getEntries().values()) {
- try {
- type.visitLabels(visitor, value, /*context=*/ null);
- } catch (InterruptedException ex) {
- // Because the LabelVisitor does not throw InterruptedException, it should not be thrown
- // by visitLabels here.
- throw new AssertionError(ex);
- }
+ type.visitLabels(visitor, value, /*context=*/ null);
}
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
index 384ce09..8630b9a 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AbstractAttributeMapper.java
@@ -165,7 +165,7 @@
}
@Override
- public Collection<DepEdge> visitLabels() throws InterruptedException {
+ public Collection<DepEdge> visitLabels() {
List<DepEdge> edges = new ArrayList<>();
Type.LabelVisitor<Attribute> visitor =
(label, attribute) -> {
@@ -187,8 +187,7 @@
}
/** Visits all labels reachable from the given attribute. */
- protected void visitLabels(Attribute attribute, Type.LabelVisitor<Attribute> visitor)
- throws InterruptedException {
+ protected void visitLabels(Attribute attribute, Type.LabelVisitor<Attribute> visitor) {
Type<?> type = attribute.getType();
Object value = get(attribute.getName(), type);
if (value != null) { // null values are particularly possible for computed defaults.
@@ -199,7 +198,7 @@
@Override
public final boolean isConfigurable(String attributeName) {
Attribute attrDef = getAttributeDefinition(attributeName);
- return attrDef == null ? false : getSelectorList(attributeName, attrDef.getType()) != null;
+ return attrDef != null && getSelectorList(attributeName, attrDef.getType()) != null;
}
public static <T> boolean isConfigurable(Rule rule, String attributeName, Type<T> type) {
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
index 75d3e0e..6604d4d 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AggregatingAttributeMapper.java
@@ -26,7 +26,6 @@
import com.google.devtools.build.lib.packages.BuildType.Selector;
import com.google.devtools.build.lib.packages.BuildType.SelectorList;
import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.syntax.Type.LabelVisitor;
import com.google.devtools.build.lib.syntax.Type.ListType;
import java.util.ArrayList;
import java.util.Collection;
@@ -72,14 +71,12 @@
* {@link #visitAttribute}'s documentation. So we want to avoid that code path when possible.
*/
@Override
- protected void visitLabels(Attribute attribute, Type.LabelVisitor<Attribute> visitor)
- throws InterruptedException {
+ protected void visitLabels(Attribute attribute, Type.LabelVisitor<Attribute> visitor) {
visitLabels(attribute, true, visitor);
}
private void visitLabels(
- Attribute attribute, boolean includeSelectKeys, Type.LabelVisitor<Attribute> visitor)
- throws InterruptedException {
+ Attribute attribute, boolean includeSelectKeys, Type.LabelVisitor<Attribute> visitor) {
Type<?> type = attribute.getType();
SelectorList<?> selectorList = getSelectorList(attribute.getName(), type);
if (selectorList == null) {
@@ -117,18 +114,12 @@
*
* @param includeSelectKeys whether to include config_setting keys for configurable attributes
*/
- public Set<Label> getReachableLabels(String attributeName, boolean includeSelectKeys)
- throws InterruptedException {
+ public Set<Label> getReachableLabels(String attributeName, boolean includeSelectKeys) {
final ImmutableSet.Builder<Label> builder = ImmutableSet.<Label>builder();
visitLabels(
getAttributeDefinition(attributeName),
includeSelectKeys,
- new LabelVisitor<Attribute>() {
- @Override
- public void visit(Label label, Attribute attribute) {
- builder.add(label);
- }
- });
+ (label, attribute) -> builder.add(label));
return builder.build();
}
@@ -581,22 +572,15 @@
}
private static ImmutableList<Label> extractLabels(Type<?> type, Object value) {
- try {
- final ImmutableList.Builder<Label> result = ImmutableList.builder();
- type.visitLabels(
- new Type.LabelVisitor<Object>() {
- @Override
- public void visit(@Nullable Label label, Object dummy) {
- if (label != null) {
- result.add(label);
- }
- }
- },
- value,
- /*context=*/ null);
- return result.build();
- } catch (InterruptedException e) {
- throw new IllegalStateException("Unexpected InterruptedException", e);
- }
+ final ImmutableList.Builder<Label> result = ImmutableList.builder();
+ type.visitLabels(
+ (label, dummy) -> {
+ if (label != null) {
+ result.add(label);
+ }
+ },
+ value,
+ /*context=*/ null);
+ return result.build();
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
index c299e64..937d19f 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/AspectDefinition.java
@@ -224,16 +224,14 @@
final Multimap<Attribute, Label> labelBuilder,
Aspect aspect,
DependencyFilter dependencyFilter) {
- LabelVisitor<Attribute> labelVisitor = new LabelVisitor<Attribute>() {
- @Override
- public void visit(Label label, Attribute aspectAttribute) {
- Label repositoryRelative = maybeGetRepositoryRelativeLabel(from, label);
- if (repositoryRelative == null) {
- return;
- }
- labelBuilder.put(aspectAttribute, repositoryRelative);
- }
- };
+ LabelVisitor<Attribute> labelVisitor =
+ (label, aspectAttribute) -> {
+ Label repositoryRelative = maybeGetRepositoryRelativeLabel(from, label);
+ if (repositoryRelative == null) {
+ return;
+ }
+ labelBuilder.put(aspectAttribute, repositoryRelative);
+ };
ImmutableMap<String, Attribute> attributes = aspect.getDefinition().getAttributes();
for (final Attribute aspectAttribute : attributes.values()) {
if (!dependencyFilter.apply(aspect, aspectAttribute)) {
@@ -243,13 +241,7 @@
if (type.getLabelClass() != LabelClass.DEPENDENCY) {
continue;
}
- try {
- type.visitLabels(labelVisitor, aspectAttribute.getDefaultValue(from), aspectAttribute);
- } catch (InterruptedException ex) {
- // Because the LabelVisitor does not throw InterruptedException, it should not be thrown
- // by visitLabels here.
- throw new AssertionError(ex);
- }
+ type.visitLabels(labelVisitor, aspectAttribute.getDefaultValue(from), aspectAttribute);
}
}
diff --git a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
index 1e48835..5bb365d 100644
--- a/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
+++ b/src/main/java/com/google/devtools/build/lib/packages/BuildType.java
@@ -189,8 +189,7 @@
}
@Override
- public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context)
- throws InterruptedException {
+ public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
for (Label label : cast(value).getLabels()) {
visitor.visit(label, context);
}
@@ -240,8 +239,7 @@
}
@Override
- public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context)
- throws InterruptedException {
+ public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
visitor.visit(cast(value), context);
}
@@ -443,8 +441,7 @@
}
@Override
- public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context)
- throws InterruptedException {
+ public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
visitor.visit(cast(value), context);
}
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Type.java b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
index 62336d1..da3a85d 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Type.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Type.java
@@ -129,21 +129,20 @@
* {@link #visitLabels}.
*/
public interface LabelVisitor<C> {
- void visit(@Nullable Label label, @Nullable C context) throws InterruptedException;
+ void visit(@Nullable Label label, @Nullable C context);
}
/**
* Invokes {@code visitor.visit(label, context)} for each {@link Label} {@code label} associated
* with {@code value}, which is assumed an instance of this {@link Type}.
*
- * <p>This is used to support reliable label visitation in
- * {@link com.google.devtools.build.lib.packages.AbstractAttributeMapper#visitLabels}. To preserve
- * that reliability, every type should faithfully define its own instance of this method. In other
+ * <p>This is used to support reliable label visitation in {@link
+ * com.google.devtools.build.lib.packages.AbstractAttributeMapper#visitLabels}. To preserve that
+ * reliability, every type should faithfully define its own instance of this method. In other
* words, be careful about defining default instances in base types that get auto-inherited by
* their children. Keep all definitions as explicit as possible.
*/
- public abstract <C> void visitLabels(LabelVisitor<C> visitor, Object value, @Nullable C context)
- throws InterruptedException;
+ public abstract <C> void visitLabels(LabelVisitor<C> visitor, Object value, @Nullable C context);
/** Classifications of labels by their usage. */
public enum LabelClass {
@@ -437,8 +436,7 @@
private final LabelClass labelClass;
@Override
- public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context)
- throws InterruptedException {
+ public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
for (Map.Entry<KeyT, ValueT> entry : cast(value).entrySet()) {
keyType.visitLabels(visitor, entry.getKey(), context);
valueType.visitLabels(visitor, entry.getValue(), context);
@@ -552,8 +550,7 @@
}
@Override
- public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context)
- throws InterruptedException {
+ public <T> void visitLabels(LabelVisitor<T> visitor, Object value, T context) {
List<ElemT> elems = cast(value);
// Hot code path. Optimize for lists with O(1) access to avoid iterator garbage.
if (elems instanceof ImmutableList || elems instanceof ArrayList) {