<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 26, 2015 at 7:40 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rsmith<br>
Date: Thu Feb 26 21:40:09 2015<br>
New Revision: 230727<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=230727&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=230727&view=rev</a><br>
Log:<br>
[modules] Don't write out name lookup table entries merely because the module<br>
happened to query them; only write them out if something new was added.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/AST/DeclContextInternals.h<br>
    cfe/trunk/include/clang/Serialization/ASTWriter.h<br>
    cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/DeclContextInternals.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclContextInternals.h?rev=230727&r1=230726&r2=230727&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclContextInternals.h?rev=230727&r1=230726&r2=230727&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/AST/DeclContextInternals.h (original)<br>
+++ cfe/trunk/include/clang/AST/DeclContextInternals.h Thu Feb 26 21:40:09 2015<br>
@@ -78,6 +78,17 @@ public:<br>
     return getAsVectorAndHasExternal().getPointer();<br>
   }<br>
<br>
+  bool hasLocalDecls() const {<br>
+    if (NamedDecl *Singleton = getAsDecl()) {<br>
+      return !Singleton->isFromASTFile();<br>
+    } else if (DeclsTy *Vec = getAsVector()) {<br></blockquote><div><br>else after return (& braces on a single-line block)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+      for (auto *D : *Vec)<br>
+        if (!D->isFromASTFile())<br>
+          return true;<br></blockquote><div><br>Looks a bit like std::any_of? (maybe not worth it, I dunno)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+    }<br>
+    return false;<br>
+  }<br>
+<br>
   bool hasExternalDecls() const {<br>
     return getAsVectorAndHasExternal().getInt();<br>
   }<br>
<br>
Modified: cfe/trunk/include/clang/Serialization/ASTWriter.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=230727&r1=230726&r2=230727&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTWriter.h?rev=230727&r1=230726&r2=230727&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Serialization/ASTWriter.h (original)<br>
+++ cfe/trunk/include/clang/Serialization/ASTWriter.h Thu Feb 26 21:40:09 2015<br>
@@ -477,6 +477,9 @@ private:<br>
   void WriteTypeAbbrevs();<br>
   void WriteType(QualType T);<br>
<br>
+  template<typename Visitor><br>
+  void visitLocalLookupResults(const DeclContext *DC, Visitor AddLookupResult);<br>
+<br>
   uint32_t GenerateNameLookupTable(const DeclContext *DC,<br>
                                    llvm::SmallVectorImpl<char> &LookupTable);<br>
   uint64_t WriteDeclContextLexicalBlock(ASTContext &Context, DeclContext *DC);<br>
<br>
Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=230727&r1=230726&r2=230727&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=230727&r1=230726&r2=230727&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)<br>
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Feb 26 21:40:09 2015<br>
@@ -3663,17 +3663,22 @@ public:<br>
 } // end anonymous namespace<br>
<br>
 template<typename Visitor><br>
-static void visitLocalLookupResults(const DeclContext *ConstDC,<br>
-                                    bool NeedToReconcileExternalVisibleStorage,<br>
-                                    Visitor AddLookupResult) {<br>
+void ASTWriter::visitLocalLookupResults(const DeclContext *ConstDC,<br>
+                                        Visitor AddLookupResult) {<br>
   // FIXME: We need to build the lookups table, which is logically const.<br>
   DeclContext *DC = const_cast<DeclContext*>(ConstDC);<br>
   assert(DC == DC->getPrimaryContext() && "only primary DC has lookup table");<br>
<br>
   SmallVector<DeclarationName, 16> ExternalNames;<br>
   for (auto &Lookup : *DC->buildLookup()) {<br>
+    // If there are no local declarations in our lookup result, we don't<br>
+    // need to write an entry for the name at all unless we're rewriting<br>
+    // the decl context.<br>
+    if (!Lookup.second.hasLocalDecls() && !isRewritten(cast<Decl>(DC)))<br>
+      continue;<br>
+<br>
     if (Lookup.second.hasExternalDecls() ||<br>
-        NeedToReconcileExternalVisibleStorage) {<br>
+        DC->NeedToReconcileExternalVisibleStorage) {<br>
       // We don't know for sure what declarations are found by this name,<br>
       // because the external source might have a different set from the set<br>
       // that are in the lookup map, and we can't update it now without<br>
@@ -3697,9 +3702,8 @@ static void visitLocalLookupResults(cons<br>
 void ASTWriter::AddUpdatedDeclContext(const DeclContext *DC) {<br>
   if (UpdatedDeclContexts.insert(DC).second && WritingAST) {<br>
     // Ensure we emit all the visible declarations.<br>
-    visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,<br>
-                            [&](DeclarationName Name,<br>
-                                DeclContext::lookup_result Result) {<br>
+    visitLocalLookupResults(DC, [&](DeclarationName Name,<br>
+                                    DeclContext::lookup_result Result) {<br>
       for (auto *Decl : Result)<br>
         GetDeclRef(getDeclForLocalLookup(getLangOpts(), Decl));<br>
     });<br>
@@ -3721,9 +3725,8 @@ ASTWriter::GenerateNameLookupTable(const<br>
   SmallVector<NamedDecl *, 8> ConstructorDecls;<br>
   SmallVector<NamedDecl *, 4> ConversionDecls;<br>
<br>
-  visitLocalLookupResults(DC, DC->NeedToReconcileExternalVisibleStorage,<br>
-                          [&](DeclarationName Name,<br>
-                              DeclContext::lookup_result Result) {<br>
+  visitLocalLookupResults(DC, [&](DeclarationName Name,<br>
+                                  DeclContext::lookup_result Result) {<br>
     if (Result.empty())<br>
       return;<br>
<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>