]> granicus.if.org Git - clang/commitdiff
Make the deserialization of Sema::PendingInstantiations lazy. At this
authorDouglas Gregor <dgregor@apple.com>
Thu, 28 Jul 2011 19:49:54 +0000 (19:49 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 28 Jul 2011 19:49:54 +0000 (19:49 +0000)
point, ASTReader::InitializeSema() has very little interesting work,
*except* issues stemming from preloaded declarations. That's something
we'll still need to cope with.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@136378 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Sema/ExternalSemaSource.h
include/clang/Serialization/ASTReader.h
lib/Sema/SemaTemplateInstantiateDecl.cpp
lib/Serialization/ASTReader.cpp

index 00494641ba7002e2a853c1c30e735c413a347278..7b83625fa332884a0045b32d2fa0b70ae256f126 100644 (file)
@@ -27,6 +27,7 @@ struct ObjCMethodList;
 class Scope;
 class Sema;
 class TypedefNameDecl;
+class ValueDecl;
 class VarDecl;
   
 /// \brief A simple structure that captures a vtable use for the purposes of
@@ -162,6 +163,17 @@ public:
   /// source should take care not to introduce the same vtables repeatedly.
   virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {}
 
+  /// \brief Read the set of pending instantiations known to the external
+  /// Sema source.
+  ///
+  /// The external source should append its own pending instantiations to the
+  /// given vector. Note that this routine may be invoked multiple times; the
+  /// external source should take care not to introduce the same instantiations
+  /// repeatedly.
+  virtual void ReadPendingInstantiations(
+                 SmallVectorImpl<std::pair<ValueDecl *, 
+                                           SourceLocation> > &Pending) {}
+
   // isa/cast/dyn_cast support
   static bool classof(const ExternalASTSource *Source) {
     return Source->SemaSource;
index 7af22548db8621e51ff11020a35c7ed3e00813ca..bd2115039f61f2f06ccb5c45e93c2db56698fc9b 100644 (file)
@@ -1406,6 +1406,10 @@ public:
 
   virtual void ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables);
 
+  virtual void ReadPendingInstantiations(
+                 SmallVectorImpl<std::pair<ValueDecl *, 
+                                           SourceLocation> > &Pending);
+
   /// \brief Load a selector from disk, registering its ID if it exists.
   void LoadSelector(Selector Sel);
 
index 41818d329c2169c77dd96cecbb40139d87aa5fe9..872bb874571d760d0522424ff5fbd77408d1acf2 100644 (file)
@@ -3229,6 +3229,14 @@ NamedDecl *Sema::FindInstantiatedDecl(SourceLocation Loc, NamedDecl *D,
 /// \brief Performs template instantiation for all implicit template
 /// instantiations we have seen until this point.
 void Sema::PerformPendingInstantiations(bool LocalOnly) {
+  // Load pending instantiations from the external source.
+  if (!LocalOnly && ExternalSource) {
+    SmallVector<std::pair<ValueDecl *, SourceLocation>, 4> Pending;
+    ExternalSource->ReadPendingInstantiations(Pending);
+    PendingInstantiations.insert(PendingInstantiations.begin(),
+                                 Pending.begin(), Pending.end());
+  }
+  
   while (!PendingLocalImplicitInstantiations.empty() ||
          (!LocalOnly && !PendingInstantiations.empty())) {
     PendingImplicitInstantiation Inst;
index eced16a6ca734f0344cbad06a3ecd222253d4b28..acd31c9a64adf7a19db6703939cdaaa891642bd7 100644 (file)
@@ -4405,15 +4405,6 @@ void ASTReader::InitializeSema(Sema &S) {
       SemaObj->StdBadAlloc = SemaDeclRefs[1];
   }
 
-  // If there were any pending implicit instantiations, deserialize them
-  // and add them to Sema's queue of such instantiations.
-  for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) {
-    ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));
-    SourceLocation Loc
-      = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);
-    SemaObj->PendingInstantiations.push_back(std::make_pair(D, Loc));
-  }
-
   if (!FPPragmaOptions.empty()) {
     assert(FPPragmaOptions.size() == 1 && "Wrong number of FP_PRAGMA_OPTIONS");
     SemaObj->FPFeatures.fp_contract = FPPragmaOptions[0];
@@ -4660,6 +4651,17 @@ void ASTReader::ReadUsedVTables(SmallVectorImpl<ExternalVTableUse> &VTables) {
   VTableUses.clear();
 }
 
+void ASTReader::ReadPendingInstantiations(
+       SmallVectorImpl<std::pair<ValueDecl *, SourceLocation> > &Pending) {
+  for (unsigned Idx = 0, N = PendingInstantiations.size(); Idx < N;) {
+    ValueDecl *D = cast<ValueDecl>(GetDecl(PendingInstantiations[Idx++]));
+    SourceLocation Loc
+      = SourceLocation::getFromRawEncoding(PendingInstantiations[Idx++]);
+    Pending.push_back(std::make_pair(D, Loc));
+  }  
+  PendingInstantiations.clear();
+}
+
 void ASTReader::LoadSelector(Selector Sel) {
   // It would be complicated to avoid reading the methods anyway. So don't.
   ReadMethodPool(Sel);