<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=""><div class="">-1 for the signature change. The most common case of autoreleasepool does <i class="">not</i>&nbsp;return a value <i class="">and</i>&nbsp;has a multi-statement body that prevents the result type from being inferred. This needs to continue to work:</div><div class=""><br class=""></div><div class="">autoreleasepool {</div><div class="">&nbsp; foo()</div><div class="">&nbsp; bar()</div><div class="">}</div><div class=""><br class=""></div><div class="">If we had a rule to default generic return values to Void if they aren't used then I'd be okay with it, but that'd be a separate proposal. (Providing two overloads may also work; haven't tested it.)</div><div class=""><br class=""></div><div class="">Jordan</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 20, 2016, at 21:32 , Timothy Wood via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div 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=""><br class=""> &nbsp;func autoreleasepool_generic&lt;ResultType&gt;(@noescape code: Void throws -&gt; ResultType) rethrows -&gt; ResultType {<br class=""><br class=""> &nbsp;&nbsp;&nbsp;// or some Result enum...<br class=""> &nbsp;&nbsp;&nbsp;var result:ResultType?<br class=""> &nbsp;&nbsp;&nbsp;var error:ErrorProtocol?<br class=""><br class=""> &nbsp;&nbsp;&nbsp;autoreleasepool {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;result = try code()<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} catch let e {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;error = e<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;if let result = result {<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return result<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;// Doesn't work, since in the case that `code` doesn't throw, the whole function can't.<br class=""> &nbsp;&nbsp;&nbsp;throw error!<br class=""> &nbsp;}<br class=""><br class="">Is there a way I’m missing to write a rethrows wrapper around autoreleasepool that would provide a fair comparison?<br class=""><br class="">At any rate, it seems much nicer to be able to do:<br class=""><br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>let value = try autoreleasepool {…}<br class=""><br class="">than to have a bunch of boilerplate at the call site, or for everyone to figure out how to write their own wrapper.<br class=""><br class="">Some other questions for feedback that I came across while looking into this:<br class=""><br class="">- Since the API is already changing, should the `code` parameter be renamed to `body`? The rest of stdlib uses `body` frequently and never uses `code` as far as I can see.<br class="">- Should the name of the generic argument be something like ‘Result’ (which might conflict with a enum that holds a value-or-error) or ‘ResultType` (which might conflict with a protocol in 2.2 land, but less so in 3.0 maybe?), or something else?<br class=""><br class="">Thanks!<br class=""><br class="">-tim<br class=""><br class=""><br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></div></blockquote></div><br class=""></body></html>