This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Fix DenseMapInfo<variant>::isEqual to delegate to DenseMapInfo, not ==
ClosedPublic

Authored by sammccall on May 26 2023, 6:00 AM.

Diff Detail

Event Timeline

sammccall created this revision.May 26 2023, 6:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 6:00 AM
sammccall requested review of this revision.May 26 2023, 6:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 6:00 AM
sammccall updated this revision to Diff 526037.May 26 2023, 6:02 AM

steal tests from D151079

sammccall planned changes to this revision.May 26 2023, 7:11 AM

sorry, sent this prematurely

IncludeGuardian requested changes to this revision.Jun 3 2023, 1:55 PM
IncludeGuardian added inline comments.
llvm/include/llvm/ADT/DenseMapInfo.h
328–330

I think we may be able to use std::visit twice and rely on the type of the parameter in the second visit matching the original type of the value we cast to const void *.

const void *ErasedLHSValue = std::visit([](const auto& LHSValue){
    return static_cast<const void *>(&LHSValue);
}, l);

return std::visit([=](const auto& RHSValue){
    using T = std::remove_reference_t<decltype(RHSValue)>;
    return DenseMapInfo<T>::isEqual(*static_cast<T *>(ErasedLHSValue), RHSValue);
}, r);
This revision now requires changes to proceed.Jun 3 2023, 1:55 PM
sammccall updated this revision to Diff 528374.Jun 5 2023, 4:27 AM

simplify isEqual by using two std::visit calls with generic lambdas

sammccall marked an inline comment as done.Jun 5 2023, 4:27 AM
sammccall added inline comments.
llvm/include/llvm/ADT/DenseMapInfo.h
328–330

Right! I always forget that auto-params in lambdas are good for something other than saving typing :-)

kadircet accepted this revision.Jun 6 2023, 7:51 AM

thanks!

This revision is now accepted and ready to land.Jun 6 2023, 9:22 AM
This revision was landed with ongoing or failed builds.Jun 6 2023, 9:37 AM
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.