<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">well dispatch also uses a bit of the blocks runtime because it uncorks the blocks and gets to the captured function pointer.<div class=""><br class=""></div><div class="">This is used pervasively, through this macro (internal.h):</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 10px; line-height: normal; color: rgb(210, 143, 90);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class="">#define _dispatch_Block_invoke(bb) \</font></span></div><div style="margin: 0px; font-size: 10px; line-height: normal; color: rgb(210, 143, 90);" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">                </span>((dispatch_function_t)((struct Block_layout *)bb)-&gt;invoke)</font></span></div></div><div class=""><br class=""></div><div class="">And we need to know the size of the Block_layout for a simple block (abused in _dispatch_block_get_data(), see inline_internal.h).</div><div class=""><br class=""></div><div class="">technically speaking dispatch only cares about the offsets/sizes and not about the rest of the layout.</div><div class=""><br class=""><div class="">
-Pierre

</div>

<br class=""><div><blockquote type="cite" class=""><div class="">On Jan 14, 2016, at 3:00 PM, Philippe Hausler via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">As a note: our closure implementation in Foundation does NOT adhere to this (since it would mean that we would need to alter the c compiler to do so and that was not something that I have gotten to look at beyond a cursory glance.</div><div class=""><br class=""></div><div class="">So the change would be effectively something like this:</div><div class=""><br class=""></div><div class="">struct&nbsp;Block_layout {<br class="">&nbsp; &nbsp;&nbsp;void&nbsp;*isa;<br class="">#if DEPLOYMENT_RUNTIME_SWIFT<br class="">&nbsp; &nbsp;&nbsp;uint32_t refCount;<br class="">&nbsp; &nbsp;&nbsp;uint32_t weakRefCount;<br class="">#else // not certain this branch can happen or not. we may need both</div><div class="">&nbsp; &nbsp;&nbsp;volatile&nbsp;int32_t flags;&nbsp;// contains ref count<br class="">&nbsp; &nbsp;&nbsp;int32_t reserved;</div><div class="">#endif</div><div class="">&nbsp; &nbsp;&nbsp;void&nbsp;(*invoke)(void&nbsp;*, ...);<br class="">&nbsp; &nbsp;&nbsp;struct&nbsp;Block_descriptor_1 *descriptor;<br class="">&nbsp; &nbsp;&nbsp;// imported variables<br class="">};</div><div class=""><br class=""></div><div class="">and making the retain and release methods for blocks just call swift_retain and swift_release. But since blocks may be emitted by the compiler we would need to make certain that the compiler had a flag to emit those with the new layout and emit correct values for the refCount fields to give it immortality for things like global static blocks etc.</div><div class=""><br class=""></div><div class="">Then we would need to find some way to have the values for:</div><div class=""><br class=""></div><div class="">void&nbsp;* _NSConcreteStackBlock[32] = {&nbsp;0&nbsp;};<br class="">void&nbsp;* _NSConcreteMallocBlock[32] = {&nbsp;0&nbsp;};<br class="">void&nbsp;* _NSConcreteAutoBlock[32] = {&nbsp;0&nbsp;};<br class="">void&nbsp;* _NSConcreteFinalizingBlock[32] = {&nbsp;0&nbsp;};<br class="">void&nbsp;* _NSConcreteGlobalBlock[32] = {&nbsp;0&nbsp;};<br class="">void&nbsp;* _NSConcreteWeakBlockVariable[32] = {&nbsp;0&nbsp;};</div><div class=""><br class=""></div><div class="">these guys emitted as objects as well so that the isa’s would be treated correctly.</div><div class=""><br class=""></div><div class="">I am not certain on how much of this lofty goal is actually needed; perhaps we should loop in one of the compiler team in on this to query what really needs to be done to properly support the&nbsp;@convention(block) syntax on linux. Perhaps I am overthinking this.</div></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 14, 2016, at 2:49 PM, David P Grove &lt;<a href="mailto:groved@us.ibm.com" class="">groved@us.ibm.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><p class=""><tt class=""><a href="mailto:phausler@apple.com" class="">phausler@apple.com</a> wrote on 01/13/2016 06:04:23 PM:</tt><br class=""><tt class="">&gt; <br class="">&gt; Tony brought up an important point about the prep for integration <br class="">&gt; this morning: the blocks runtime from libblocksruntime-dev will be <br class="">&gt; incompatible with the layout of blocks referenced from swift since <br class="">&gt; the object size there is 2 uint32’s bigger to handle the RR (we <br class="">&gt; don’t have objc). Without modifying clang and the runtime we won’t <br class="">&gt; have a way to properly handoff blocks back and forth w/o objc.</tt><br class=""><br class=""><tt class="">Hi,</tt><br class=""><br class=""><tt class="">        I'm guessing RR expands to Retain Release?</tt><br class=""><br class=""><tt class="">        I've started exploring the source in swift-corelibs-foundation/closure. &nbsp;Any chance there is a design doc laying out the object model used by the Swift implementation? &nbsp;I'm sure I could figure it out from the source code, but it would be nice to be able to cheat and start with a an overview.</tt><br class=""><br class=""><tt class="">thanks,</tt><br class=""><br class=""><tt class="">--dave</tt><br class=""><br class=""><tt class="">&gt; <br class="">&gt; I am currently taking a look at this to see what we can do to add an<br class="">&gt; option to the clang code-gen to properly emit this structural <br class="">&gt; difference. This isn’t a big issue for Foundation to CF since we <br class="">&gt; don’t have many block APIs but dispatch is mostly blocks and that <br class="">&gt; might pose an issue.</tt><br class=""><tt class="">&gt; <br class=""></tt><br class="">
</p></div>
</div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=ST9LHNQ2kYRKURQJ7G-2FmGJ7cPtWGB-2BbbnqmgrSbiwvh2zUjMBvxZA4yJRaeYSv2NBRJ7uNCOoCbjqWhCSPFTpTfZmVXoH-2F86C0GXHGLmVEQtyhj4BOt6JPn3c3oxnQDd0cwvmvCiWax3F29do35zsWfvGcChy6lG1GR4Ehhnrvx7psi6dzodIFJnHMwXFqpt6r7B6xD8-2BjMpjjN3srmcxuTIrlK8ChlsPgGBX7wrJTE-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-corelibs-dev mailing list<br class=""><a href="mailto:swift-corelibs-dev@swift.org" class="">swift-corelibs-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev<br class=""></div></blockquote></div><br class=""></div></body></html>