This is an archive of the discontinued LLVM Phabricator instance.

[StringView] remove dropFront
ClosedPublic

Authored by nickdesaulniers on Apr 14 2023, 9:17 AM.

Details

Summary

Towards converting our use of llvm::StringView to std::string_view,
remove a method that std::string_view doesn't have.
llvm::StringView::dropFront is semantically similar to
std::string_view::substr but with the input clamped to the size. No code
was relying on clamping other than the rust demangler, which I fixed in
https://reviews.llvm.org/D148272. Removing this method makes it easier
to switch over code later.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 9:17 AM
nickdesaulniers requested review of this revision.Apr 14 2023, 9:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2023, 9:17 AM
llvm/include/llvm/Demangle/ItaniumDemangle.h
1587

anywhere we assign the result back to the string view object we should probably use StringView::remove_prefix instead.

llvm/include/llvm/Demangle/ItaniumDemangle.h
1587

Nevermind; there is no StringView::remove_prefix. These can be changed to std::string_view::remove_prefix after conversion.

MaskRay added inline comments.Apr 14 2023, 9:39 AM
llvm/include/llvm/Demangle/ItaniumDemangle.h
1586

The second assert is made redundant by assert(SV.startsWith("basic_"));

2269

The assert is unnecessary. Integer[0] expresses the intention.

2289–2290

The assert is unnecessary. Value[0] expresses the intention.

nickdesaulniers marked 3 inline comments as done.
  • remove redundant asserts

So I think most of your asserts are actually unnecessary. I only made it about 1/2 way down, but dont see any that are obviously necessary.

llvm/include/llvm/Demangle/ItaniumDemangle.h
1841

I think this assert is actually ALSO unnecessary, we already know that we're not in Offset.empty, line 1837 (and even if we weren't, line 1839 would probably be UB?).

2634

See above assert that checks startsWith, so also probably unnecessary.

3708

This assert is also redundant.

llvm/lib/Demangle/MicrosoftDemangle.cpp
172

index of zero above these makes this assert 'too late', since it would already be UB.

489

startswith above this.

nickdesaulniers marked 5 inline comments as done.
nickdesaulniers edited the summary of this revision. (Show Details)
llvm/include/llvm/Demangle/StringView.h
66–70
nickdesaulniers planned changes to this revision.Apr 14 2023, 10:05 AM
nickdesaulniers added inline comments.
llvm/include/llvm/Demangle/ItaniumDemangle.h
1587
MaskRay accepted this revision.Apr 14 2023, 10:22 AM

Thanks!

This revision is now accepted and ready to land.Apr 14 2023, 10:22 AM
This revision was landed with ongoing or failed builds.Apr 14 2023, 10:27 AM
This revision was automatically updated to reflect the committed changes.