Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] remove ClassScopeFunctionSpecializationDecl #66636

Merged
merged 1 commit into from
Oct 7, 2023

Conversation

sdkrystian
Copy link
Member

This removes the ClassScopeFunctionSpecializationDecl Decl node, and instead uses DependentFunctionTemplateSpecializationInfo to handle such declarations. DependentFunctionTemplateSpecializationInfo is also changed to store a const ASTTemplateArgumentListInfo* to be more in line with FunctionTemplateSpecializationInfo.

This also changes FunctionDecl::isFunctionTemplateSpecialization to return true for dependent specializations, and FunctionDecl::getTemplateSpecializationKind/FunctionDecl::getTemplateSpecializationKindForInstantiation to return TSK_ExplicitSpecialization for non-friend dependent specializations (the same behavior as dependent class scope ClassTemplateSepcializationDecl & VarTemplateSepcializationDecl).

@llvmbot llvmbot added clang Clang issues not falling into any other category clangd clang-tidy clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:codegen clang:static analyzer labels Sep 18, 2023
@cor3ntin
Copy link
Contributor

@erichkeane Opinions?

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess my first question is 'why'? My second is 'if this is unnecessary, why was it here in the first place?`. I'd like some level of historical analysis here/perhaps the knowledge of @zygoloid.

clang/include/clang/AST/DeclTemplate.h Show resolved Hide resolved
@sdkrystian
Copy link
Member Author

@erichkeane

I guess my first question is 'why'?

Per the comment you mentioned, it is redundant. Switching to DependentFunctionTemplateSpecializationInfo also results in constructs such as:

template<typename T>
struct A {
  template<>
  void f();
};

being diagnosed prior to instantiation. Class scope explicit specializations currently exist in their own broken little corner of the frontend, so unifying their representation in the AST would be the first step towards properly fixing them.

My second is 'if this is unnecessary, why was it here in the first place?`.

ClassScopeFunctionSpecializationDecl was originally added in this commit to "parse MSVC standard C++ headers, MFC and ATL code." Back then, class scope explicit specializations were a Microsoft extension, but since CWG727 they are valid ISO C++. As for why this was not originally implemented using DependentFunctionTemplateSpecializationInfo, I cannot say.

Copy link
Collaborator

@erichkeane erichkeane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't spend much time in Serialization, so hopefully someone else can take a look, but in general I think I'm warming toward this.

clang/include/clang/AST/ASTNodeTraverser.h Outdated Show resolved Hide resolved
clang/include/clang/AST/RecursiveASTVisitor.h Outdated Show resolved Hide resolved
clang/lib/Sema/SemaDecl.cpp Show resolved Hide resolved
Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly minor fixes and or questions.

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp Outdated Show resolved Hide resolved
clang/lib/Serialization/ASTReaderDecl.cpp Show resolved Hide resolved
clang/lib/Serialization/ASTWriterDecl.cpp Show resolved Hide resolved
@EugeneZelenko EugeneZelenko removed the clang Clang issues not falling into any other category label Sep 19, 2023
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Sep 19, 2023
@sdkrystian sdkrystian force-pushed the inline-function-spec branch 2 times, most recently from 2b5e53b to 01ad064 Compare September 19, 2023 09:29
@sdkrystian
Copy link
Member Author

Ping @erichkeane & @shafik -- I left comments responding to your feedback

@erichkeane
Copy link
Collaborator

I don't have any comments, though someone with knowledge of teh clang-tools-extra stuff would be nice to take a look, as well as someone familiar with the serialization. @AaronBallman .

ALSO, this might need a release note and does this need to be mailed to the 'breaking changes' vendor list since it is significantly going to change the AST?

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes should definitely have a release note so that downstreams can be aware of the changes. This isn't really a potentially breaking change, but we should alert clang-vendors in case a downstream actually cares.

clang/include/clang/AST/RecursiveASTVisitor.h Outdated Show resolved Hide resolved
clang/lib/Sema/SemaDecl.cpp Show resolved Hide resolved
clang/lib/Sema/SemaTemplate.cpp Outdated Show resolved Hide resolved
@sdkrystian
Copy link
Member Author

@AaronBallman

Can you be sure to file an issue or add a test case + FIXME comment so we don't lose track of the needed follow-up work, or are you planning to do that work immediately after this lands?

I will address that once this gets merged

@AaronBallman
Copy link
Collaborator

CC @llvm/clang-vendors for awareness of the AST changing to remove a node.

@sdkrystian
Copy link
Member Author

Updated the release notes. I didn't go into exhaustive detail, but I can add more if anyone here deems it necessary @erichkeane @AaronBallman

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM aside from a minor suggestion with the release note.

clang/docs/ReleaseNotes.rst Outdated Show resolved Hide resolved
@AaronBallman
Copy link
Collaborator

Do you need someone to land these changes on your behalf?

@sdkrystian
Copy link
Member Author

@AaronBallman I don't have write access, so that would be appreciated 🙂. I was putting off rebasing incase there were more responses to my comments, but I presume that there won't be so I will get it rebased now

@sdkrystian sdkrystian force-pushed the inline-function-spec branch from 3b55a38 to cc76b72 Compare October 6, 2023 20:21
@sdkrystian sdkrystian requested a review from Endilll as a code owner October 6, 2023 20:21
@sdkrystian sdkrystian force-pushed the inline-function-spec branch from cc76b72 to 4ea4e89 Compare October 6, 2023 20:23
@github-actions
Copy link

github-actions bot commented Oct 6, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@erichkeane
Copy link
Collaborator

If Aaron doesn't get to it, feel free to ping me on Monday. Its too late on a Friday for me to be able to merge this for you, but monday morning would be fine for me.

@sdkrystian sdkrystian force-pushed the inline-function-spec branch from 4ea4e89 to 39744e6 Compare October 6, 2023 20:25
@Endilll Endilll merged commit 3a3b84b into llvm:main Oct 7, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:static analyzer clang Clang issues not falling into any other category clang-tidy clangd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants