<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 Mar 20, 2016, at 11:41 PM, Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">On Sun, Mar 20, 2016 at 9:32 PM, Timothy Wood via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class=""><br class="">In preparation for writing a proposal, I wanted to solicit any feedback and general level of interest on addressing SR-842, which proposes modifying ObjectiveC.autoreleasepool to allow a potentially `throw`ing body via a `rethrows` annotation. I have a branch with the very simple change applied and a test. However, Dmitri Gribenko pointed out that it would be even better if the signature was amended to allow for a generic return type:<br class=""><br class=""> &nbsp;public func autoreleasepool&lt;Result&gt;(@noescape code: () throws -&gt; Result) rethrows -&gt; Result<br class=""><br class="">It isn’t clear to me whether it is possible for a wrapper to be written that adds rethrow, since the function needs to compile under the assumption that the passed block does not throw. So, something like this doesn’t actually compile.<br class=""></blockquote><br class="">Hi Timothy,<br class=""><br class="">I think it should be possible -- or I wouldn't be suggesting it :)<br class=""><br class="">func poolPush() {}<br class="">func poolPop() {}<br class=""><br class="">public func autoreleasepool&lt;Result&gt;(@noescape code: () throws -&gt;<br class="">Result) rethrows -&gt; Result {<br class=""> &nbsp;poolPush()<br class=""> &nbsp;defer { poolPop() }<br class=""> &nbsp;return try code()<br class="">}<br class=""></div></div></blockquote></div><br class=""><div class=""><br class=""></div><div class="">Sorry; yes of course it is possible to make stdlib do this. What I meant was whether it is possible for code outside stdlib to easily wrap a autoreleasepool that does not have `rethrow` applied and make one that does. Or, more generically, is it possible in Swift, given only `func f(@noescape body: Void -&gt; Void)` to write `func f(@noescape body: Void throws -&gt; Void) rethrows`? It seemed to me like it isn’t possible, since the wrapper needs to capture the error inside a do/catch in a var and then optionally re-throw it outside the do/catch, but the rethrow can’t be done (as far as I can see) since that seems to make the compiler thing that the function should be marked as `throws` instead of `rethrows`.</div><div class=""><br class=""></div><div class="">In particular, in this case pushPool() and popPool() don’t exist as nice public API:</div><div class=""><br class=""></div><blockquote style="margin: 0px 0px 0px 40px; border: none; padding: 0px;" class=""><div class="">@warn_unused_result</div><div class="">@_silgen_name("objc_autoreleasePoolPush")</div><div class="">func __pushAutoreleasePool() -&gt; OpaquePointer</div><div class=""><br class=""></div><div class="">@_silgen_name("objc_autoreleasePoolPop")</div><div class="">func __popAutoreleasePool(pool: OpaquePointer)</div></blockquote><div class=""><br class=""></div><div class="">Either way, I think stdlib should be marked `rethrow` here, but it may make for a more compelling argument for this (and other cases in stdlib that take a function argument) if it is hard or impossible(?) for code outside stdlib to provide a `rethrows` wrapper of code in stdlib.</div><div class=""><br class=""></div><div class="">Thanks!</div><div class=""><br class=""></div><div class="">-tim</div><div class=""><br class=""></div></body></html>