We are missing the default parmeter arguments when IndexFunctionLocals
is true.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Unit Tests
Event Timeline
Oh god, this code is a mess, so many knobs, and apparently I made it worst in the past sorry for that :D
I totally understand if you want to make minimal changes to the code like this, but it would be great to simplify it a little bit without regressing too much, currently there is a knob for function locals and then another for parameters in declarations, then there is an implicit conditioning for function definitions.
I would say it would be sensible to only have IndexFunctionLocals as an option and do full indexing of parameters, both in declarations and definitions if it is present (assuming this doesn't result in real regressions in the client code), but it is also OK to leave it as it is, since the mess is beyond the scope of this patch.
But if you leave it as it is, I believe we'll still be missing some references to decls inside default arguments in clangd, for example:
a.h:
int var = 2; void foo(int x = var);
a.cc
void foo(int x) { va^r = x; }
clangd won't have the reference occuring in default arg inside the index, as preambles are not indexed with IndexParametersInDeclarations option turned on.
clang/lib/Index/IndexDecl.cpp | ||
---|---|---|
102 | this should move into the else clause down below, otherwise it would end up being indexed twice |
I totally understand if you want to make minimal changes to the code like this, but it would be great to simplify it a little bit without regressing too much, currently there is a knob for function locals and then another for parameters in declarations, then there is an implicit conditioning for function definitions.
I would say it would be sensible to only have IndexFunctionLocals as an option and do full indexing of parameters, both in declarations and definitions if it is present (assuming this doesn't result in real regressions in the client code), but it is also OK to leave it as it is, since the mess is beyond the scope of this patch.
removing the shouldIndexParametersInDeclarations seems good to me, looks like clangd is the only user of this flag. Regression is the concern -- as we are changing the behavior of libindex, and the libindex doesn't seem to have enough test coverage. I'd land this fix as it-is, and cleanup afterwards.
But if you leave it as it is, I believe we'll still be missing some references to decls inside default arguments in clangd, for example:
a.h:
int var = 2;
void foo(int x = var);
a.ccvoid foo(int x) {
va^r = x;}
clangd won't have the reference occuring in default arg inside the index, as preambles are not indexed with IndexParametersInDeclarations option turned on.
Are you talking about dynamic index? clangd doesn't record any refs in preamble by design -- as we skip function bodies in preamble
clang/lib/Index/IndexDecl.cpp | ||
---|---|---|
102 | My reading to the source is that
a conservative fix is that we only need the change on Line 117. I removed the change in the current if clause. |
Looking the source code closely, we also have another code path of indexing the ParmVarDecl in clang/lib/Index/IndexTypeSourceInfo.cpp, it was called via IndexCtx.indexTypeSourceInfo in handleDeclarator.
In summary:
- default arguments will be visited if this is a non-definition decl, regardless the shouldIndexFunctionLocatl -- this is done in IndexTypeSourceInfo
- default arguments will be visited if this is a definition decl and shouldIndexFunctionLocal is fasle -- this is done in IndexDecl.
- default arguments will not be visited if this is a definition decl and shouldIndexFunctionLocal is true
This patch fixes 3).
LGTM,
just wondering though if you've tried the solution we discussed offline regarding updating indexTypeSourceInfo instead of this call site, could you mention the results in here?
So that the next soul that touches these lines has an idea about what's expecting them?
this should move into the else clause down below, otherwise it would end up being indexed twice