From 0a3c6cd90083505e667fad2092600e66ef9bc5dd Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Fri, 27 Feb 2015 03:40:09 +0000 Subject: [PATCH] [modules] Don't write out name lookup table entries merely because the module happened to query them; only write them out if something new was added. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@230727 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/DeclContextInternals.h | 11 +++++++++++ include/clang/Serialization/ASTWriter.h | 3 +++ lib/Serialization/ASTWriter.cpp | 23 +++++++++++++---------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/clang/AST/DeclContextInternals.h b/include/clang/AST/DeclContextInternals.h index ff37758c25..f83dd026b0 100644 --- a/include/clang/AST/DeclContextInternals.h +++ b/include/clang/AST/DeclContextInternals.h @@ -78,6 +78,17 @@ public: return getAsVectorAndHasExternal().getPointer(); } + bool hasLocalDecls() const { + if (NamedDecl *Singleton = getAsDecl()) { + return !Singleton->isFromASTFile(); + } else if (DeclsTy *Vec = getAsVector()) { + for (auto *D : *Vec) + if (!D->isFromASTFile()) + return true; + } + return false; + } + bool hasExternalDecls() const { return getAsVectorAndHasExternal().getInt(); } diff --git a/include/clang/Serialization/ASTWriter.h b/include/clang/Serialization/ASTWriter.h index 1d2fa556e2..bf7c2605b9 100644 --- a/include/clang/Serialization/ASTWriter.h +++ b/include/clang/Serialization/ASTWriter.h @@ -477,6 +477,9 @@ private: void WriteTypeAbbrevs(); void WriteType(QualType T); + template + void visitLocalLookupResults(const DeclContext *DC, Visitor AddLookupResult); + uint32_t GenerateNameLookupTable(const DeclContext *DC, llvm::SmallVectorImpl &LookupTable); uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC); diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 3af2a4003b..c70935c0c7 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3663,17 +3663,22 @@ public: } // end anonymous namespace template -static void visitLocalLookupResults(const DeclContext *ConstDC, - bool NeedToReconcileExternalVisibleStorage, - Visitor AddLookupResult) { +void ASTWriter::visitLocalLookupResults(const DeclContext *ConstDC, + Visitor AddLookupResult) { // FIXME: We need to build the lookups table, which is logically const. DeclContext *DC = const_cast(ConstDC); assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table"); SmallVector ExternalNames; for (auto &Lookup : *DC->buildLookup()) { + // If there are no local declarations in our lookup result, we don't + // need to write an entry for the name at all unless we're rewriting + // the decl context. + if (!Lookup.second.hasLocalDecls() && !isRewritten(cast(DC))) + continue; + if (Lookup.second.hasExternalDecls() || - NeedToReconcileExternalVisibleStorage) { + DC->NeedToReconcileExternalVisibleStorage) { // We don't know for sure what declarations are found by this name, // because the external source might have a different set from the set // that are in the lookup map, and we can't update it now without @@ -3697,9 +3702,8 @@ static void visitLocalLookupResults(const DeclContext *ConstDC, void ASTWriter::AddUpdatedDeclContext(const DeclContext *DC) { if (UpdatedDeclContexts.insert(DC).second && WritingAST) { // Ensure we emit all the visible declarations. - visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage, - [&](DeclarationName Name, - DeclContext::lookup_result Result) { + visitLocalLookupResults(DC, [&](DeclarationName Name, + DeclContext::lookup_result Result) { for (auto *Decl : Result) GetDeclRef(getDeclForLocalLookup(getLangOpts(), Decl)); }); @@ -3721,9 +3725,8 @@ ASTWriter::GenerateNameLookupTable(const DeclContext *DC, SmallVector ConstructorDecls; SmallVector ConversionDecls; - visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage, - [&](DeclarationName Name, - DeclContext::lookup_result Result) { + visitLocalLookupResults(DC, [&](DeclarationName Name, + DeclContext::lookup_result Result) { if (Result.empty()) return; -- 2.40.0