Skip to content

Commit 08e551a

Browse files
committed
[FOLD] more cleanup
1 parent 3791fe1 commit 08e551a

File tree

4 files changed

+30
-106
lines changed

4 files changed

+30
-106
lines changed

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
765765
}
766766
// Template arguments used to transform the template arguments in
767767
// DeducedResults.
768-
SmallVector<TemplateArgument> TemplateArgsForBuildingRC(
768+
SmallVector<TemplateArgument> InnerArgsForBuildingRC(
769769
F->getTemplateParameters()->size());
770770
// Transform the transformed template args
771771
MultiLevelTemplateArgumentList Args;
@@ -778,39 +778,31 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
778778
NamedDecl *TP = F->getTemplateParameters()->getParam(Index);
779779
MultiLevelTemplateArgumentList Args;
780780
Args.setKind(TemplateSubstitutionKind::Rewrite);
781-
Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
781+
Args.addOuterTemplateArguments(InnerArgsForBuildingRC);
782782
// Rebuild the template parameter with updated depth and index.
783783
NamedDecl *NewParam =
784784
transformTemplateParameter(SemaRef, F->getDeclContext(), TP, Args,
785785
/*NewIndex=*/FirstUndeducedParamIdx,
786786
getDepthAndIndex(TP).first + AdjustDepth);
787787
FirstUndeducedParamIdx += 1;
788-
assert(TemplateArgsForBuildingRC[Index].isNull());
789-
TemplateArgsForBuildingRC[Index] =
788+
assert(InnerArgsForBuildingRC[Index].isNull());
789+
InnerArgsForBuildingRC[Index] =
790790
Context.getInjectedTemplateArg(NewParam);
791791
continue;
792792
}
793793
TemplateArgumentLoc Input =
794794
SemaRef.getTrivialTemplateArgumentLoc(D, QualType(), SourceLocation{});
795795
TemplateArgumentLoc Output;
796796
if (!SemaRef.SubstTemplateArgument(Input, Args, Output)) {
797-
assert(TemplateArgsForBuildingRC[Index].isNull() &&
797+
assert(InnerArgsForBuildingRC[Index].isNull() &&
798798
"InstantiatedArgs must be null before setting");
799-
TemplateArgsForBuildingRC[Index] = Output.getArgument();
799+
InnerArgsForBuildingRC[Index] = Output.getArgument();
800800
}
801801
}
802802

803-
// A list of template arguments for transforming the require-clause of F.
804-
// It must contain the entire set of template argument lists.
805-
MultiLevelTemplateArgumentList ArgsForBuildingRC =
806-
SemaRef.getTemplateInstantiationArgs(
807-
F, F->getLexicalDeclContext(),
808-
/*Final=*/false, /*Innermost=*/TemplateArgsForBuildingRC,
809-
/*RelativeToPrimary=*/true,
810-
/*ForConstraintInstantiation=*/true);;
811-
ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
812-
#if 0
813-
ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
803+
// A list of template arguments for transforming the require-clause using
804+
// the transformed template arguments as the template argument list of F.
805+
//
814806
// For 2), if the underlying deduction guide F is nested in a class template,
815807
// we need the entire template argument list, as the constraint AST in the
816808
// require-clause of F remains completely uninstantiated.
@@ -833,27 +825,15 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
833825
// - The occurrence of U in the function parameter is [depth:0, index:0]
834826
// - The template parameter of U is [depth:0, index:0]
835827
//
836-
// We add the outer template arguments which is [int] to the multi-level arg
837-
// list to ensure that the occurrence U in `C<U>` will be replaced with int
838-
// during the substitution.
839-
//
840828
// NOTE: The underlying deduction guide F is instantiated -- either from an
841829
// explicitly-written deduction guide member, or from a constructor.
842-
// getInstantiatedFromMemberTemplate() can only handle the former case, so we
843-
// check the DeclContext kind.
844-
if (F->getLexicalDeclContext()->getDeclKind() ==
845-
clang::Decl::ClassTemplateSpecialization) {
846-
auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
830+
MultiLevelTemplateArgumentList ArgsForBuildingRC =
831+
SemaRef.getTemplateInstantiationArgs(
847832
F, F->getLexicalDeclContext(),
848-
/*Final=*/false, /*Innermost=*/std::nullopt,
833+
/*Final=*/false, /*Innermost=*/InnerArgsForBuildingRC,
849834
/*RelativeToPrimary=*/true,
850-
/*Pattern=*/nullptr,
851-
/*ForConstraintInstantiation=*/true);
852-
for (auto It : OuterLevelArgs)
853-
ArgsForBuildingRC.addOuterTemplateArguments(It.Args);
854-
}
855-
#endif
856-
835+
/*ForConstraintInstantiation=*/true);;
836+
ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
857837

858838
ExprResult E = SemaRef.SubstExpr(RC, ArgsForBuildingRC);
859839
if (E.isInvalid())

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,6 @@ using namespace sema;
5252
//===----------------------------------------------------------------------===/
5353

5454
namespace {
55-
struct Response {
56-
const Decl *NextDecl = nullptr;
57-
bool IsDone = false;
58-
bool ClearRelativeToPrimary = true;
59-
static Response Done() {
60-
Response R;
61-
R.IsDone = true;
62-
return R;
63-
}
64-
static Response ChangeDecl(const Decl *ND) {
65-
Response R;
66-
R.NextDecl = ND;
67-
return R;
68-
}
69-
static Response ChangeDecl(const DeclContext *Ctx) {
70-
Response R;
71-
R.NextDecl = Decl::castFromDeclContext(Ctx);
72-
return R;
73-
}
74-
75-
static Response UseNextDecl(const Decl *CurDecl) {
76-
return ChangeDecl(CurDecl->getDeclContext());
77-
}
78-
79-
static Response DontClearRelativeToPrimaryNextDecl(const Decl *CurDecl) {
80-
Response R = Response::UseNextDecl(CurDecl);
81-
R.ClearRelativeToPrimary = false;
82-
return R;
83-
}
84-
};
8555
// Retrieve the primary template for a lambda call operator. It's
8656
// unfortunate that we only have the mappings of call operators rather
8757
// than lambda classes.
@@ -169,25 +139,6 @@ bool isLambdaEnclosedByTypeAliasDecl(
169139
.TraverseType(Underlying);
170140
}
171141

172-
namespace TemplateInstArgsHelpers {
173-
174-
// If we have a template template parameter with translation unit context,
175-
// then we're performing substitution into a default template argument of
176-
// this template template parameter before we've constructed the template
177-
// that will own this template template parameter. In this case, we
178-
// use empty template parameter lists for all of the outer templates
179-
// to avoid performing any substitutions.
180-
Response
181-
HandleDefaultTempArgIntoTempTempParam(const TemplateTemplateParmDecl *TTP,
182-
MultiLevelTemplateArgumentList &Result) {
183-
for (unsigned I = 0, N = TTP->getDepth() + 1; I != N; ++I)
184-
Result.addOuterTemplateArguments(std::nullopt);
185-
return Response::Done();
186-
}
187-
188-
} // namespace TemplateInstArgsHelpers
189-
190-
191142
struct TemplateInstantiationArgumentCollecter
192143
: DeclVisitor<TemplateInstantiationArgumentCollecter, Decl*> {
193144
Sema &S;
@@ -540,8 +491,6 @@ MultiLevelTemplateArgumentList Sema::getTemplateInstantiationArgs(
540491
assert((ND || DC) && "Can't find arguments for a decl if one isn't provided");
541492
// Accumulate the set of template argument lists in this structure.
542493
MultiLevelTemplateArgumentList Result;
543-
544-
using namespace TemplateInstArgsHelpers;
545494
const Decl *CurDecl = ND;
546495

547496
if (!CurDecl)

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,25 +4684,30 @@ bool Sema::InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
46844684
ParmVarDecl *Param) {
46854685
assert(Param->hasUninstantiatedDefaultArg());
46864686

4687-
NamedDecl *Pattern = nullptr;
4687+
NamedDecl *Pattern = FD;
46884688
std::optional<ArrayRef<TemplateArgument>> Innermost;
4689-
#if 1
46904689

4691-
if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) {
4690+
if (FD->isCXXClassMember() && !isGenericLambdaCallOperatorOrStaticInvokerSpecialization(FD)) {
4691+
if (FunctionTemplateDecl *FTD = FD->getPrimaryTemplate()) {
4692+
Pattern = FTD->getFirstDecl();
4693+
Innermost = FD->getTemplateSpecializationArgs()->asArray();
4694+
}
4695+
}
4696+
#if 0
4697+
46924698
Pattern = FTD->isCXXClassMember() ? FTD->getFirstDecl() : FTD;
4693-
Innermost = FD->getTemplateSpecializationArgs()->asArray();
46944699
} else if (FD->isCXXClassMember()) {
46954700
Pattern = FD->getFirstDecl();
46964701
} else {
46974702
Pattern = FD;
46984703
}
4699-
#else
4704+
#elif 0
47004705
Pattern = FD;
4706+
#elif 0
4707+
Pattern = FD->getTemplateInstantiationPattern(/*ForDefinition=*/true);
4708+
#elif 1
47014709
#endif
47024710

4703-
if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(FD))
4704-
Pattern = FD;
4705-
47064711
// Instantiate the expression.
47074712
//
47084713
// FIXME: Pass in a correct Pattern argument, otherwise
@@ -5201,14 +5206,8 @@ void Sema::InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
52015206
RebuildTypeSourceInfoForDefaultSpecialMembers();
52025207
SetDeclDefaulted(Function, PatternDecl->getLocation());
52035208
} else {
5204-
#if 0
5205-
MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(
5206-
Function, Function->getLexicalDeclContext(), /*Final=*/false,
5207-
/*Innermost=*/std::nullopt, false, PatternDecl);
5208-
#else
52095209
MultiLevelTemplateArgumentList TemplateArgs = getTemplateInstantiationArgs(
52105210
Function, Function->getLexicalDeclContext());
5211-
#endif
52125211

52135212
// Substitute into the qualifier; we can get a substitution failure here
52145213
// through evil use of alias templates.

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,15 +1707,13 @@ void ASTDeclWriter::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) {
17071707
void ASTDeclWriter::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
17081708
VisitRedeclarable(D);
17091709

1710-
// if (D->getInstantiatedFromMemberTemplate())
17111710
Record.push_back(D->isMemberSpecialization());
17121711

17131712
// Emit data to initialize CommonOrPrev before VisitTemplateDecl so that
17141713
// getCommonPtr() can be used while this is still initializing.
1715-
if (D->isFirstDecl()) {
1714+
if (D->isFirstDecl())
17161715
// This declaration owns the 'common' pointer, so serialize that data now.
17171716
Record.AddDeclRef(D->getInstantiatedFromMemberTemplate());
1718-
}
17191717

17201718
VisitTemplateDecl(D);
17211719
Record.push_back(D->getIdentifierNamespace());
@@ -1791,9 +1789,8 @@ void ASTDeclWriter::VisitClassTemplatePartialSpecializationDecl(
17911789

17921790
Record.push_back(D->isMemberSpecialization());
17931791
// These are read/set from/to the first declaration.
1794-
if (D->getPreviousDecl() == nullptr) {
1792+
if (D->isFirstDecl())
17951793
Record.AddDeclRef(D->getInstantiatedFromMember());
1796-
}
17971794

17981795
Code = serialization::DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION;
17991796
}
@@ -1860,9 +1857,8 @@ void ASTDeclWriter::VisitVarTemplatePartialSpecializationDecl(
18601857
Record.push_back(D->isMemberSpecialization());
18611858

18621859
// These are read/set from/to the first declaration.
1863-
if (D->getPreviousDecl() == nullptr) {
1860+
if (D->isFirstDecl())
18641861
Record.AddDeclRef(D->getInstantiatedFromMember());
1865-
}
18661862

18671863
Code = serialization::DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION;
18681864
}

0 commit comments

Comments
 (0)