This is an archive of the discontinued LLVM Phabricator instance.

[llvm][ADT] Change isEqual for DenseMapInfo<std::variant<...>>
AbandonedPublic

Authored by kadircet on May 22 2023, 4:39 AM.

Details

Reviewers
IncludeGuardian
Summary

Defer to DenseMapInfo<T>::isEqual instead of operator==(T,T).

Diff Detail

Event Timeline

kadircet created this revision.May 22 2023, 4:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 4:39 AM
kadircet requested review of this revision.May 22 2023, 4:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 4:39 AM
llvm/unittests/ADT/DenseMapTest.cpp
755–756

It is worth testing a type were isEqual and operator== disagree? The tombstone and empty keys in StringRef would be an example where they don't work with operator== https://github.com/llvm/llvm-project/blob/a68bbf42fa680c7159165be8915d73e012c50f96/llvm/include/llvm/ADT/StringRef.h#L911-L931

kadircet marked an inline comment as done.May 23 2023, 7:53 AM
kadircet added inline comments.
llvm/unittests/ADT/DenseMapTest.cpp
755–756

i'd rather not depend on the implementation details for DenseMapInfo<StringRef>, added a custom type into the test instead.

kadircet updated this revision to Diff 524719.May 23 2023, 7:53 AM
kadircet marked an inline comment as done.
  • Add a test case for a type with different operator== and isEqual.
kadircet updated this revision to Diff 524720.May 23 2023, 7:54 AM
  • formatting
IncludeGuardian requested changes to this revision.Jun 3 2023, 2:06 PM
IncludeGuardian added inline comments.
llvm/include/llvm/ADT/DenseMapInfo.h
326–329

As this will be instantiated for each combination of types in our variant, I think the approach taken in https://reviews.llvm.org/D151079 is slightly better for compilation speed, although it is not as simple as this.

I would love to suggest C-style variadic functions to avoid any template instantiation, i.e.

bool operator()(...) const {
  return false;
}

but I don't think the behavior is guaranteed for non-POD user-defined types and some compilers will create a copy.

This revision now requires changes to proceed.Jun 3 2023, 2:06 PM
kadircet abandoned this revision.Jun 5 2023, 11:59 PM
kadircet added a subscriber: sammccall.
kadircet added inline comments.
llvm/include/llvm/ADT/DenseMapInfo.h
326–329

yes that was my concern as well, hence we had an offline discussion with @sammccall and he was kind enough to come up with go/phab/D151557. so i'll abandon this patch in favor of it.