This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Support include canonicalization in symbol leve.
ClosedPublic

Authored by ioeric on Feb 28 2018, 5:15 AM.

Details

Summary

Symbols with different canonical includes might be defined in the same header
(e.g. symbols defined in STL <iosfwd>). This patch adds support for mapping from
qualified symbol names to canonical headers and special mapping for symbols in <iosfwd>

Diff Detail

Event Timeline

ioeric created this revision.Feb 28 2018, 5:15 AM
hokein added inline comments.Mar 1 2018, 1:52 AM
clangd/index/CanonicalIncludes.cpp
83

Looks like the list only contains stream-related symbols, there are some symbols in <iosfwd> not covered, is it intended?

Maybe we keep the order of this map the same as the one listed in http://en.cppreference.com/w/cpp/header/iosfwd? That would make it easier to see the difference?

unittests/clangd/SymbolCollectorTests.cpp
561

The STL implementation of ios is a typedef typedef basic_ios<char> ios; , I think we should make the test align with it?

ioeric added inline comments.Mar 1 2018, 2:03 AM
clangd/index/CanonicalIncludes.cpp
83

Although allocator could be exposed by <iosfwd>, it's not defined in <iosfwd>, so we don't need to handle it specially.

I am sorting the symbols by their canonical headers, which I think would make it easier to check the header mapping.

unittests/clangd/SymbolCollectorTests.cpp
561

The symbol mapping doesn't make a difference between symbol types, and symbol kind test is not in the scope of this patch, so I think this wouldn't be necessary here.

sammccall accepted this revision.Mar 1 2018, 6:06 AM
sammccall added inline comments.
clangd/index/CanonicalIncludes.h
47

Nit: "Symbol mappings take precedence over header mappings"?

51

Nit: rephrase as "returns the canonical include for \p Symbol, which is declared in \p Header"?

53–56

Why can't we always provide this?

unittests/clangd/SymbolCollectorTests.cpp
561

I'd be +1 on matching the real header a bit more so it's more obvious how this relates to the standard library. As long as it's not too hard!

This revision is now accepted and ready to land.Mar 1 2018, 6:06 AM
ioeric updated this revision to Diff 136561.Mar 1 2018, 10:04 AM
ioeric marked 2 inline comments as done.
  • Merge with origin/master
  • Address review comments.
clangd/index/CanonicalIncludes.h
53–56

I think it would be better to keep supporting the header-only mapping use case.

unittests/clangd/SymbolCollectorTests.cpp
561

I'd prefer to keep the test case minimum so that it's clear that we are only matching on names.

This revision was automatically updated to reflect the committed changes.