<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 Jun 24, 2016, at 11:23 AM, Joe Groff via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><blockquote type="cite" class="">On Jun 24, 2016, at 11:05 AM, Saleem Abdulrasool via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class="">Hi,<br class=""><br class="">The blocks runtime itself is pretty tiny, and works across various targets already, so including it is not too onerous. &nbsp;As such, Id like to propose enabling blocks across all the targets.<br class=""><br class="">This make it easier to then import code on targets which have optional blocks support. &nbsp;For most users, this would be a transparent change, but would mean that the clang importer goes through a more similar path across the various targets.<br class=""></blockquote><br class="">It's a little trickier than that. We only support Swift refcounting object headers on non-Darwin platforms, since there's no universal objc_retain implementation to fall back to. Blocks don't use Swift-compatible refcounting with the current runtime.<br class=""></div></div></blockquote><div><br class=""></div>It’s a bit more subtle than that. I think IRGen now does the right thing if a value is statically known to be a block, emitting calls to the block-specific refcounting entry points on both platforms:</div><div><br class=""></div><div><a href="https://github.com/apple/swift/commit/aa40f206cb993846c3c211219e54ec246a62a384" class="">https://github.com/apple/swift/commit/aa40f206cb993846c3c211219e54ec246a62a384</a></div><div><br class=""></div><div>However, on Darwin we can cast a block to AnyObject, and use the unknown reference counting entry points on these values. On Linux, AnyObject still uses Swift-native reference counting, and thus is not bitwise-compatible with blocks. So as long as this is not an issue, you can go ahead and use blocks on Linux.</div><div><br class=""></div><div>We’ve talked about hacking the blocks runtime to use Swift reference counting on Linux, but this is a non-trivial change.</div><div><br class=""></div><div>Saleem, please give it a shot and let us know if you run into any problems!</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div class=""><br class="">-Joe<br class="">_______________________________________________<br class="">swift-dev mailing list<br class=""><a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-dev<br class=""></div></div></blockquote></div><br class=""></body></html>