Skip to content

[clang] remove ClassScopeFunctionSpecializationDecl - #66636

Merged
Endilll merged 1 commit into
llvm:mainfrom
sdkrystian:inline-function-spec
Oct 7, 2023
Merged

[clang] remove ClassScopeFunctionSpecializationDecl#66636
Endilll merged 1 commit into
llvm:mainfrom
sdkrystian:inline-function-spec

Conversation

@sdkrystian

Copy link
Copy Markdown
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 IR generation bugs: mangling, exceptions, etc. clang:static analyzer labels Sep 18, 2023
@cor3ntin

Copy link
Copy Markdown
Contributor

@erichkeane Opinions?

@erichkeane erichkeane left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread clang/include/clang/AST/DeclTemplate.h Outdated
@sdkrystian

Copy link
Copy Markdown
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.

@erichkeane erichkeane left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread clang/include/clang/AST/ASTNodeTraverser.h Outdated
Comment thread clang/include/clang/AST/RecursiveASTVisitor.h Outdated
Comment thread clang/lib/Sema/SemaDecl.cpp Outdated
Comment thread clang/test/SemaTemplate/instantiate-method.cpp Outdated
Comment thread clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp Outdated

@shafik shafik left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread clang/lib/Sema/SemaTemplateInstantiateDecl.cpp Outdated
Comment thread clang/lib/Serialization/ASTReaderDecl.cpp Outdated
Comment thread clang/lib/Serialization/ASTWriterDecl.cpp Outdated
@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
Copy Markdown
Member Author

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

@erichkeane

Copy link
Copy Markdown
Contributor

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?

@AaronBallman AaronBallman left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread clang-tools-extra/clangd/SemanticHighlighting.cpp Outdated
Comment thread clang/include/clang/AST/RecursiveASTVisitor.h Outdated
Comment thread clang/include/clang/Serialization/ASTBitCodes.h Outdated
Comment thread clang/lib/Sema/SemaDecl.cpp Outdated
Comment thread clang/lib/Sema/SemaTemplate.cpp Outdated
@sdkrystian

Copy link
Copy Markdown
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
Copy Markdown
Contributor

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

@sdkrystian

Copy link
Copy Markdown
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

@AaronBallman AaronBallman left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread clang/docs/ReleaseNotes.rst Outdated
@AaronBallman

Copy link
Copy Markdown
Contributor

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

@sdkrystian

Copy link
Copy Markdown
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

github-actions Bot commented Oct 6, 2023

Copy link
Copy Markdown

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

@erichkeane

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:codegen IR generation bugs: mangling, exceptions, etc. 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.

10 participants