Skip to content

Commit

Permalink
Remove ability to modify EnumType equality and hashing
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 586023733
  • Loading branch information
jcking authored and copybara-github committed Nov 28, 2023
1 parent d65ec54 commit 0d158a3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 27 deletions.
4 changes: 0 additions & 4 deletions common/types/enum_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@ class BasicEnumType final : public EnumTypeInterface {
private:
friend class BasicEnumTypeValueIterator;

bool Equals(const EnumTypeInterface&) const override { return true; }

void HashValue(absl::HashState) const override {}

absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
absl::string_view name) const override {
if (auto it = values_by_name_.find(name); it != values_by_name_.end()) {
Expand Down
23 changes: 4 additions & 19 deletions common/types/enum_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include "absl/base/attributes.h"
#include "absl/base/nullability.h"
#include "absl/hash/hash.h"
#include "absl/log/absl_check.h"
#include "absl/meta/type_traits.h"
#include "absl/status/statusor.h"
Expand Down Expand Up @@ -160,16 +159,6 @@ class EnumTypeInterface : public TypeInterface,
private:
friend class EnumType;
friend class EnumTypeView;
friend bool operator==(const EnumType& lhs, const EnumType& rhs);
template <typename H>
friend H AbslHashValue(H state, const EnumType& type);
friend bool operator==(EnumTypeView lhs, EnumTypeView rhs);
template <typename H>
friend H AbslHashValue(H state, EnumTypeView type);

virtual bool Equals(const EnumTypeInterface& other) const = 0;

virtual void HashValue(absl::HashState state) const = 0;

virtual absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
absl::string_view name) const ABSL_ATTRIBUTE_LIFETIME_BOUND = 0;
Expand Down Expand Up @@ -248,14 +237,12 @@ class EnumType {
}

friend bool operator==(const EnumType& lhs, const EnumType& rhs) {
return lhs.name() == rhs.name() && lhs.interface_->Equals(*rhs.interface_);
return lhs.name() == rhs.name();
}

template <typename H>
friend H AbslHashValue(H state, const EnumType& type) {
state = H::combine(std::move(state), type.kind(), type.name());
type.interface_->HashValue(absl::HashState::Create(&state));
return std::move(state);
return H::combine(std::move(state), type.kind(), type.name());
}

private:
Expand Down Expand Up @@ -453,14 +440,12 @@ class EnumTypeView {
}

friend bool operator==(EnumTypeView lhs, EnumTypeView rhs) {
return lhs.name() == rhs.name() && lhs.interface_->Equals(*rhs.interface_);
return lhs.name() == rhs.name();
}

template <typename H>
friend H AbslHashValue(H state, EnumTypeView type) {
state = H::combine(std::move(state), type.kind(), type.name());
type.interface_->HashValue(absl::HashState::Create(&state));
return std::move(state);
return H::combine(std::move(state), type.kind(), type.name());
}

private:
Expand Down
4 changes: 0 additions & 4 deletions common/types/enum_type_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ class CustomEnumTypeInterface final
private:
friend class CustomEnumTypeValueIterator;

bool Equals(const EnumTypeInterface&) const override { return true; }

void HashValue(absl::HashState) const override {}

absl::StatusOr<absl::optional<EnumTypeValueId>> FindIdByName(
absl::string_view name) const override {
if (name == "FOO") {
Expand Down

0 comments on commit 0d158a3

Please # to comment.