Skip to content

[Clang][Sema] Refactor collection of multi-level template argument lists #106585

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

Merged
merged 35 commits into from
Sep 20, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
072be6e
[WIP] set isMemberSpecialization early
sdkrystian Aug 1, 2024
6cb3f61
[WIP] set isMemberSpecialization before comparing template parameter …
sdkrystian Aug 8, 2024
420b553
[FOLD]
sdkrystian Aug 8, 2024
bd8156b
[FOLD] pass old and new declarations to TemplateParameterListsAreEqua…
sdkrystian Aug 12, 2024
a37d796
[FOLD] implement TemplateInstantiationArgumentCollecter
sdkrystian Aug 12, 2024
07d100a
[FOLD] update test
sdkrystian Aug 12, 2024
37f1461
[FOLD] further simplify getTemplateInstantiationArgs
sdkrystian Aug 12, 2024
f1e1272
[FOLD] add tests
sdkrystian Aug 12, 2024
623e4ac
[FOLD]
sdkrystian Aug 12, 2024
3c78bbf
[FOLD] remove SkipForSpecialization and Pattern parameters from getTe…
sdkrystian Aug 13, 2024
e0bd523
[FOLD] using the right next decl after adding innermost template argu…
sdkrystian Aug 14, 2024
658c6c9
[FOLD] instantiate lambda default args correctly
sdkrystian Aug 20, 2024
4832287
[FOLD] handle template template params correctly and switch to descri…
sdkrystian Aug 23, 2024
3c8ce5c
[FOLD] remove code for handling described templates
sdkrystian Aug 23, 2024
fd186a9
[FOLD] handle partial specializations that are member specializations
sdkrystian Aug 23, 2024
66b0d89
[FOLD] cleanups
sdkrystian Aug 23, 2024
b467dfe
[FOLD] cleanup dead code
sdkrystian Aug 27, 2024
c0af059
[FOLD] revert whitespace only changes
sdkrystian Aug 27, 2024
a82ccbb
[FOLD] remove some redundant checks
sdkrystian Aug 27, 2024
e235dce
[FOLD] fix common pointer being overwritten when deserializing
sdkrystian Aug 28, 2024
af67f88
[FOLD] more cleanup
sdkrystian Aug 29, 2024
2b98556
[FOLD] more cleanups
sdkrystian Aug 29, 2024
86e9e55
[FOLD] format
sdkrystian Aug 29, 2024
fec5107
[FOLD] address some review feedback
sdkrystian Aug 30, 2024
6b39e14
[FOLD] use pointer for InstantiatedFromMember
sdkrystian Aug 30, 2024
9e18656
[FOLD] add comment
sdkrystian Aug 30, 2024
6073ed4
[FOLD] diagnose redefinitions after checking template parameter equiv…
sdkrystian Sep 3, 2024
f94fb03
[FOLD] more tests
sdkrystian Sep 3, 2024
0a64b37
[FOLD] add getCommonPtrInternal
sdkrystian Sep 20, 2024
a9b14fa
[FOLD] add asserts in setInstantiationOf
sdkrystian Sep 20, 2024
ad6e50d
[FOLD] split up template argument collection for class/variable templ…
sdkrystian Sep 20, 2024
3add30a
[FOLD] add RedeclarableTemplateDecl::setCommonPtr
sdkrystian Sep 20, 2024
29745c7
[FOLD] update docs
sdkrystian Sep 20, 2024
22e4d64
[FOLD] remove DontClearRelativeToPrimaryNextDecl
sdkrystian Sep 20, 2024
bd6a615
[FOLD] add release note
sdkrystian Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[FOLD] cleanups
  • Loading branch information
sdkrystian committed Sep 20, 2024
commit 66b0d8938fa214c0c2e83370a5867d87b7991d2f
92 changes: 4 additions & 88 deletions clang/lib/Sema/SemaTemplateInstantiate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,40 +323,22 @@ struct TemplateInstantiationArgumentCollecter
return UseNextDecl(CD);
}

#if 0
Decl *VisitClassTemplatePartialSpecializationDecl(ClassTemplatePartialSpecializationDecl *CTPSD) {
if (!SkipForSpecialization)
Result.addOuterRetainedLevels(CTPSD->getTemplateDepth());
return Done();
}
#endif

Decl *VisitFunctionDecl(FunctionDecl *FD) {
assert(!FD->getDescribedFunctionTemplate() && "not for templated declarations");

if (!RelativeToPrimary) {
// Add template arguments from a function template specialization.
if (const MemberSpecializationInfo *MSI = FD->getMemberSpecializationInfo();
MSI && MSI->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
return Done();

// This is an implicit instantiation of an explicit specialization. We
// don't get any template arguments from this function but might get
// some from an enclosing template.
if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization)
return UseNextDecl(FD);
}
#if 0
// Add template arguments from a function template specialization.
if (!RelativeToPrimary &&
FD->getTemplateSpecializationKindForInstantiation() ==
TSK_ExplicitSpecialization)
return Done();

if (!RelativeToPrimary &&
FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) {
// This is an implicit instantiation of an explicit specialization. We
// don't get any template arguments from this function but might get
// some from an enclosing template.
return UseNextDecl(FD);
} else
#endif
if (const TemplateArgumentList *TemplateArgs =
FD->getTemplateSpecializationArgs()) {
// Add the template arguments for this specialization.
Expand Down Expand Up @@ -452,33 +434,6 @@ struct TemplateInstantiationArgumentCollecter
}

Decl *VisitClassTemplateSpecializationDecl(ClassTemplateSpecializationDecl *CTSD) {
#if 0
if (!CTSD->isClassScopeExplicitSpecialization()) {
// We're done when we hit an explicit specialization.
if (CTSD->getSpecializationKind() == TSK_ExplicitSpecialization &&
!isa<ClassTemplatePartialSpecializationDecl>(CTSD))
return Done();

if (!SkipForSpecialization)
Result.addOuterTemplateArguments(
CTSD, CTSD->getTemplateInstantiationArgs().asArray(), /*Final=*/false);

// If this class template specialization was instantiated from a
// specialized member that is a class template, we're done.
assert(CTSD->getSpecializedTemplate() && "No class template?");
if (CTSD->getSpecializedTemplate()->isMemberSpecialization())
return Done();

// If this was instantiated from a partial template specialization, we need
// to get the next level of declaration context from the partial
// specialization, as the ClassTemplateSpecializationDecl's
// DeclContext/LexicalDeclContext will be for the primary template.
if (auto *CTPSD = CTSD->getSpecializedTemplateOrPartial()
.dyn_cast<ClassTemplatePartialSpecializationDecl *>())
return ChangeDecl(CTPSD->getLexicalDeclContext());
}
return UseNextDecl(CTSD);
#else
// For a class-scope explicit specialization, there are no template arguments
// at this level, but there may be enclosing template arguments.
if (CTSD->isClassScopeExplicitSpecialization() &&
Expand All @@ -490,23 +445,6 @@ struct TemplateInstantiationArgumentCollecter
!isa<ClassTemplatePartialSpecializationDecl>(CTSD))
return Done();

#if 0
if (auto *CTPSD = Specialized.dyn_cast<ClassTemplatePartialSpecializationDecl *>()) {
Result.addOuterTemplateArguments(
CTPSD, CTSD->getTemplateInstantiationArgs().asArray(),
/*Final=*/false);
if (CTPSD->isMemberSpecialization())
return Done();
} else {
auto *CTD = Specialized.get<ClassTemplateDecl *>();
Result.addOuterTemplateArguments(
CTD, CTSD->getTemplateInstantiationArgs().asArray(),
/*Final=*/false);
if (CTD->isMemberSpecialization())
return Done();
}
#else

if (Innermost)
AddInnermostTemplateArguments(CTSD);
else
Expand All @@ -533,9 +471,7 @@ struct TemplateInstantiationArgumentCollecter
if (CTD->isMemberSpecialization())
return Done();
}
#endif
return DontClearRelativeToPrimaryNextDecl(CTSD);
#endif
}

Decl *VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *VTSD) {
Expand Down Expand Up @@ -595,13 +531,11 @@ struct TemplateInstantiationArgumentCollecter
return UseNextDecl(D);
}

#if 1
Decl *Visit(Decl *D) {
if (TemplateDecl *TD = D->getDescribedTemplate())
D = TD;
return DeclVisitor::Visit(D);
}
#endif
};

} // namespace
Expand All @@ -620,24 +554,6 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
if (!CurDecl)
CurDecl = Decl::castFromDeclContext(DC);

#if 0
if (Innermost) {
Result.addOuterTemplateArguments(const_cast<NamedDecl *>(ND), *Innermost,
Final);
// Populate placeholder template arguments for TemplateTemplateParmDecls.
// This is essential for the case e.g.
//
// template <class> concept Concept = false;
// template <template <Concept C> class T> void foo(T<int>)
//
// where parameter C has a depth of 1 but the substituting argument `int`
// has a depth of 0.
if (const auto *TTP = dyn_cast<TemplateTemplateParmDecl>(CurDecl))
HandleDefaultTempArgIntoTempTempParam(TTP, Result);
CurDecl = Response::UseNextDecl(CurDecl).NextDecl;
}
#endif

TemplateInstantiationArgumentCollecter Collecter(
*this, Result, Innermost, RelativeToPrimary,
ForConstraintInstantiation);
Expand Down