Automated rollback of commit af7fc3b75a62edc3b4b62de25b733b03c3ff925e.
*** Reason for rollback ***
See http://b/138789815#comment1 for motivation and plan.
*** Original change description ***
BaseFunction: don't define equality
The fact that two functions are defined in the same location does not imply
that they are equal; they still might depend on unequal values imported
from somewhere else. In particular, the starlark semantics nowadays changes
the way labels are interpreted (due to renaming).
Fixes #8937.
PiperOrigin-RevId: 261364168
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 0d3c49a..8904f9d 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
@@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.annotation.Nullable;
/**
@@ -574,6 +575,23 @@
return builder.toString();
}
+ @Override
+ public boolean equals(@Nullable Object other) {
+ if (other instanceof BaseFunction) {
+ BaseFunction that = (BaseFunction) other;
+ // In theory, the location alone unambiguously identifies a given function. However, in
+ // some test cases the location might not have a valid value, thus we also check the name.
+ return Objects.equals(this.getName(), that.getName())
+ && Objects.equals(this.location, that.location);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(getName(), location);
+ }
+
@Nullable
public Location getLocation() {
return location;
diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeProviderApi.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeProviderApi.java
index 5b07317..645f96e 100644
--- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeProviderApi.java
+++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeProviderApi.java
@@ -47,4 +47,10 @@
@Override
public void repr(SkylarkPrinter printer) {}
+
+ @Override
+ public boolean equals(@Nullable Object other) {
+ // Use exact object matching.
+ return this == other;
+ }
}
diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
index 32a5b56..c30ab1e 100644
--- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
+++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/FakeSkylarkRuleFunctionsApi.java
@@ -47,6 +47,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
/**
* Fake implementation of {@link SkylarkRuleFunctionsApi}.
@@ -243,6 +244,12 @@
public RuleDefinitionIdentifier() {
super("RuleDefinitionIdentifier" + idCounter++);
}
+
+ @Override
+ public boolean equals(@Nullable Object other) {
+ // Use exact object matching.
+ return this == other;
+ }
}
/**
diff --git a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/repository/FakeRepositoryModule.java b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/repository/FakeRepositoryModule.java
index 30bb834..7c1ab1c 100644
--- a/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/repository/FakeRepositoryModule.java
+++ b/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/repository/FakeRepositoryModule.java
@@ -31,6 +31,7 @@
import com.google.devtools.build.skydoc.rendering.proto.StardocOutputProtos.RuleInfo;
import java.util.List;
import java.util.stream.Collectors;
+import javax.annotation.Nullable;
/**
* Fake implementation of {@link RepositoryModuleApi}.
@@ -95,5 +96,11 @@
public RepositoryRuleDefinitionIdentifier() {
super("RepositoryRuleDefinitionIdentifier" + idCounter++);
}
+
+ @Override
+ public boolean equals(@Nullable Object other) {
+ // Use exact object matching.
+ return this == other;
+ }
}
}