@@ -362,63 +362,30 @@ void RedeclarableTemplateDecl::loadLazySpecializationsImpl(
362362 ExternalSource->LoadExternalSpecializations (this ->getCanonicalDecl (),
363363 OnlyPartial);
364364 return ;
365-
366- // Grab the most recent declaration to ensure we've loaded any lazy
367- // redeclarations of this template.
368- CommonBase *CommonBasePtr = getMostRecentDecl ()->getCommonPtr ();
369- if (auto *Specs = CommonBasePtr->LazySpecializations ) {
370- if (!OnlyPartial)
371- CommonBasePtr->LazySpecializations = nullptr ;
372- unsigned N = Specs[0 ].DeclID .getRawValue ();
373- for (unsigned I = 0 ; I != N; ++I) {
374- // Skip over already loaded specializations.
375- if (!Specs[I + 1 ].ODRHash )
376- continue ;
377- if (!OnlyPartial || Specs[I + 1 ].IsPartial )
378- (void )loadLazySpecializationImpl (Specs[I + 1 ]);
379- }
380- }
381- }
382-
383- Decl *RedeclarableTemplateDecl::loadLazySpecializationImpl (
384- LazySpecializationInfo &LazySpecInfo) const {
385- llvm_unreachable (" We don't use LazySpecializationInfo any more" );
386-
387- GlobalDeclID ID = LazySpecInfo.DeclID ;
388- assert (ID.isValid () && " Loading already loaded specialization!" );
389- // Note that we loaded the specialization.
390- LazySpecInfo.DeclID = GlobalDeclID ();
391- LazySpecInfo.ODRHash = LazySpecInfo.IsPartial = 0 ;
392- return getASTContext ().getExternalSource ()->GetExternalDecl (ID);
393365}
394366
395- void RedeclarableTemplateDecl::loadLazySpecializationsImpl (
367+ bool RedeclarableTemplateDecl::loadLazySpecializationsImpl (
396368 ArrayRef<TemplateArgument> Args, TemplateParameterList *TPL) const {
397369 auto *ExternalSource = getASTContext ().getExternalSource ();
398370 if (!ExternalSource)
399- return ;
371+ return false ;
400372
401- ExternalSource->LoadExternalSpecializations (this ->getCanonicalDecl (), Args);
402- return ;
373+ // If TPL is not null, it implies that we're loading specializations for
374+ // partial templates. We need to load all specializations in such cases.
375+ if (TPL)
376+ return ExternalSource->LoadExternalSpecializations (this ->getCanonicalDecl (),
377+ /* OnlyPartial=*/ false );
403378
404- CommonBase *CommonBasePtr = getMostRecentDecl ()->getCommonPtr ();
405- if (auto *Specs = CommonBasePtr->LazySpecializations ) {
406- unsigned Hash = TemplateArgumentList::ComputeODRHash (Args);
407- unsigned N = Specs[0 ].DeclID .getRawValue ();
408- for (unsigned I = 0 ; I != N; ++I)
409- if (Specs[I + 1 ].ODRHash && Specs[I + 1 ].ODRHash == Hash)
410- (void )loadLazySpecializationImpl (Specs[I + 1 ]);
411- }
379+ return ExternalSource->LoadExternalSpecializations (this ->getCanonicalDecl (),
380+ Args);
412381}
413382
414- template <class EntryType , typename ... ProfileArguments>
383+ template <class EntryType , typename ... ProfileArguments>
415384typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
416- RedeclarableTemplateDecl::findSpecializationImpl (
385+ RedeclarableTemplateDecl::findSpecializationLocally (
417386 llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
418- ProfileArguments&&... ProfileArgs) {
419- using SETraits = SpecEntryTraits<EntryType>;
420-
421- loadLazySpecializationsImpl (std::forward<ProfileArguments>(ProfileArgs)...);
387+ ProfileArguments &&...ProfileArgs) {
388+ using SETraits = RedeclarableTemplateDecl::SpecEntryTraits<EntryType>;
422389
423390 llvm::FoldingSetNodeID ID;
424391 EntryType::Profile (ID, std::forward<ProfileArguments>(ProfileArgs)...,
@@ -427,6 +394,24 @@ RedeclarableTemplateDecl::findSpecializationImpl(
427394 return Entry ? SETraits::getDecl (Entry)->getMostRecentDecl () : nullptr ;
428395}
429396
397+ template <class EntryType , typename ... ProfileArguments>
398+ typename RedeclarableTemplateDecl::SpecEntryTraits<EntryType>::DeclType *
399+ RedeclarableTemplateDecl::findSpecializationImpl (
400+ llvm::FoldingSetVector<EntryType> &Specs, void *&InsertPos,
401+ ProfileArguments &&...ProfileArgs) {
402+
403+ if (auto *Found = findSpecializationLocally (
404+ Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...))
405+ return Found;
406+
407+ if (!loadLazySpecializationsImpl (
408+ std::forward<ProfileArguments>(ProfileArgs)...))
409+ return nullptr ;
410+
411+ return findSpecializationLocally (
412+ Specs, InsertPos, std::forward<ProfileArguments>(ProfileArgs)...);
413+ }
414+
430415template <class Derived , class EntryType >
431416void RedeclarableTemplateDecl::addSpecializationImpl (
432417 llvm::FoldingSetVector<EntryType> &Specializations, EntryType *Entry,
@@ -955,14 +940,6 @@ TemplateArgumentList::CreateCopy(ASTContext &Context,
955940 return new (Mem) TemplateArgumentList (Args);
956941}
957942
958- unsigned TemplateArgumentList::ComputeODRHash (ArrayRef<TemplateArgument> Args) {
959- ODRHash Hasher;
960- for (TemplateArgument TA : Args)
961- Hasher.AddTemplateArgument (TA);
962-
963- return Hasher.CalculateHash ();
964- }
965-
966943FunctionTemplateSpecializationInfo *FunctionTemplateSpecializationInfo::Create (
967944 ASTContext &C, FunctionDecl *FD, FunctionTemplateDecl *Template,
968945 TemplateSpecializationKind TSK, TemplateArgumentList *TemplateArgs,
0 commit comments