<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 12:53 PM, Jacob Bandes-Storch 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=""><div dir="ltr" class=""><div class="">There are several functions in public API, such as dispatch_sync and dispatch_apply, which do not allow their block parameters to escape the function call.</div><div class=""><br class=""></div><div class="">However, they are not currently exposed to Swift as @noescape, meaning that users are required to specify "self." or "[weak self]" in their closures.</div><div class=""><br class=""></div><div class="">The instances I can think of:</div><div class=""><br class=""></div><div class="">- dispatch_sync</div><div class="">- dispatch_barrier_sync</div><div class="">- dispatch_apply</div><div class="">-&nbsp;dispatch_block_perform (thanks to Pierre Habouzit for pointing this out)</div></div></div></blockquote><div><br class=""></div><div>I also pointed out dispatch_once(), which even it doesn’t make sense for swift where the globals already have the proper semantics, is still useful as the compiler can still implement various optimizations in how the block captures its variables (it is okay to use the things where they are on the stack as opposed to have to create a real state for the block).</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">I provided a preliminary implementation at <a href="https://github.com/apple/swift-corelibs-libdispatch/pull/6" class="">https://github.com/apple/swift-corelibs-libdispatch/pull/6</a>, but it needs refinement. Tony Parker mentioned commented that there might be similar changes to make for the&nbsp;swift-corelibs-foundation project.</div><div class=""><br class=""></div><div class="">Thoughts?</div><div class=""><br class=""></div><div class="">Question: does __attribute__((noescape)) have the same meaning when applied to C function pointers? Namely, does Swift understand @noescape as it applies to @convention(c)?</div><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Jacob Bandes-Storch<br class=""></div></div></div></div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=5iieyF0sfNoNTPw-2FMLoCOzQ6uY4r1XYWvXHoQH8KwZwhnhDjOLk0t3C9IIMYMTw7aeLd6P4Y-2FxStt2ioxyMdP4-2BRqF8RuG5mCFsImGP4h8FHBgGabGfAXho6d0yrCIgLPFd0Z6jNSjMTtjNGts9C8cU234Vr8gpt8o9GeN-2Ba-2FA2s1HzZms63-2FbdC9Pi9T34exDLPyTFSEf0FNaw0zWyaQGNgArXUZcxuDrALTxWkOtY-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="">
_______________________________________________<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=""></body></html>