This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Change ObjectValueDictionary to use a StringMap
ClosedPublic

Authored by bulbazord on Apr 28 2023, 1:37 PM.

Details

Summary

llvm has a structure for maps where the key's type is a string. Using
that also means that the keys for OptionValueDictionary don't stick
around forever in ConstString's StringPool (even after they are gone).

The only thing we lose here is ordering: iterating over the map where the keys
are ConstStrings guarantees that we iterate in alphabetical order.
StringMap makes no guarantees about the ordering when you iterate over
the entire map.

Diff Detail

Event Timeline

bulbazord created this revision.Apr 28 2023, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 1:37 PM
bulbazord requested review of this revision.Apr 28 2023, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 28 2023, 1:37 PM

No reason for these strings to be in the ConstString pool, so that part is fine.

But if we're going to use this to store things like the env-vars, having no ordering guarantees when we dump them seems likely to be a bit annoying. If the order of element output in settings show env-vars dump changes around every time I add an element to it, that would be make the results hard to follow. Can we make the dumper for this option value pull the keys out, alphabetize the keys, then look the values up in that order? I don't think printing these objects is ever going to be performance critical.

lldb/source/Core/Disassembler.cpp
845

That's kind of answering a question with a question: Why isn't there an eTypeUInt32?

lldb/source/Interpreter/OptionValueDictionary.cpp
38–39

Does the llvm::StringMap dingus not support for (auto value : m_values) { ?

bulbazord added inline comments.Apr 28 2023, 4:12 PM
lldb/source/Core/Disassembler.cpp
845

I'm not sure, we'd have to ask Caroline who added this back in 2011. I added a comment to help me remember, but I suppose this comment may add more confusion than remove. I'll remove the note.

lldb/source/Interpreter/OptionValueDictionary.cpp
38–39

Oh, it probably does. Didn't even think about it, good catch.

+1 on making the output deterministic with a sort

This revision was not accepted when it landed; it landed in state Needs Review.Apr 28 2023, 6:13 PM
This revision was automatically updated to reflect the committed changes.

I think something went wrong here. This was a patch for OptionValueDictionary, but it seems to have become a patch for OpenInExternalEditor?

JDevlieghere reopened this revision.EditedApr 28 2023, 8:56 PM

That's my bad: I put the wrong differential URL in my commit (13dbc16b4d82b9adc98c0919873b2b59ccc46afd). The correct differential revision for this was https://reviews.llvm.org/D149472. Sorry Alex!

bulbazord updated this revision to Diff 518542.May 1 2023, 1:05 PM

Sort output for dumping to be deterministic (based on alphabetical order like previous implementation)

JDevlieghere accepted this revision.May 1 2023, 2:05 PM

LGTM

lldb/source/Core/Disassembler.cpp
804–805

I don't think you need this: key is a std::string that can be used directly.

This revision is now accepted and ready to land.May 1 2023, 2:05 PM
bulbazord updated this revision to Diff 518569.May 1 2023, 2:38 PM

Remove unneeded StringRef

This revision was automatically updated to reflect the committed changes.