Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 0a3c6cd

Browse files
committed
[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
1 parent 3bb6fcf commit 0a3c6cd

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Diff for: include/clang/AST/DeclContextInternals.h

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ struct StoredDeclsList {
7878
return getAsVectorAndHasExternal().getPointer();
7979
}
8080

81+
bool hasLocalDecls() const {
82+
if (NamedDecl *Singleton = getAsDecl()) {
83+
return !Singleton->isFromASTFile();
84+
} else if (DeclsTy *Vec = getAsVector()) {
85+
for (auto *D : *Vec)
86+
if (!D->isFromASTFile())
87+
return true;
88+
}
89+
return false;
90+
}
91+
8192
bool hasExternalDecls() const {
8293
return getAsVectorAndHasExternal().getInt();
8394
}

Diff for: include/clang/Serialization/ASTWriter.h

+3
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ class ASTWriter : public ASTDeserializationListener,
477477
void WriteTypeAbbrevs();
478478
void WriteType(QualType T);
479479

480+
template<typename Visitor>
481+
void visitLocalLookupResults(const DeclContext *DC, Visitor AddLookupResult);
482+
480483
uint32_t GenerateNameLookupTable(const DeclContext *DC,
481484
llvm::SmallVectorImpl<char> &LookupTable);
482485
uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);

Diff for: lib/Serialization/ASTWriter.cpp

+13-10
Original file line numberDiff line numberDiff line change
@@ -3663,17 +3663,22 @@ class ASTDeclContextNameLookupTrait {
36633663
} // end anonymous namespace
36643664

36653665
template<typename Visitor>
3666-
static void visitLocalLookupResults(const DeclContext *ConstDC,
3667-
bool NeedToReconcileExternalVisibleStorage,
3668-
Visitor AddLookupResult) {
3666+
void ASTWriter::visitLocalLookupResults(const DeclContext *ConstDC,
3667+
Visitor AddLookupResult) {
36693668
// FIXME: We need to build the lookups table, which is logically const.
36703669
DeclContext *DC = const_cast<DeclContext*>(ConstDC);
36713670
assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table");
36723671

36733672
SmallVector<DeclarationName, 16> ExternalNames;
36743673
for (auto &Lookup : *DC->buildLookup()) {
3674+
// If there are no local declarations in our lookup result, we don't
3675+
// need to write an entry for the name at all unless we're rewriting
3676+
// the decl context.
3677+
if (!Lookup.second.hasLocalDecls() && !isRewritten(cast<Decl>(DC)))
3678+
continue;
3679+
36753680
if (Lookup.second.hasExternalDecls() ||
3676-
NeedToReconcileExternalVisibleStorage) {
3681+
DC->NeedToReconcileExternalVisibleStorage) {
36773682
// We don't know for sure what declarations are found by this name,
36783683
// because the external source might have a different set from the set
36793684
// that are in the lookup map, and we can't update it now without
@@ -3697,9 +3702,8 @@ static void visitLocalLookupResults(const DeclContext *ConstDC,
36973702
void ASTWriter::AddUpdatedDeclContext(const DeclContext *DC) {
36983703
if (UpdatedDeclContexts.insert(DC).second && WritingAST) {
36993704
// Ensure we emit all the visible declarations.
3700-
visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,
3701-
[&](DeclarationName Name,
3702-
DeclContext::lookup_result Result) {
3705+
visitLocalLookupResults(DC, [&](DeclarationName Name,
3706+
DeclContext::lookup_result Result) {
37033707
for (auto *Decl : Result)
37043708
GetDeclRef(getDeclForLocalLookup(getLangOpts(), Decl));
37053709
});
@@ -3721,9 +3725,8 @@ ASTWriter::GenerateNameLookupTable(const DeclContext *DC,
37213725
SmallVector<NamedDecl *, 8> ConstructorDecls;
37223726
SmallVector<NamedDecl *, 4> ConversionDecls;
37233727

3724-
visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,
3725-
[&](DeclarationName Name,
3726-
DeclContext::lookup_result Result) {
3728+
visitLocalLookupResults(DC, [&](DeclarationName Name,
3729+
DeclContext::lookup_result Result) {
37273730
if (Result.empty())
37283731
return;
37293732

0 commit comments

Comments
 (0)