This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Don't set the Underlying bit on targets of UsingDecls.
ClosedPublic

Authored by hokein on Sep 29 2020, 2:41 AM.

Details

Summary

With this patch, we don't treat using ns::X as a first-class declaration like using Z = ns::Y, reference to X that goes through this using-decl is considered a direct reference (without the Underlying bit).

Fix the workaround in https://reviews.llvm.org/D87225 and https://reviews.llvm.org/D74054.

Diff Detail

Event Timeline

hokein created this revision.Sep 29 2020, 2:41 AM
hokein requested review of this revision.Sep 29 2020, 2:41 AM
hokein added inline comments.Sep 29 2020, 2:46 AM
clang-tools-extra/clangd/FindTarget.h
112

The previous Alias vs Underlying were pretty nice, but they were not enough to support our non-renaming-alias-underlying case. Looking for the feedback on the API change here.

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1121–1122

this seems a small regression, I think it is fine.

1132

I think it is an improvement.

We manage to get rid of a little code here, but we add complexity to an important API, and make... one test better and a few tests worse.
I'd like to get rid of the wart in the code, but the tradeoff doesn't seem completely compelling... going to think about the API here a bit.

clang-tools-extra/clangd/FindTarget.h
112

Inevitably this adds some noise, and the names are less clear (we certainly need to avoid using "alias" to mean two different things, and we should try to avoid negatives that confuse the boolean logic).
We could simplify this at least at query locations by defining Underlying = NonAliasUnderlying | AliasUnderlying, but unfortunately we can't put it in DeclRelation.

The other thing is this isn't complete either, because it doesn't distinguish between renaming and non-renaming Aliases. This is why we have the regression in the testcases.

That this is so verbose is a property of the original design: the idea was "mark this edge as alias->underlying, and apply a bit when that edge is traversed" but of course we decided to signal "the edge is not traversed" too. So if we introduce a new type of edge, we need *two* new bits - one at each end.

I'm trying to think of ideas for improvements without totally ditching the API...

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1121–1122

I can't follow why this is different from the second case of

TEST_F(TargetDeclTest, UsingDecl), where the usingdecl is not reported at all.

hokein updated this revision to Diff 295238.Sep 30 2020, 4:27 AM

refine the patch based on the offline discussion:

  • don't set the Underlying bits for using-declaration's underlying decl.
hokein added inline comments.Sep 30 2020, 4:28 AM
clang-tools-extra/clangd/unittests/XRefsTests.cpp
1121–1122

I think you over-look it, the second case of TEST_F(TargetDeclTest, UsingDecl) does report the using-decl.

hokein retitled this revision from [WIP][clangd] Support non-renaming alias underlying decls in TargetDecl. to [clangd] Don't set the Underlying bit on targets of UsingDecls..Oct 1 2020, 2:22 AM
hokein edited the summary of this revision. (Show Details)
sammccall accepted this revision.Oct 6 2020, 12:17 AM

LG, thanks for all the iterations here.

I do want to solve the regression but we can land without that.

clang-tools-extra/clangd/FindTarget.cpp
346

maybe a comment here "// no Underlying as this is a non-renaming alias"

358

and here

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1121–1122

I'd like to make a plan to solve this regression (we can do it here or in a followup patch, happy to hack on that).

What do you think about the following heuristic:

  • if go-to-definition yields multiple results
  • and a particular result touches the cursor*
  • (optional) and that result is marked with Alias
  • then drop it from the set

It means we still keep some special-case code, but it's not complex and fairly intuitive I think.

This revision is now accepted and ready to land.Oct 6 2020, 12:17 AM
hokein updated this revision to Diff 296612.Oct 7 2020, 12:59 AM
hokein marked 2 inline comments as done.

address comments.

clang-tools-extra/clangd/unittests/XRefsTests.cpp
1121–1122

sounds good. I'd leave it as a follow-up. Added a FIXME.

This revision was landed with ongoing or failed builds.Oct 7 2020, 1:04 AM
This revision was automatically updated to reflect the committed changes.