<div dir="ltr">On Wed, Sep 4, 2013 at 6:32 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="im">On Wed, Sep 4, 2013 at 6:07 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br>
</div><div class="gmail_extra"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">With this commit, I'm hitting the following assertion:<div>

<br></div><div><p style="margin:0px;font-size:11px;font-family:Menlo">Assertion failed: (!WritingAST && "Already writing the AST!"), function DeclarationMarkedUsed, file /Volumes/storage/llvm/tools/clang/lib/Serialization/ASTWriter.cpp, line 5376.</p>


</div><div><br></div><div>(Unfortunately, it's going to be a bit difficult to reduce.)</div><div><br></div>Basically, what happens is that ASTWriter::WriteASTCore() calls ASTReader::updateOutOfDateIdentifier(), which eventually calls ASTDeclReader::UpdateDecl, which explodes because we're updating the AST in the middle of writing it.<div>


<br></div><div>What do you think of moving the loop which call updateOutOfDateIdentifier out into ASTWriter::WriteAST, before we set WritingAST to true?</div></div></blockquote><div><br></div></div><div>No objection to that change, but I'm pretty sure there are other parts of the AST writer that trigger deserialization of AST nodes. Another possibility:</div>
<div class="im">
<div><br></div><div><div>+    case UPD_DECL_MARKED_USED: {</div><div>+      D->markUsed(Reader.getContext());</div><div>+      break;</div></div><div><br></div></div><div>Do you need to use markUsed here, rather than setIsUsed? We already have an appropriate update record for this declaration in whichever AST file we're loading.</div>
<div><div class="h5">
<div> </div><div><br></div></div></div></div></div></div></blockquote><div><br></div><div>I'm not sure I really understand how this needs to work.  I mean, the ASTWriter doesn't really care if it doesn't get notified: any update record has to come from a file which the file its writing depends on.  On the other hand, other users of ASTMutationListener (are the any?) might care: if the decl got deserialized before the AST file with the update was included, they might miss an update caused by loading an AST file.</div>
<div><br></div><div>-Eli</div></div></div></div>