This is an archive of the discontinued LLVM Phabricator instance.

[clangd][StdSymbolMap] Prefer std::remove from algorithm
ClosedPublic

Authored by kadircet on Nov 29 2021, 10:22 AM.

Details

Summary

std::remove from algorithm is a lot more common than the overload from
the cstdio (which deletes files). This patch introduces a set of symbols
for which we should prefer the overloaded versions.

Diff Detail

Event Timeline

kadircet created this revision.Nov 29 2021, 10:22 AM
kadircet requested review of this revision.Nov 29 2021, 10:22 AM
sammccall added inline comments.Nov 29 2021, 1:58 PM
clang-tools-extra/clangd/StdSymbolMap.inc
958

Is the stdio version so uncommon we are willing to be wrong about it? For move we omit it from here and consider it case-by-case, I'd have imagined doing the same here

(BTW at some point we may want to extend this to list alternative headers for ambiguous symbols)

clang-tools-extra/clangd/include-mapping/cppreference_parser.py
140–142

This logic seems a bit weird and non-general: it allows us to accept any variant and reject any non-variant, but it doesn't allow us to accept a*specific* variant (they are named) and doesn't allow us to accept both (which currently would lead to the symbol being dropped as ambiguous).

kadircet added inline comments.Nov 30 2021, 2:38 AM
clang-tools-extra/clangd/StdSymbolMap.inc
958

Is the stdio version so uncommon we are willing to be wrong about it?

Waiting for permissions on a big codebase with lots of third_party code to perform some analysis.

For move we omit it from here and consider it case-by-case, I'd have imagined doing the same here

std::move is different, both occurrences are marked as variants. We don't really drop it during post-processing saying there are multiple options, it just never makes it to the final list.

move<>() (algorithm) (since C++11)
move<>() (utility) (since C++11)

I am not sure how we ended up with this ignore the varianted symbols behavior.

(BTW at some point we may want to extend this to list alternative headers for ambiguous symbols)

I agree, there is some room for improvement, like also listing different overloads with expected number of parameters and language versions.
It's unclear whether we need such detail today though.

clang-tools-extra/clangd/include-mapping/cppreference_parser.py
140–142

I was trying to keep the change to a minimum. Happy to go with a solution that accepts a dictionary in the form of (FQN, list_of_accepted_variants), where the list can have "" variant, or instead of a list we can also have a glob, but I don't think it'll provide much value considering the irregularity of std header names.

1658removeNULL
1731std::__u::removellvm/include/c++/v1/__algorithm/remove.h

for whatever reason I remembered the std::remove to have been referenced ~17k. looks like these two are much closer. I don't think it makes sense to prefer one or the other here.

I suggest moving forward with a mechanism that enables accepting certain variants and accepting both unnamed and algorithm variants for std::remove, hence it being rejected as an ambiguous symbol in the end. That way we won't have a special case to handle once we start including multiple options for a symbol.
WDYT?

for whatever reason I remembered the std::remove to have been referenced ~17k. looks like these two are much closer. I don't think it makes sense to prefer one or the other here.

Agree, for StdSymbolMap.inc this means neither version of remove should be there.

I suggest moving forward with a mechanism that enables accepting certain variants and accepting both unnamed and algorithm variants for std::remove, hence it being rejected as an ambiguous symbol in the end. That way we won't have a special case to handle once we start including multiple options for a symbol.
WDYT?

In practice we don't actually need the ability to accept specific variants, just variants in general.
(Maybe we'll need it later, but maybe not.)

clang-tools-extra/clangd/CSymbolMap.inc
701 ↗(On Diff #390405)

hmm, I would expect this to still be in CSymbolMap, it's not ambiguous there.

clang-tools-extra/clangd/include-mapping/cppreference_parser.py
140–142

I'd just change this to variant or (ns + name in variants to accept)

That way we accept both versions of move, and end up dropping it as ambiguous.

168

we should have a comment on the symbol

  1. std::remove<> template has variant "algorithm"
kadircet updated this revision to Diff 399300.Jan 12 2022, 5:42 AM
kadircet marked 5 inline comments as done.
  • Change the variant acception mechanism to work with specific variants.
sammccall accepted this revision.Jan 12 2022, 5:58 AM
This revision is now accepted and ready to land.Jan 12 2022, 5:58 AM
This revision was automatically updated to reflect the committed changes.