This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Disambiguate overloads of std::move for header insertion.
ClosedPublic

Authored by sammccall on Oct 6 2020, 4:08 AM.

Details

Summary

Up until now, we relied on matching the filename.
This depends on unstable details of libstdc++ and doesn't work well on other
stdlibs. Also we'd like to remove it (see D88204).

Diff Detail

Event Timeline

sammccall created this revision.Oct 6 2020, 4:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2020, 4:08 AM
sammccall requested review of this revision.Oct 6 2020, 4:08 AM
kadircet added inline comments.Oct 6 2020, 5:46 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
561

i think this should live inside CanonicalIncludes. What about changing mapHeader to take in an llvm::Optional<size_t> NumParams or llvm::Optional<llvm::StringRef> Signature ?

That way we can actually get rid of the ambiguity caused by all of the overloads. I am not sure if number of parameters is always going to be enough tho so Signature might be a safer bet with some canonicalization so that we can match the version in cppreference.

(I would prefer the solution above, but I am also fine with moving this into SymbolCollector::getIncludeHeader with a FIXME.)

sammccall added inline comments.Oct 6 2020, 6:33 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
561

That's kind of the point of this patch, I think this one special case isn't worth making that library more complicated.

Would also be happy with just always suggesting <utility>, or never suggesting anything, though.

kadircet accepted this revision.Oct 6 2020, 8:41 AM

Thanks, LGTM! As you mentioned I believe std::move is common enough to deserve the special casing.

clang-tools-extra/clangd/index/SymbolCollector.cpp
561

Makes sense, I was suggesting SymbolCollector::getIncludeHeader rather than SymbolCollector::finish to keep the logic in here less complicated. But I am fine if you don't want to make changes to the singature. (It is unfortunate that getIncludeHeader is a private member instead of a free helper in here anyways.)

This revision is now accepted and ready to land.Oct 6 2020, 8:41 AM
sammccall marked an inline comment as done.Oct 7 2020, 10:36 AM

Thanks, LGTM! As you mentioned I believe std::move is common enough to deserve the special casing.

Common enough and also literally the only case AFAIK (hopefully the committee is friendly enough not to add more in future).
That combination pushes me towards preferring this hack at least for now...

clang-tools-extra/clangd/index/SymbolCollector.cpp
561

Oh right, of course. Done.

Yeah it's unfortunate, it's because isSelfContainedHeader is an expensive check that we have to cache, so there's a bunch of state it needs access to.

sammccall updated this revision to Diff 296734.Oct 7 2020, 10:36 AM
sammccall marked an inline comment as done.

Refactor the hack into a more appropriate place.

kadircet added inline comments.Oct 7 2020, 10:42 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
557

this one is no longer needed.

This revision was landed with ongoing or failed builds.Oct 7 2020, 10:42 AM
This revision was automatically updated to reflect the committed changes.
sammccall added inline comments.Oct 9 2020, 1:27 AM
clang-tools-extra/clangd/index/SymbolCollector.cpp
557