This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Handle DependentNameType in HeuristicResolver::resolveTypeToRecordDecl()
ClosedPublic

Authored by nridge on Jun 10 2023, 11:59 PM.

Diff Detail

Event Timeline

nridge created this revision.Jun 10 2023, 11:59 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2023, 11:59 PM
nridge requested review of this revision.Jun 10 2023, 11:59 PM
nridge edited the summary of this revision. (Show Details)Jun 11 2023, 12:02 AM
nridge added inline comments.Jun 11 2023, 12:04 AM
clang-tools-extra/clangd/HeuristicResolver.cpp
38

I wanted to call out the change on this line which is easy to overlook due to the code move:

We were previously calling TypeDecl::getTypeForDecl(), but that's actually a low-level accessor for a cached value. The function that also populates the value if needed is ASTContext::getTypeDeclType(), hence I switch to using that.

hokein added inline comments.Jun 15 2023, 1:08 AM
clang-tools-extra/clangd/HeuristicResolver.cpp
33

the reason to promote this utility function to a class method seems to be able to access the member field ASTContext. If so, I'd probably just passing the ASTContext as a parameter rather then making them member methods.

38

thanks for the highlight, I think this change makes sense.

60

Is the resolveDeclsToType call necessary here?
The code path we're doing is dependent-type => Decl* => Type => Decl*, the later two steps seems redundant, can we just use the Decl result from resolveDependentNameType()?

nridge updated this revision to Diff 532008.Jun 16 2023, 12:12 AM
nridge marked 2 inline comments as done.

Address review comments

clang-tools-extra/clangd/HeuristicResolver.cpp
60

The Decl returned by resolveDependentNameType() in this testcase is a TypeAliasDecl. The function needs to return the CXXRecordDecl which is named by the target type of the alias.

We could add logic to "desugar" the TypeAliasDecl, but it seems easier to reuse the existing logic that does the desugaring in type-land.

hokein accepted this revision.Jun 16 2023, 2:57 AM
hokein added inline comments.
clang-tools-extra/clangd/HeuristicResolver.cpp
33

nit: move this helper function to anonymous namespace.

60

I see, thanks for the explanation (this part of code is a bit hard to follow).

This revision is now accepted and ready to land.Jun 16 2023, 2:57 AM
nridge updated this revision to Diff 532263.Jun 16 2023, 12:19 PM
nridge marked an inline comment as done.

Address last comment

This revision was landed with ongoing or failed builds.Jun 16 2023, 12:21 PM
This revision was automatically updated to reflect the committed changes.