Skip to content

Commit

Permalink
Automated rollback of commit af7fc3b.
Browse files Browse the repository at this point in the history
*** 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
  • Loading branch information
haxorz authored and copybara-github committed Aug 2, 2019
1 parent 7ed66f7 commit aaff22c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.annotation.Nullable;

/**
Expand Down Expand Up @@ -574,6 +575,23 @@ protected String printTypeString(Object[] args, int howManyArgsToPrint) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,10 @@ protected Object call(Object[] args, @Nullable FuncallExpression ast, Environmen

@Override
public void repr(SkylarkPrinter printer) {}

@Override
public boolean equals(@Nullable Object other) {
// Use exact object matching.
return this == other;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -243,6 +244,12 @@ private static class RuleDefinitionIdentifier extends BaseFunction {
public RuleDefinitionIdentifier() {
super("RuleDefinitionIdentifier" + idCounter++);
}

@Override
public boolean equals(@Nullable Object other) {
// Use exact object matching.
return this == other;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down Expand Up @@ -95,5 +96,11 @@ private static class RepositoryRuleDefinitionIdentifier extends BaseFunction {
public RepositoryRuleDefinitionIdentifier() {
super("RepositoryRuleDefinitionIdentifier" + idCounter++);
}

@Override
public boolean equals(@Nullable Object other) {
// Use exact object matching.
return this == other;
}
}
}

0 comments on commit aaff22c

Please sign in to comment.