Skip to content

Commit c096afb

Browse files
hahnjodevajithvs
authored andcommitted
[llvm-project] Revert our version of D41416
1 parent 6035b0f commit c096afb

File tree

7 files changed

+61
-242
lines changed

7 files changed

+61
-242
lines changed

Diff for: interpreter/llvm-project/clang/include/clang/AST/DeclTemplate.h

+4-32
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@ class TemplateArgumentList final
267267
static TemplateArgumentList *CreateCopy(ASTContext &Context,
268268
ArrayRef<TemplateArgument> Args);
269269

270-
/// \brief Create hash for the given arguments.
271-
static unsigned ComputeODRHash(ArrayRef<TemplateArgument> Args);
272-
273270
/// Construct a new, temporary template argument list on the stack.
274271
///
275272
/// The template argument list does not own the template arguments
@@ -752,26 +749,6 @@ class RedeclarableTemplateDecl : public TemplateDecl,
752749
}
753750

754751
void anchor() override;
755-
struct LazySpecializationInfo {
756-
uint32_t DeclID = ~0U;
757-
unsigned ODRHash = ~0U;
758-
bool IsPartial = false;
759-
LazySpecializationInfo(uint32_t ID, unsigned Hash = ~0U,
760-
bool Partial = false)
761-
: DeclID(ID), ODRHash(Hash), IsPartial(Partial) { }
762-
LazySpecializationInfo() { }
763-
bool operator<(const LazySpecializationInfo &Other) const {
764-
return DeclID < Other.DeclID;
765-
}
766-
bool operator==(const LazySpecializationInfo &Other) const {
767-
assert((DeclID != Other.DeclID || ODRHash == Other.ODRHash) &&
768-
"Hashes differ!");
769-
assert((DeclID != Other.DeclID || IsPartial == Other.IsPartial) &&
770-
"Both must be the same kinds!");
771-
return DeclID == Other.DeclID;
772-
}
773-
};
774-
775752
protected:
776753
template <typename EntryType> struct SpecEntryTraits {
777754
using DeclType = EntryType;
@@ -812,12 +789,7 @@ class RedeclarableTemplateDecl : public TemplateDecl,
812789
return SpecIterator<EntryType>(isEnd ? Specs.end() : Specs.begin());
813790
}
814791

815-
void loadLazySpecializationsImpl(bool OnlyPartial = false) const;
816-
817-
void loadLazySpecializationsImpl(llvm::ArrayRef<TemplateArgument> Args,
818-
TemplateParameterList *TPL = nullptr) const;
819-
820-
Decl *loadLazySpecializationImpl(LazySpecializationInfo &LazySpecInfo) const;
792+
void loadLazySpecializationsImpl() const;
821793

822794
template <class EntryType, typename ...ProfileArguments>
823795
typename SpecEntryTraits<EntryType>::DeclType*
@@ -844,7 +816,7 @@ class RedeclarableTemplateDecl : public TemplateDecl,
844816
///
845817
/// The first value in the array is the number of specializations/partial
846818
/// specializations that follow.
847-
LazySpecializationInfo *LazySpecializations = nullptr;
819+
uint32_t *LazySpecializations = nullptr;
848820

849821
/// The set of "injected" template arguments used within this
850822
/// template.
@@ -2329,7 +2301,7 @@ class ClassTemplateDecl : public RedeclarableTemplateDecl {
23292301
friend class TemplateDeclInstantiator;
23302302

23312303
/// Load any lazily-loaded specializations from the external source.
2332-
void LoadLazySpecializations(bool OnlyPartial = false) const;
2304+
void LoadLazySpecializations() const;
23332305

23342306
/// Get the underlying class declarations of the template.
23352307
CXXRecordDecl *getTemplatedDecl() const {
@@ -3114,7 +3086,7 @@ class VarTemplateDecl : public RedeclarableTemplateDecl {
31143086
friend class ASTDeclWriter;
31153087

31163088
/// Load any lazily-loaded specializations from the external source.
3117-
void LoadLazySpecializations(bool OnlyPartial = false) const;
3089+
void LoadLazySpecializations() const;
31183090

31193091
/// Get the underlying variable declarations of the template.
31203092
VarDecl *getTemplatedDecl() const {

Diff for: interpreter/llvm-project/clang/lib/AST/DeclTemplate.cpp

+22-74
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#include "clang/AST/TemplateBase.h"
2121
#include "clang/AST/TemplateName.h"
2222
#include "clang/AST/Type.h"
23-
#include "clang/AST/ODRHash.h"
24-
#include "clang/AST/ExprCXX.h"
2523
#include "clang/AST/TypeLoc.h"
2624
#include "clang/Basic/Builtins.h"
2725
#include "clang/Basic/LLVM.h"
@@ -333,43 +331,16 @@ RedeclarableTemplateDecl::CommonBase *RedeclarableTemplateDecl::getCommonPtr() c
333331
return Common;
334332
}
335333

336-
void RedeclarableTemplateDecl::loadLazySpecializationsImpl(
337-
bool OnlyPartial/*=false*/) const {
334+
void RedeclarableTemplateDecl::loadLazySpecializationsImpl() const {
338335
// Grab the most recent declaration to ensure we've loaded any lazy
339336
// redeclarations of this template.
340337
CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
341-
if (auto *Specs = CommonBasePtr->LazySpecializations) {
342-
if (!OnlyPartial)
343-
CommonBasePtr->LazySpecializations = nullptr;
344-
for (uint32_t I = 0, N = Specs[0].DeclID; I != N; ++I) {
345-
// Skip over already loaded specializations.
346-
if (!Specs[I+1].ODRHash)
347-
continue;
348-
if (!OnlyPartial || Specs[I+1].IsPartial)
349-
(void)loadLazySpecializationImpl(Specs[I+1]);
350-
}
351-
}
352-
}
353-
354-
Decl *RedeclarableTemplateDecl::loadLazySpecializationImpl(
355-
LazySpecializationInfo &LazySpecInfo) const {
356-
uint32_t ID = LazySpecInfo.DeclID;
357-
assert(ID && "Loading already loaded specialization!");
358-
// Note that we loaded the specialization.
359-
LazySpecInfo.DeclID = LazySpecInfo.ODRHash = LazySpecInfo.IsPartial = 0;
360-
return getASTContext().getExternalSource()->GetExternalDecl(ID);
361-
}
362-
363-
void
364-
RedeclarableTemplateDecl::loadLazySpecializationsImpl(ArrayRef<TemplateArgument>
365-
Args,
366-
TemplateParameterList *TPL) const {
367-
CommonBase *CommonBasePtr = getMostRecentDecl()->getCommonPtr();
368-
if (auto *Specs = CommonBasePtr->LazySpecializations) {
369-
unsigned Hash = TemplateArgumentList::ComputeODRHash(Args);
370-
for (uint32_t I = 0, N = Specs[0].DeclID; I != N; ++I)
371-
if (Specs[I+1].ODRHash && Specs[I+1].ODRHash == Hash)
372-
(void)loadLazySpecializationImpl(Specs[I+1]);
338+
if (CommonBasePtr->LazySpecializations) {
339+
ASTContext &Context = getASTContext();
340+
uint32_t *Specs = CommonBasePtr->LazySpecializations;
341+
CommonBasePtr->LazySpecializations = nullptr;
342+
for (uint32_t I = 0, N = *Specs++; I != N; ++I)
343+
(void)Context.getExternalSource()->GetExternalDecl(Specs[I]);
373344
}
374345
}
375346

@@ -380,8 +351,6 @@ RedeclarableTemplateDecl::findSpecializationImpl(
380351
ProfileArguments&&... ProfileArgs) {
381352
using SETraits = SpecEntryTraits<EntryType>;
382353

383-
loadLazySpecializationsImpl(std::forward<ProfileArguments>(ProfileArgs)...);
384-
385354
llvm::FoldingSetNodeID ID;
386355
EntryType::Profile(ID, std::forward<ProfileArguments>(ProfileArgs)...,
387356
getASTContext());
@@ -397,14 +366,10 @@ void RedeclarableTemplateDecl::addSpecializationImpl(
397366

398367
if (InsertPos) {
399368
#ifndef NDEBUG
400-
auto Args = SETraits::getTemplateArgs(Entry);
401-
// Due to hash collisions, it can happen that we load another template
402-
// specialization with the same hash. This is fine, as long as the next
403-
// call to findSpecializationImpl does not find a matching Decl for the
404-
// template arguments.
405-
loadLazySpecializationsImpl(Args);
406369
void *CorrectInsertPos;
407-
assert(!findSpecializationImpl(Specializations, CorrectInsertPos, Args) &&
370+
assert(!findSpecializationImpl(Specializations,
371+
CorrectInsertPos,
372+
SETraits::getTemplateArgs(Entry)) &&
408373
InsertPos == CorrectInsertPos &&
409374
"given incorrect InsertPos for specialization");
410375
#endif
@@ -478,14 +443,12 @@ FunctionTemplateDecl::getSpecializations() const {
478443
FunctionDecl *
479444
FunctionTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
480445
void *&InsertPos) {
481-
auto *Common = getCommonPtr();
482-
return findSpecializationImpl(Common->Specializations, InsertPos, Args);
446+
return findSpecializationImpl(getSpecializations(), InsertPos, Args);
483447
}
484448

485449
void FunctionTemplateDecl::addSpecialization(
486450
FunctionTemplateSpecializationInfo *Info, void *InsertPos) {
487-
auto *Common = getCommonPtr();
488-
addSpecializationImpl<FunctionTemplateDecl>(Common->Specializations, Info,
451+
addSpecializationImpl<FunctionTemplateDecl>(getSpecializations(), Info,
489452
InsertPos);
490453
}
491454

@@ -545,9 +508,8 @@ ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
545508
DeclarationName(), nullptr, nullptr);
546509
}
547510

548-
void ClassTemplateDecl::LoadLazySpecializations(
549-
bool OnlyPartial/*=false*/) const {
550-
loadLazySpecializationsImpl(OnlyPartial);
511+
void ClassTemplateDecl::LoadLazySpecializations() const {
512+
loadLazySpecializationsImpl();
551513
}
552514

553515
llvm::FoldingSetVector<ClassTemplateSpecializationDecl> &
@@ -558,7 +520,7 @@ ClassTemplateDecl::getSpecializations() const {
558520

559521
llvm::FoldingSetVector<ClassTemplatePartialSpecializationDecl> &
560522
ClassTemplateDecl::getPartialSpecializations() const {
561-
LoadLazySpecializations(/*PartialOnly = */ true);
523+
LoadLazySpecializations();
562524
return getCommonPtr()->PartialSpecializations;
563525
}
564526

@@ -572,15 +534,12 @@ ClassTemplateDecl::newCommon(ASTContext &C) const {
572534
ClassTemplateSpecializationDecl *
573535
ClassTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
574536
void *&InsertPos) {
575-
auto *Common = getCommonPtr();
576-
return findSpecializationImpl(Common->Specializations, InsertPos, Args);
537+
return findSpecializationImpl(getSpecializations(), InsertPos, Args);
577538
}
578539

579540
void ClassTemplateDecl::AddSpecialization(ClassTemplateSpecializationDecl *D,
580541
void *InsertPos) {
581-
auto *Common = getCommonPtr();
582-
addSpecializationImpl<ClassTemplateDecl>(Common->Specializations, D,
583-
InsertPos);
542+
addSpecializationImpl<ClassTemplateDecl>(getSpecializations(), D, InsertPos);
584543
}
585544

586545
ClassTemplatePartialSpecializationDecl *
@@ -925,14 +884,6 @@ TemplateArgumentList::CreateCopy(ASTContext &Context,
925884
return new (Mem) TemplateArgumentList(Args);
926885
}
927886

928-
unsigned TemplateArgumentList::ComputeODRHash(ArrayRef<TemplateArgument> Args) {
929-
ODRHash Hasher;
930-
for (TemplateArgument TA : Args)
931-
Hasher.AddTemplateArgument(TA);
932-
933-
return Hasher.CalculateHash();
934-
}
935-
936887
FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create(
937888
ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
938889
TemplateSpecializationKind TSK, const TemplateArgumentList *TemplateArgs,
@@ -1275,9 +1226,8 @@ VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
12751226
DeclarationName(), nullptr, nullptr);
12761227
}
12771228

1278-
void VarTemplateDecl::LoadLazySpecializations(
1279-
bool OnlyPartial/*=false*/) const {
1280-
loadLazySpecializationsImpl(OnlyPartial);
1229+
void VarTemplateDecl::LoadLazySpecializations() const {
1230+
loadLazySpecializationsImpl();
12811231
}
12821232

12831233
llvm::FoldingSetVector<VarTemplateSpecializationDecl> &
@@ -1288,7 +1238,7 @@ VarTemplateDecl::getSpecializations() const {
12881238

12891239
llvm::FoldingSetVector<VarTemplatePartialSpecializationDecl> &
12901240
VarTemplateDecl::getPartialSpecializations() const {
1291-
LoadLazySpecializations(/*PartialOnly = */ true);
1241+
LoadLazySpecializations();
12921242
return getCommonPtr()->PartialSpecializations;
12931243
}
12941244

@@ -1302,14 +1252,12 @@ VarTemplateDecl::newCommon(ASTContext &C) const {
13021252
VarTemplateSpecializationDecl *
13031253
VarTemplateDecl::findSpecialization(ArrayRef<TemplateArgument> Args,
13041254
void *&InsertPos) {
1305-
auto *Common = getCommonPtr();
1306-
return findSpecializationImpl(Common->Specializations, InsertPos, Args);
1255+
return findSpecializationImpl(getSpecializations(), InsertPos, Args);
13071256
}
13081257

13091258
void VarTemplateDecl::AddSpecialization(VarTemplateSpecializationDecl *D,
13101259
void *InsertPos) {
1311-
auto *Common = getCommonPtr();
1312-
addSpecializationImpl<VarTemplateDecl>(Common->Specializations, D, InsertPos);
1260+
addSpecializationImpl<VarTemplateDecl>(getSpecializations(), D, InsertPos);
13131261
}
13141262

13151263
VarTemplatePartialSpecializationDecl *

Diff for: interpreter/llvm-project/clang/lib/AST/ODRHash.cpp

-15
Original file line numberDiff line numberDiff line change
@@ -812,21 +812,6 @@ void ODRHash::AddDecl(const Decl *D) {
812812
for (const TemplateArgument &TA : List.asArray())
813813
AddTemplateArgument(TA);
814814
}
815-
816-
// If this was a specialization we should take into account its template
817-
// arguments. This helps to reduce collisions coming when visiting template
818-
// specialization types (eg. when processing type template arguments).
819-
ArrayRef<TemplateArgument> Args;
820-
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
821-
Args = CTSD->getTemplateArgs().asArray();
822-
else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
823-
Args = VTSD->getTemplateArgs().asArray();
824-
else if (auto *FD = dyn_cast<FunctionDecl>(D))
825-
if (FD->getTemplateSpecializationArgs())
826-
Args = FD->getTemplateSpecializationArgs()->asArray();
827-
828-
for (auto &TA : Args)
829-
AddTemplateArgument(TA);
830815
}
831816

832817
namespace {

Diff for: interpreter/llvm-project/clang/lib/Serialization/ASTReader.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -7602,23 +7602,14 @@ void ASTReader::CompleteRedeclChain(const Decl *D) {
76027602
}
76037603
}
76047604

7605-
RedeclarableTemplateDecl *Template = nullptr;
7606-
ArrayRef<TemplateArgument> Args;
7607-
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) {
7608-
Template = CTSD->getSpecializedTemplate();
7609-
Args = CTSD->getTemplateArgs().asArray();
7610-
} else if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
7611-
Template = VTSD->getSpecializedTemplate();
7612-
Args = VTSD->getTemplateArgs().asArray();
7613-
} else if (auto *FD = dyn_cast<FunctionDecl>(D)) {
7614-
if (auto *Tmplt = FD->getPrimaryTemplate()) {
7615-
Template = Tmplt;
7616-
Args = FD->getTemplateSpecializationArgs()->asArray();
7617-
}
7618-
}
7619-
7620-
if (Template)
7621-
Template->loadLazySpecializationsImpl(Args);
7605+
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D))
7606+
CTSD->getSpecializedTemplate()->LoadLazySpecializations();
7607+
if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D))
7608+
VTSD->getSpecializedTemplate()->LoadLazySpecializations();
7609+
if (auto *FD = dyn_cast<FunctionDecl>(D)) {
7610+
if (auto *Template = FD->getPrimaryTemplate())
7611+
Template->LoadLazySpecializations();
7612+
}
76227613
}
76237614

76247615
CXXCtorInitializer **

0 commit comments

Comments
 (0)