<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="">Le 31 janv. 2016 à 01:17, Félix Cloutier via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</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="">I'd like to pitch this proposal to implement the feature:&nbsp;<a href="https://github.com/zneak/swift-evolution/blob/master/proposals/00xx-noescape-once.md" class="">https://github.com/zneak/swift-evolution/blob/master/proposals/00xx-noescape-once.md</a><div class=""><br class=""></div><div class="">Rationale for some points:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">Only one closure parameter can be marked as&nbsp;@noescape(once)&nbsp;in a function signature.</blockquote></div><div class=""><br class=""></div><div class="">The attribute doesn't specify the order of execution of the closures, so it could have unintended consequences if closure B depends on closure A but closure B is called first. Given the typical use case (the @noescape(once) closure as a trailing closure), I don't think that it's worth it to invest a lot of effort into coming up with a model to decide (and enforce) which closure has to be called first and what to do if either closure throws or something.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">it is not required to be executed on a code path that throws;</blockquote></div><div class=""><br class=""></div><div class="">It may need to be clarified into "must" or "must not", but I can't think about very good examples supporting either case right now.</div><div class=""><div class=""><div class=""><br class=""></div></div></div></div></div></blockquote><br class=""></div><div>What is the implication of this @noescape(once) closure not being call on throws when the caller use try? variation? Looks like the compiler will have to assume that the @escape(once) is both not called and not not called (sorry for the double-negative). For the try!, i think that the compiler could assume that the @escape(none) is called, as the process would crash otherwise anyway on the throw.</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">var</span> bad: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Bool</span> = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">true</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">enum</span> e: <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">ErrorType</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span> Simple</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> f(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> closure: () -&gt; ()) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span>&nbsp;{</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> (bad) { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throw</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">e</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Simple</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; closure()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(187, 44, 162);" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">x</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp;&nbsp;</span>// Not initialized</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: rgb(187, 44, 162);" class="">try</span>? <span style="color: rgb(49, 89, 93);" class="">f</span> { x = <span style="color: rgb(39, 42, 216);" class="">1</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(x)&nbsp; &nbsp; </span>// May still be uninitialized, compiler must generate error</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp;&nbsp;x = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">2</span>&nbsp; &nbsp; &nbsp; &nbsp;// May have been initialized, compiler must generate error</div></div><div class=""><br class=""></div></div><div>This should probably be highlighted in the proposal as an intended limitation for the typical usage.</div><div>Another special case with try? that people may be unlikely to use, is:</div><div><br class=""></div><div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">func</span> g(<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">@noescape</span> closure: () -&gt; ()) <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throws</span> -&gt; <span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span> {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> (bad) { <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">throw</span> <span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">e</span>.<span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">Simple</span> }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; closure()</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span> data = <span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">try</span>? <span style="font-variant-ligatures: no-common-ligatures; color: #31595d" class="">g</span>({ x = <span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">1</span> }) {</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class="">(x) </span>// Guaranteed to be initialized</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="color: rgb(61, 29, 129);" class="">&nbsp; &nbsp; print</span>(x)&nbsp; &nbsp;&nbsp;<span style="color: rgb(0, 132, 0);" class="">// May still be uninitialized, compiler must generate error</span></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(0, 132, 0);" class=""><div style="margin: 0px; line-height: normal;" class="">&nbsp; &nbsp; x =&nbsp;<span style="color: rgb(39, 42, 216);" class="">2</span>&nbsp; &nbsp; &nbsp; &nbsp;// May have been initialized, compiler must generate error</div></div></div><div class=""><br class=""></div></div><div>Not sure if this case will make the implementation more complex, it is why I’m mentioning it.</div><div><br class=""></div><div>Dany</div></body></html>