<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jan 16, 2018, at 1:49 PM, Raj Barik &lt;<a href="mailto:rkbarik@gmail.com" class="">rkbarik@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks a lot for the clarification Adrain and Vedant.&nbsp;<div class=""><br class=""></div><div class="">What confused me is the cycle -- A SILFunction has a DeubgScope&nbsp; and the DebugScope points back to the SILFunction. During moving instructions across functions, one can easily mess up the pointers. As you all pointed out, one needs to also use ScopeCloner to get around this problem.&nbsp;</div><div class="">&nbsp;</div><div class="">Does it make sense not to have the cycle, i.e., DebugScopes are made independent of SILFunction so that multiple SILFunction(s) can share the same DebugScope?</div></div></div></blockquote><div><br class=""></div>SILDebugScopes are also the vehicle to represent inlining information. If you want to change the representation such that SILDebugScopes can be shared between functions, you will have to change how inline info is being represented. Representing it differently is definitely possibly, but you also have to redesign inline info along with it.</div><div><br class=""></div><div>-- adrian</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 16, 2018 at 1:26 PM, Adrian Prantl <span dir="ltr" class="">&lt;<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><br class=""><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 16, 2018, at 1:20 PM, Vedant Kumar &lt;<a href="mailto:vsk@apple.com" target="_blank" class="">vsk@apple.com</a>&gt; wrote:</div><br class="m_6218366152709277374Apple-interchange-newline"><div class=""><div style="word-wrap:break-word" class="">+ Adrian and Davide, since they work in this area.<div class=""><br class=""></div><div class="">Hi Raj,<div class=""><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 15, 2018, at 4:48 PM, Raj Barik via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="m_6218366152709277374Apple-interchange-newline"><div class=""><div dir="ltr" class="">Thanks Mark. You are right, the following assertion fails<div class=""><br class=""></div><div class=""><div class="">require(!DS || DS-&gt;getParentFunction() == I-&gt;getFunction(),</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "debug scope of instruction belongs to a different function");</div></div><div class=""><br class=""></div><div class="">I am not sure if we need such a check.</div></div></div></blockquote><div class=""><br class=""></div><div class="">This check exists to ensure that the debug info generated for a program is helpful. For example, a function with the wrong debug scope attached might make for confusing backtraces.</div></div></div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">It's more than just confusing backtraces. If these invariants aren't met the LLVM IR generated from this SIL will not pass the LLVM IR verifier or in older versions even crash LLVM.</div><div class=""><br class=""></div><div class="">The constraint being checked in this assertion is that each instruction must be in a lexical scope whose top-level ancestor is the function itself. I.e., it is not legal to move an instruction from one function to another with updating that instruction's debug information by either reparenting it into the new function or by creating inline information for it. SILClonerWithScope implements this re-parenting of instructions into a new function for you.</div><span class="HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">-- adrian</div></font></span><div class=""><div class="h5"><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><br class=""></div><div class="">vedant</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">&nbsp;&nbsp;</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 15, 2018 at 4:16 PM, Mark Lacey <span dir="ltr" class="">&lt;<a href="mailto:mark.lacey@apple.com" target="_blank" class="">mark.lacey@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space" class=""><br class=""><div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class="">On Jan 15, 2018, at 12:54 PM, Raj Barik &lt;<a href="mailto:rkbarik@gmail.com" target="_blank" class="">rkbarik@gmail.com</a>&gt; wrote:</div><br class="m_6218366152709277374m_3833984575572660261Apple-interchange-newline"><div class=""><div dir="ltr" class="">Mark,<div class=""><br class=""></div><div class="">Thanks a lot for quick reply.</div><div class="">&nbsp;</div><div class="">Is there any reason this interface in SILInstruction should be private?</div><div class="">void setDebugScope(SILBuilder &amp;B, const SILDebugScope *DS);<br class=""></div><div class=""><br class=""></div><div class="">In my case, I am splicing the old F into the new function NF. While splicing retains the debug scope, the new instruction (InitRef) that I am adding to NF is being created in some random scope (not F) even though I explicitly make Builder's debug scope point to F's.&nbsp;</div></div></div></blockquote><div class=""><br class=""></div></span><div class="">The assert you originally hit appears to indicate that the parentFunction of the debug scope for an instruction should be the same as the function the instruction is in. I am not very familiar with the requirements of our debug information and debug scopes, but this seems like a reasonable expectation.</div><div class=""><br class=""></div><div class="">I suggested looking at SILCloner because it is the primary way by which we clone functions, and clearly has to deal with debug scopes when it does so.</div><div class=""><br class=""></div><div class="">I’m not sure how much more help I can be on this matter, but perhaps someone more knowledgable can chime in.</div><span class="m_6218366152709277374HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">Mark</div></font></span><div class=""><div class="m_6218366152709277374h5"><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Best,</div><div class="">Raj</div><div class=""><br class=""></div><div class=""><br class=""></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Jan 15, 2018 at 9:52 AM, Mark Lacey <span dir="ltr" class="">&lt;<a href="mailto:mark.lacey@apple.com" target="_blank" class="">mark.lacey@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I’d suggest looking at SILCloner.h as well as ScopeCloner in SILBasicBlock.cpp to see how they are dealing with debug scopes.<br class="">
<br class="">
Mark<br class="">
<div class=""><div class="m_6218366152709277374m_3833984575572660261h5"><br class="">
&gt; On Jan 15, 2018, at 9:24 AM, Raj Barik via swift-dev &lt;<a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt; Hi,<br class="">
&gt;<br class="">
&gt; I am running into a debug scope SIL Verifier error when creating a new function (NF) from an existing one (F). Can someone point me where I am going wrong?<br class="">
&gt;<br class="">
&gt; NF = M.createFunction(...., F-&gt;getDebugScope());<br class="">
&gt; SILBasicBlock *NFBody = NF-&gt;createBasicBlock();<br class="">
&gt; SILBuilder NFBuilder(NFBody);<br class="">
&gt; SILOpenedArchetypesTracker OpenedArchetypesTrackerNF(NF);<br class="">
&gt; NFBuilder.setOpenedArchetypesT<wbr class="">racker(&amp;OpenedArchetypesTracke<wbr class="">rNF);<br class="">
&gt; NFBuilder.setCurrentDebugScope<wbr class="">(NFBody-&gt;getParent()-&gt;getDebug<wbr class="">Scope());<br class="">
&gt; ...<br class="">
&gt; for (auto &amp;param : params) { /* Assume all are generic types */<br class="">
&gt;&nbsp; &nbsp;auto GenericsSILType = ....<br class="">
&gt;&nbsp; &nbsp;auto NewArg = NFBody-&gt;createFunctionArgument<wbr class="">(GenericSILType);<br class="">
&gt;&nbsp; &nbsp;auto Conformances = Mod-&gt;lookupConformance(...);<br class="">
&gt;&nbsp; &nbsp;auto *InitRef = NFBuilder.createInitExistentia<wbr class="">lRef( Loc, ArgDesc.Arg-&gt;getType(), NewArg-&gt;getType().getSwiftRVal<wbr class="">ueType()-&gt;getCanonicalType(), NewArg, Conformances);<br class="">
&gt;&nbsp; &nbsp;...<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; The InitRef instruction created above runs into SIL verifier error:<br class="">
&gt;<br class="">
&gt; SIL verification failed: debug scope of instruction belongs to a different function: !DS || DS-&gt;getParentFunction() == I-&gt;getFunction()<br class="">
&gt; Verifying instruction:<br class="">
&gt;&nbsp; &nbsp; %0 = argument of bb0 : $τ_0_0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// user: %1<br class="">
&gt; -&gt;&nbsp; &nbsp;%1 = init_existential_ref %0 : $τ_0_0 : $τ_0_0, $SomeProtocol // user: %2<br class="">
&gt;<br class="">
&gt; The SIL looks correct to me though.<br class="">
&gt;<br class="">
&gt; --Raj<br class="">
</div></div>&gt; ______________________________<wbr class="">_________________<br class="">
&gt; swift-dev mailing list<br class="">
&gt; <a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-dev</a><br class="">
<br class="">
</blockquote></div><br class=""></div>
</div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div>
______________________________<wbr class="">_________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" target="_blank" class="">swift-dev@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-dev" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-dev</a><br class=""></div></blockquote></div><br class=""></div></div></div></div></div></blockquote></div></div></div><br class=""></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>