<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Aug 15, 2014 at 3:29 PM, Nico Weber <span dir="ltr"><<a href="mailto:nicolasweber@gmx.de" target="_blank">nicolasweber@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: nico<br>
Date: Fri Aug 15 17:29:14 2014<br>
New Revision: 215780<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=215780&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=215780&view=rev</a><br>
Log:<br>
Add a RAII class for saving and restoring instantiations and uses. No behavior change.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/Sema/Sema.h<br>
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
<br>
Modified: cfe/trunk/include/clang/Sema/Sema.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=215780&r1=215779&r2=215780&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=215780&r1=215779&r2=215780&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/include/clang/Sema/Sema.h (original)<br>
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Aug 15 17:29:14 2014<br>
@@ -6568,6 +6568,31 @@ public:<br>
   /// but have not yet been performed.<br>
   std::deque<PendingImplicitInstantiation> PendingInstantiations;<br>
<br>
+  class SavePendingInstantiationsAndVTableUsesRAII {<br>
+  public:<br>
+    SavePendingInstantiationsAndVTableUsesRAII(Sema &S): S(S) {<br>
+      SavedPendingInstantiations.swap(S.PendingInstantiations);<br>
+      SavedVTableUses.swap(S.VTableUses);<br>
+    }<br>
+<br>
+    ~SavePendingInstantiationsAndVTableUsesRAII() {<br>
+      // Restore the set of pending vtables.<br>
+      assert(S.VTableUses.empty() &&<br>
+             "VTableUses should be empty before it is discarded.");<br>
+      S.VTableUses.swap(SavedVTableUses);<br>
+<br>
+      // Restore the set of pending implicit instantiations.<br>
+      assert(S.PendingInstantiations.empty() &&<br>
+             "PendingInstantiations should be empty before it is discarded.");<br>
+      S.PendingInstantiations.swap(SavedPendingInstantiations);<br>
+    }<br>
+<br>
+  private:<br>
+    Sema &S;<br>
+    SmallVector<VTableUse, 16> SavedVTableUses;<br>
+    std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;<br>
+  };<br>
+<br>
   /// \brief The queue of implicit template instantiations that are required<br>
   /// and must be performed within the current local scope.<br>
   ///<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=215780&r1=215779&r2=215780&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=215780&r1=215779&r2=215780&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Fri Aug 15 17:29:14 2014<br>
@@ -3389,13 +3389,13 @@ void Sema::InstantiateFunctionDefinition<br>
   // If we're performing recursive template instantiation, create our own<br>
   // queue of pending implicit instantiations that we will instantiate later,<br>
   // while we're still within our own instantiation context.<br>
-  SmallVector<VTableUse, 16> SavedVTableUses;<br>
-  std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;<br>
   SavePendingLocalImplicitInstantiationsRAII<br>
       SavedPendingLocalImplicitInstantiations(*this);<br>
+  std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII><br>
+      SavePendingInstantiationsAndVTableUses;<br>
   if (Recursive) {<br>
-    VTableUses.swap(SavedVTableUses);<br>
-    PendingInstantiations.swap(SavedPendingInstantiations);<br>
+    SavePendingInstantiationsAndVTableUses.reset(<br>
+        new SavePendingInstantiationsAndVTableUsesRAII(*this));<br></blockquote><div><br></div><div>It seems wasteful to go to the heap for this each time; maybe instead pass a flag to the RAII object to tell it whether to do this save/load instead?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   }<br>
<br>
   EnterExpressionEvaluationContext EvalContext(*this,<br>
@@ -3466,15 +3466,8 @@ void Sema::InstantiateFunctionDefinition<br>
     // instantiation of this template.<br>
     PerformPendingInstantiations();<br>
<br>
-    // Restore the set of pending vtables.<br>
-    assert(VTableUses.empty() &&<br>
-           "VTableUses should be empty before it is discarded.");<br>
-    VTableUses.swap(SavedVTableUses);<br>
-<br>
-    // Restore the set of pending implicit instantiations.<br>
-    assert(PendingInstantiations.empty() &&<br>
-           "PendingInstantiations should be empty before it is discarded.");<br>
-    PendingInstantiations.swap(SavedPendingInstantiations);<br>
+    // Restore PendingInstantiations and VTableUses.<br>
+    SavePendingInstantiationsAndVTableUses.reset();<br>
   }<br>
 }<br>
<br>
@@ -3790,11 +3783,11 @@ void Sema::InstantiateVariableDefinition<br>
       // If we're performing recursive template instantiation, create our own<br>
       // queue of pending implicit instantiations that we will instantiate<br>
       // later, while we're still within our own instantiation context.<br>
-      SmallVector<VTableUse, 16> SavedVTableUses;<br>
-      std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;<br>
+      std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII><br>
+          SavePendingInstantiationsAndVTableUses;<br>
       if (Recursive) {<br>
-        VTableUses.swap(SavedVTableUses);<br>
-        PendingInstantiations.swap(SavedPendingInstantiations);<br>
+        SavePendingInstantiationsAndVTableUses.reset(<br>
+            new SavePendingInstantiationsAndVTableUsesRAII(*this));<br>
       }<br>
<br>
       LocalInstantiationScope Local(*this);<br>
@@ -3822,15 +3815,8 @@ void Sema::InstantiateVariableDefinition<br>
         // instantiation of this template.<br>
         PerformPendingInstantiations();<br>
<br>
-        // Restore the set of pending vtables.<br>
-        assert(VTableUses.empty() &&<br>
-               "VTableUses should be empty before it is discarded.");<br>
-        VTableUses.swap(SavedVTableUses);<br>
-<br>
-        // Restore the set of pending implicit instantiations.<br>
-        assert(PendingInstantiations.empty() &&<br>
-               "PendingInstantiations should be empty before it is discarded.");<br>
-        PendingInstantiations.swap(SavedPendingInstantiations);<br>
+        // Restore PendingInstantiations and VTableUses.<br>
+        SavePendingInstantiationsAndVTableUses.reset();<br>
       }<br>
     }<br>
<br>
@@ -3914,13 +3900,13 @@ void Sema::InstantiateVariableDefinition<br>
   // If we're performing recursive template instantiation, create our own<br>
   // queue of pending implicit instantiations that we will instantiate later,<br>
   // while we're still within our own instantiation context.<br>
-  SmallVector<VTableUse, 16> SavedVTableUses;<br>
-  std::deque<PendingImplicitInstantiation> SavedPendingInstantiations;<br>
   SavePendingLocalImplicitInstantiationsRAII<br>
       SavedPendingLocalImplicitInstantiations(*this);<br>
+  std::unique_ptr<SavePendingInstantiationsAndVTableUsesRAII><br>
+      SavePendingInstantiationsAndVTableUses;<br>
   if (Recursive) {<br>
-    VTableUses.swap(SavedVTableUses);<br>
-    PendingInstantiations.swap(SavedPendingInstantiations);<br>
+    SavePendingInstantiationsAndVTableUses.reset(<br>
+        new SavePendingInstantiationsAndVTableUsesRAII(*this));<br>
   }<br>
<br>
   // Enter the scope of this instantiation. We don't use<br>
@@ -3987,15 +3973,8 @@ void Sema::InstantiateVariableDefinition<br>
     // instantiation of this template.<br>
     PerformPendingInstantiations();<br>
<br>
-    // Restore the set of pending vtables.<br>
-    assert(VTableUses.empty() &&<br>
-           "VTableUses should be empty before it is discarded.");<br>
-    VTableUses.swap(SavedVTableUses);<br>
-<br>
-    // Restore the set of pending implicit instantiations.<br>
-    assert(PendingInstantiations.empty() &&<br>
-           "PendingInstantiations should be empty before it is discarded.");<br>
-    PendingInstantiations.swap(SavedPendingInstantiations);<br>
+    // Restore PendingInstantiations and VTableUses.<br>
+    SavePendingInstantiationsAndVTableUses.reset();<br>
   }<br>
 }<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>