<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 27 February 2017 at 11:11, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Reflected on this a bit more & realized that modular codegen shouldn't've been triggering this case anyway - it could only happen (I think) if a modular codegen decl was found dynamically while deserializing otehr things. That means the modular codegen decl wasn't in the modular codegen decls list.<br><br>So I changed the way the list is built (to not use isRequiredDecl, but to add things to the list in AddFunctionDefinition, right where the bit is set on the decl itself - so the list and the decl bits should never be out of sync) which avoids the need for other fixes.<br><br>Would it be worth checking in the missing Deserializing context and suggested assertion on principle anyway?</div></blockquote><div><br></div><div>It seems like we could get to the same issue any time loading a statement transitively adds a deferred action that results in loading another statement. I don't know if there are other codepaths that result in that happening, but it seems like that should be possible (without resulting in this issue), and we probably mostly avoid it because we usually load statements lazily.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><div class="gmail_quote"><div dir="ltr">On Fri, Feb 24, 2017 at 5:13 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978gmail_msg">On 24 February 2017 at 14:25, David Blaikie via cfe-dev <span dir="ltr" class="m_-4660032068075316978gmail_msg"><<a href="mailto:cfe-dev@lists.llvm.org" class="m_-4660032068075316978gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br class="m_-4660032068075316978gmail_msg"><blockquote class="gmail_quote m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-4660032068075316978gmail_msg">OK, sounds fair - so GetExternalDeclStmt needs at least a Deserializing object to defer deserialization further. Does it also need a SavedStreamPosition, do you think? I can't immediately think of how/why it might, but they seemed to be paired in other places.</div></blockquote><div class="m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978gmail_msg"></div></div></div></div><div dir="ltr" class="m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978gmail_msg"><div class="m_-4660032068075316978gmail_msg">I think this is an accurate summary:</div><div class="m_-4660032068075316978gmail_msg"> * You need a Deserializing object if you're going to deserialize (or more accurately, temporarily violate invariants, use global cursors, ...) and your caller might not be deserializing</div><div class="m_-4660032068075316978gmail_msg"> * You need a SavedStreamPosition object if you're going to use a global cursor and your caller might be deserializing</div><div class="m_-4660032068075316978gmail_msg">... so you'd see a pair of them whenever someone is using a global cursor and doesn't know whether their caller is deserializing.</div><div class="m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978gmail_msg"></div><div class="m_-4660032068075316978gmail_msg">I think GetExternalDeclStmt doesn't need a SavedStreamPosition, but should assert that NumCurrentElementsDeserializin<wbr>g == 0 before it creates its Deserializing object.</div><div class="m_-4660032068075316978gmail_msg"> </div><blockquote class="gmail_quote m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div><div dir="ltr" class="m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978gmail_msg"><blockquote class="gmail_quote m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-4660032068075316978m_8162889088671218504HOEnZb m_-4660032068075316978gmail_msg"><div class="m_-4660032068075316978m_8162889088671218504h5 m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978gmail_msg"><div dir="ltr" class="m_-4660032068075316978gmail_msg">On Fri, Feb 24, 2017 at 2:22 PM Richard Smith <<a href="mailto:richard@metafoo.co.uk" class="m_-4660032068075316978gmail_msg" target="_blank">richard@metafoo.co.uk</a>> wrote:<br class="m_-4660032068075316978gmail_msg"></div><blockquote class="gmail_quote m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">On 24 February 2017 at 09:41, David Blaikie <span dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><<a href="mailto:dblaikie@gmail.com" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg" target="_blank">dblaikie@gmail.com</a>></span> wrote:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><blockquote class="gmail_quote m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">I've spent a few days debugging/trying to understand the following, so I'm writing it all down in the hopes of getting it straight/clear and potentially getting some external perspective on what's going on, whether I've understood it correctly, and what might be a good way to solve it.<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">Starting with this test case:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">foo.h:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></font><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> struct foo {};</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> inline void e() { foo(); }<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">bar.h:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></font><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> #include "foo.h"</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> template <typename T></font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> foo bar(foo &f) {</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> return f;</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> }</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> void z() { (void)&bar<int>; }<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></font><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">Build each into a separate module, run modular codegen on bar.pcm:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div style="font-family:monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> clang-tot -cc1 -fmodules-codegen -xc++ -emit-module -fmodules \<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> -fmodule-name=foo foo.cppmap -o foo.pcm</div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> clang-tot -cc1 -fmodules-codegen -xc++ -emit-module -fmodules \<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> -fmodule-name=bar bar.cppmap -o bar.pcm -fmodule-file=foo.pcm</div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> clang-tot -c bar.pcm -o bar.o<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></div></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">(I haven't fully understood why the use of 'foo' in foo.h is necessary, nor why 'bar' needs to be a template - those might provide some further insight about how this should/could work)</div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">This patch makes the failure a bit more visible/immediate:<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> diff --git lib/Serialization/<wbr>ASTReaderStmt.cpp lib/Serialization/<wbr>ASTReaderStmt.cpp</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> index b4718367d4..1fb48e9560 100644</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> @@ -3903,7 +3904,9 @@ Stmt *ASTReader::<wbr>ReadStmtFromStream(ModuleFile &F) {</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> ++NumStatementsRead;</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> </font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> if (S && !IsStmtReference) {</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> + auto X = Cursor.GetCurrentBitNo();</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> Reader.Visit(S);</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> + assert(X == Cursor.GetCurrentBitNo() && "Narf");</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> StmtEntries[Cursor.<wbr>GetCurrentBitNo()] = S;</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><font face="monospace" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> }</font></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"> </div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">This is layered on top of the modular codegen rewrite/refactor (to use a bit on function definitions, instead of to imply modular codegen from the Module object) and some other fixes. I'll include the full patch I'm working with.</div><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">The sequence of relevant steps (as best as I can figure)<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><ol class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">bar() body deserialization begins</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">bar module's DeclCursor is used, jumping to the start of the bar()'s definition</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">clang::ASTReader::<wbr>ReadStmtFromStream iterates through Stmts in bar()<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">no SavedStreamPosition nor Deserializing object here</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">deserializing the EXPR_CXX_CONSTRUCT gets interesting:</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">eventually involves deserializing foo(const foo&)</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">foo module's DeclCursor is used</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">foo module's DeclCursor is saved/preserved with a SavedStreamPosition</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">a ExternalASTSource::<wbr>Deserializing context is started</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">the definition of foo(const foo&) (in the bar module) is deserialized</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">this definition is 'interesting' and added to the ASTReader's InterestingDecls</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">The end of the Deserializing context (8) is reached</li><ol class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">In the non-modular-codegen case, DeclMustBeEmitted is not true for foo(const foo&) and it is shelved for lazy emission, end of story</li></ol><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">In the modular-codegen case, foo(const foo&) in the bar module must be emitted (all inline functions (implicitly or explicitly) defined in a module are emitted weak, etc)<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">So foo(const foo&) is non-lazily deserialized and emitted</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">The bar module's DeclCursor is used for this, unprotected</li><li class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">execution eventually gets back to the deserialization of bar() - and the DeclCursor it's using is out of position -> badness.</li></ol><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">Maybe there's a better way to provide this timeline, I'm not sure - hopefully it makes sense.<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072m_4127207265168833327m_833859486294641431gmail_msg m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">Essentially the way ASTReader::ReadDeclRecord (started in (5) that contains the SavedStreamPosition and Deserializing context) seems to assume that the only things that will be non-lazily deserialized will come from the same module. Modular codegen breaks that invariant at the moment (well, with the patch provided).<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">I did try SavedStreamPosition-protecting the call from 3->4 (specifically the "Visit(Expr)" call in ReadStmtFromStream) though still hit some crashes. Maybe that's the right path to go down still, but need to do more?<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">When I tried to copy the DeclCursor in ReadStmtFromStream that actually broke things pretty significantly (compile errors on valid code even without modular codegen enabled). But I don't know much about the cursors - evidently more than only an efficiency concern, I guess the non-offset state in the copy of the cursor changes and so the original DeclCursor isn't updated, etc. (I wonder about splitting these cursors into a shared state + offset, share the state with shared_ptr and make it cheap to copy the actual offset state around so there's less reason to risk these sharing situations & all the SavedStreamPosition protection that requires).<br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">Long & short of it: What should I do here? What're the likely goals I should be trying to move the code towards, if any?</div></div></div></div></div></div></div></blockquote><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></div></div></div></div><div dir="ltr" class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">We should have at least one instance of Deserializing extant during all deserialization. It looks like one is missing from GetExternalDeclStmt.</div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"><br class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg"></div><div class="m_-4660032068075316978m_8162889088671218504m_6945530598186804072gmail_msg m_-4660032068075316978gmail_msg">I think it's correct that ReadStmtFromStream does not try to maintain the stream position: it's intending to be called with the DeclsCursor pointing at the Stmt to read, and intends to leave the stream pointing to the record after that point. The external caller (GetExternalDeclStmt) jumps to the correct bit location (as do all other users of the DeclsCursor) before calling it, and does not expect to ever be called reentrantly. But a reentrant call to GetExternalDeclStmt is exactly what's happening in your case, because it also doesn't /defend/ against reentrancy from end-of-deserialization actions through a Deserializing object.</div></div></div></div>
</blockquote></div>
</div></div><br class="m_-4660032068075316978gmail_msg"></blockquote></div></div></div><div dir="ltr" class="m_-4660032068075316978gmail_msg"><div class="gmail_extra m_-4660032068075316978gmail_msg"><div class="gmail_quote m_-4660032068075316978gmail_msg"><blockquote class="gmail_quote m_-4660032068075316978gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">______________________________<wbr>_________________<br class="m_-4660032068075316978gmail_msg">
cfe-dev mailing list<br class="m_-4660032068075316978gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="m_-4660032068075316978gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="m_-4660032068075316978gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="m_-4660032068075316978gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br class="m_-4660032068075316978gmail_msg">
<br class="m_-4660032068075316978gmail_msg"></blockquote></div><br class="m_-4660032068075316978gmail_msg"></div></div>
</blockquote></div>
</div></div></blockquote></div><br></div></div>