<div dir="ltr">I agree; I think the &#39;in&#39; should be there. This should be fairly straight-forward to implement right? It&#39;s just alternative syntax over existing behavior. (thinking about the proposal now...)</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 25, 2017 at 5:45 PM, John McCall via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><blockquote type="cite"><div>On Oct 25, 2017, at 4:21 PM, David Hart &lt;<a href="mailto:david@hartbit.com" target="_blank">david@hartbit.com</a>&gt; wrote:</div><div><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>On 25 Oct 2017, at 19:01, John McCall &lt;<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>&gt; wrote:</div><br class="m_1580424629663797031Apple-interchange-newline"><div><div style="word-wrap:break-word"><div><blockquote type="cite"><div>On Oct 25, 2017, at 7:41 AM, David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><div><div style="word-wrap:break-word">I got bit again by a sneaky memory leak concerning local functions and would like to discuss a small language change. I vaguely remember this being discussed in the past, but can’t find the thread (if anybody could point me to it, I’d appreciate it). Basically, here’s an example of the leak:<div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">class</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">A</span> {
    <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">foo</span>() {
        <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">local</span>() {
            <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">bar</span>()
        }
    
        methodWithEscapingClosure { [<span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">unowned</span> <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">self</span>] <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">_</span> <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">in</span>
            <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">self</span>.<span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">bar</span>()
            <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">local</span>() <span class="m_1580424629663797031pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"><span class="m_1580424629663797031pl-c" style="box-sizing:border-box">//</span> this leaks because local captures self</span>
<span class="m_1580424629663797031pl-c" style="box-sizing:border-box;color:rgb(106,115,125)"></span>        }
    }
    
    <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">bar</span>() {
    }
}</pre><div><br></div></div><div>Its sneaky because local’s capturing of self is not obvious if you’ve trained your brain to watch out for calls prefixed with self. I would suggest having the compiler force users to make self capturing explicit, the same way it does for closures:</div></div></div></blockquote><div><br></div>I think this is a good idea.  Ideally the proposal would also allow explicit capture lists in local functions.</div></div></div></blockquote><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Ideally, yes. But the only sensible syntax I can come up for that seems odd in the context of functions:</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">class</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">A</span> {
    <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">foo</span>() {
        <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">local</span>() <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">-&gt;</span> <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">Int</span> { [<span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">weak</span> <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">self</span>] <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">in</span>
        }
    }
}</pre></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Don’t you think?</div></div></blockquote><div><br></div></span>You could leave the &quot;in&quot; off, but it&#39;s only a little weird to have it, and the inconsistency would probably be worse.</div><div><br></div><div>John.</div><span class=""><div><br></div><div><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">David.</div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite" style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div><div style="word-wrap:break-word"><div>John.</div><div><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div><pre style="box-sizing:border-box;font-family:SFMono-Regular,Consolas,&#39;Liberation Mono&#39;,Menlo,Courier,monospace;font-size:13.600000381469727px;margin-top:0px;margin-bottom:0px;word-wrap:normal;padding:16px;overflow:auto;line-height:1.45;background-color:rgb(246,248,250);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal;color:rgb(36,41,46)"><span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">class</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">A</span> {
    <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">foo</span>() {
        <span class="m_1580424629663797031pl-k" style="box-sizing:border-box;color:rgb(215,58,73)">func</span> <span class="m_1580424629663797031pl-en" style="box-sizing:border-box;color:rgb(111,66,193)">local</span>() {
            <span class="m_1580424629663797031pl-c1" style="box-sizing:border-box;color:rgb(0,92,197)">bar</span>() // error: Call to method ‘bar&#39; in function ‘local&#39; requires explicit &#39;self.&#39; to make capture semantics explicit
        }
    
<span class="m_1580424629663797031Apple-tab-span" style="white-space:pre-wrap">        </span>// ...
    }
}</pre><div><br></div></div><div>What do you think?</div><div><br></div><div>David.</div><div><br></div></div>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></div></blockquote></div></div></div></blockquote></div></blockquote></div><br></span></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>