<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="">I was okay with memberwise initializers but this pushes me beyond my comfort zone.<div class=""><br class=""></div><div class="">I'm not sold on the usefulness of the feature. Memberwise initializers save you from typing out the init parameters and assignments to each field. Argument forwarding saves you from spelling out the parameters *more than once* (because you still need to type them out for the receiving function) and from *one call*. While I've been annoyed at initializers, I don't think I've ever been particularly annoyed at forwarding functions.</div><div class=""><br class=""></div><div class="">I'll let the parser guys say if it's a lot of work to implement or not, but if I allow myself to speak outside of my expertise, I imagine that it's gonna be a lot more work than memberwise initializers because this requires inspecting the function body to figure out its parameters.</div><div class=""><br class=""></div><div class="">At this point, I feel that a competent macro system is a better investment than adding distinct bits of automation wherever there appears to be repetition.<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>

<br class=""><div><blockquote type="cite" class=""><div class="">Le 10 janv. 2016 à 22:44:36, Matthew Johnson 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=""><div class="">I have always considered the Flexible Memberwise Initialization proposal to be just a first step (as evidenced by the many future enhancements it discussed). &nbsp;Its review has inspired new ideas and helped to shape my vision of the best long-term solution. &nbsp;My final thoughts about the review can be found here:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/006176.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/006176.html</a></div><div class=""><br class=""></div><div class="">Parameter forwarding is the first in a series of three proposals describing general features that can work together to form a complete solution.</div><div class=""><br class=""></div><div class=""><div class="">The proposal drafts can be found at the following links:</div><div class=""><br class=""></div><div class="">*&nbsp;<b class="">Parameter forwarding:</b>&nbsp;<a href="https://github.com/anandabits/swift-evolution/blob/parameter-forwarding/proposals/NNNN-parameter-forwarding.md" class="">https://github.com/anandabits/swift-evolution/blob/parameter-forwarding/proposals/NNNN-parameter-forwarding.md</a></div><div class="">*&nbsp;<b class="">Partial initializers:</b>&nbsp;<a href="https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md" class="">https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md</a></div><div class="">*&nbsp;<b class="">Property lists:</b>&nbsp;<a href="https://github.com/anandabits/swift-evolution/blob/property-lists/proposals/NNNN-property-lists.md" class="">https://github.com/anandabits/swift-evolution/blob/property-lists/proposals/NNNN-property-lists.md</a></div></div><div class=""><br class=""></div><div class="">Matthew</div><div class=""><h1 id="parameterforwarding" style="font-size: 37px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Parameter Forwarding</h1><ul style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;" class=""><li style="font-size: 17px;" class="">Proposal:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-parameter-forwarding.md" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">SE-NNNN</a></li><li style="font-size: 17px;" class="">Author(s):&nbsp;<a href="https://github.com/anandabits" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Matthew Johnson</a></li><li style="font-size: 17px;" class="">Status:&nbsp;<strong style="line-height: 1;" class="">Awaiting review</strong></li><li style="font-size: 17px;" class="">Review manager: TBD</li></ul><h2 id="introduction" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Introduction</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This feature introduces an automatic parameter forwarding mechanism.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Swift-evolution thread:&nbsp;<a href="https://lists.swift.org/pipermail/swift-evolution" style="color: rgb(13, 110, 161); text-decoration: none; transition: color 0.2s ease-in-out; -webkit-transition: color 0.2s ease-in-out;" class="">Proposal Draft: parameter forwarding</a></p><h2 id="motivation" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Motivation</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">There are many cases where a function declares parameters simply for the purpose of forwarding the provided arguments to another function. This results in reduntant parameter specifications that make code less clear and less readable by obscuring the simple forwarding that is actually happening.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This feature will be especially useful in initializers such as:</p><ul style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;" class=""><li style="font-size: 17px;" class="">Convenience initializers that foward parameters directly to a designated initializer</li><li style="font-size: 17px;" class="">Designated initializers that foward parameters directly to a super initializer</li><li style="font-size: 17px;" class="">Designated initializers that foward parameters directly to a member initializer, perhaps in a composition-based design</li><li style="font-size: 17px;" class="">If the partial initilaizer proposal is accepted, designated initializers that forward parameters to one or more partial initializers</li></ul><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">NOTE: I haven’t had time to think too much aboue use cases beyond initialization. Please share examples and I will add them to this proposal.</p><h2 id="proposedsolution" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Proposed solution</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The proposed solution is to introduce an automatic parameter forwarding mechansim. It allows users to provide direct arguments for some parameters while forwarding others.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The basic mechanism looks like this:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, s: s, f: f, d: d, b: b)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Some things to note about the syntax:</p><ol style="margin-top: 21px; margin-bottom: 21px; padding-left: 1.5em; color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; font-size: 15px;" class=""><li style="font-size: 17px;" class=""><code style="line-height: 1;" class="">...fooParams</code>&nbsp;is a placeholder introduced with&nbsp;<code style="line-height: 1;" class="">...</code>&nbsp;and followed by an identifier.</li><li style="font-size: 17px;" class="">In the signature it can be placed anywhere in the parameter list.</li><li style="font-size: 17px;" class="">At the call site, it must appear at the end of the argument list.</li><li style="font-size: 17px;" class="">The placeholder matches the parameters not directly provided including their external label and default value if those exist.</li><li style="font-size: 17px;" class="">Parameters corresponding to the matched parameters are synthesized by the compiler where the placeholder exists in the parameter list, including the default argument if one exists.</li><li style="font-size: 17px;" class="">The identifier portion of the placeholder may be omitted if only one set of forwarded parameters exist within the function.</li></ol><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Additional details will be introduced with a corresponding example.</p><h3 id="omittingtheplaceholderidentifier" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Omitting the placeholder identifier</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The above example can be written more concisely by omitting the placeholder identifier.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, ...)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, s: s, f: f, d: d, b: b)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">NOTE: If the community feels strongly that the identifier should be required I am willing to do so.</p><h3 id="multipleforwardedparametersets" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Multiple forwarded parameter sets</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">It is possible for a single function to forward more than one set of parameters:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>)</span></span> { }
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo2</span><span class="hljs-params">(d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams, ...foo2Params)</span></span> {
    foo2(...foo2Params)
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, s: s, f: f, d: d, b: b)
}</code></pre><h3 id="directarguments" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Direct arguments</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">Any direct arguments provided in the forwarding call must follow the usual argument ordering rules, with the only exception being that it is allowed to omit some arguments that would normally be required. When the compiler performs forwarding it will insert forwarded arguments in the correct location.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// error: `i` must precede `s` in the argument list</span>
    foo(s: <span class="hljs-string" style="color: rgb(221, 17, 68);">"hello"</span>, i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, f: <span class="hljs-number" style="color: rgb(0, 153, 153);">0</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(s s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(i: <span class="hljs-number" style="color: rgb(0, 153, 153);">32</span>, s: s, f: <span class="hljs-number" style="color: rgb(0, 153, 153);">0</span>, d: d, b: b)
}</code></pre><h3 id="multi-forwardingthesameparameters" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Multi-forwarding the same parameters</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">It is allowed to use the same identifier in multiple forwarding calls as long as the signature of the matched parameters matches exactly, including any default values.&nbsp;</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>)</span></span> { }
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">baz</span><span class="hljs-params">(...fooBarParams)</span></span> {
    foo(...fooBarParams)
    bar(...fooBarParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes: </span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">baz</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>)</span></span> {
    foo(i: i, s: s, d: d)
    bar(i: i, s: s, d: d)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">NOTE: This provision might be controversial. If the community doesn’t like it or the implementation is too complex I will remove it.</p><h3 id="unambiguouscall" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Unambiguous call</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">When forwarding parameters to a function that is overloaded the caller must provide enough direct arguments to make the call unambiguous.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// error: ambiguous use of foo</span>
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// foo(i: 32, ...fooParams)</span>
    
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ok: `b` makes the call to foo unambiguous</span>
    foo(b: <span class="hljs-literal">true</span>, ...fooParams)
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ok: `f` makes the call to foo unambiguous</span>
    foo(f: <span class="hljs-number" style="color: rgb(0, 153, 153);">24</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes: </span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>)</span></span> {
    foo(i: i, s: s, d: d, b: <span class="hljs-literal">true</span>)
    foo(i: i, s: s, d: d, f: <span class="hljs-number" style="color: rgb(0, 153, 153);">24</span>)
}</code></pre><h3 id="defaultvalues" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Default values</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">When forwarding to a function that accepts default values it is possible to explicitly request the default value. This allows for disambiguation and also allows the forwarding function to suppress a defaulted parameter from participating in forwarding without needing to supply a specific value. The&nbsp;<code style="line-height: 1;" class="">default</code>&nbsp;keyword is used to do this.</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">We can modify the previous example to use the defualt values:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, f: Float = <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ok: `b` makes the call to foo unambiguous, still uses default value</span>
    foo(b: <span class="hljs-keyword" style="font-weight: bold;">default</span>, ...fooParams)
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// ok: `f` makes the call to foo unambiguous, still uses default value</span>
    foo(f: <span class="hljs-keyword" style="font-weight: bold;">default</span>, ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>)</span></span> {
    foo(i: i, s: s, d: d, b: <span class="hljs-literal">false</span>)
    foo(i: i, s: s, d: d, f: <span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">It is also possible to explicitly request all defaults at once using&nbsp;<code style="line-height: 1;" class="">default...</code>. In this example,&nbsp;<code style="line-height: 1;" class="">foo</code>is not overloaded:</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-params">(i i: Int, s: String, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    foo(<span class="hljs-keyword" style="font-weight: bold;">default</span>..., ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(i i: Int, s: String)</span></span> {
    foo(i: i, s: s, d: <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: <span class="hljs-literal">false</span>)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">NOTE: The actual implementation of default arguments looks somewhat different. These examples are intended to communicate the behavior, not the exact details of implementation.</p><h3 id="genericparameters" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Generic parameters</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">If the types of any matched parameters reference any generic type parameters of the forwardee the generic type parameters must also be forwarded, along with any constraints on those generic parameters.&nbsp;</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-generics">&lt;T&gt;</span><span class="hljs-params">(i i: Int, s: String, t: T, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    foo(...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-generics">&lt;T&gt;</span><span class="hljs-params">(i i: Int, s: String, t: T, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(i: i, s: s, t: t, d: d, b: b)
}</code></pre><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">If a generic parameter is referenced in a constraint that also references a generic parameter that will not be forwarded the constraint is resolved to a concrete type when possible. This may not be possible in all cases. When it is not possible a compiler error will be necessary.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-generics">&lt;S: SequenceType, T: SequenceType where S.Generator.Element == T.Generator.Element&gt;</span>
    <span class="hljs-params">(s: S, t: T)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-params">(...fooParams)</span></span> {
    foo(t: [<span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>], ...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-generics">&lt;S: SequenceType where S.Generator.Element == Int&gt;</span><span class="hljs-params">(s: S)</span></span> {
    foo(s: s, t: [<span class="hljs-number" style="color: rgb(0, 153, 153);">42</span>])
}</code></pre><h3 id="synthesziedinternalnames" style="color: rgb(17, 17, 17); margin: 21px 0px; font-size: 20px; line-height: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Syntheszied internal names</h3><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The compiler must ensure that all synthesized parameters have internal names that do not conflict with the internal names of any manually declared parameters. This applies to both generic type parameter names as well as value arguments in the parameter list of the function.</p><pre style="margin-top: 21px; margin-bottom: 21px; tab-size: 4; color: rgb(17, 17, 17); font-size: 15px; background-color: rgb(248, 248, 248);" class=""><code class="swift hljs" style="line-height: inherit; display: block; padding: 0.5em; color: rgb(51, 51, 51); height: auto;"><span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">foo</span><span class="hljs-generics">&lt;T&gt;</span><span class="hljs-params">(i i: Int, s: String, t: T, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> { }

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// user writes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-generics">&lt;T&gt;</span><span class="hljs-params">(t: T, ...fooParams)</span></span> {
    <span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// do something with t</span>
    foo(...fooParams)
}

<span class="hljs-comment" style="color: rgb(153, 153, 136); font-style: italic;">// compiler synthesizes:</span>
<span class="hljs-func"><span class="hljs-keyword" style="font-weight: bold;">func</span> <span class="hljs-title" style="color: rgb(153, 0, 0); font-weight: bold;">bar</span><span class="hljs-generics">&lt;T, InternalCompilerIdentifier&gt;</span><span class="hljs-params">(t: T, i i: Int, s: String, t internalCompilerIdentifier: InternalCompilerIdentifier, d: Double = <span class="hljs-number" style="color: rgb(0, 153, 153);">43</span>, b: Bool = <span class="hljs-literal">false</span>)</span></span> {
    foo(t: t, i: i, s: s, t: internalCompilerIdentifier, d: d, b: b)
}</code></pre><h2 id="detaileddesign" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Detailed design</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">TODO but should fall out pretty clearly from the proposed solution</p><h2 id="impactonexistingcode" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Impact on existing code</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">This is a strictly additive change. It has no impact on existing code.</p><h2 id="alternativesconsidered" style="color: rgb(17, 17, 17); font-size: 27px; line-height: 42px; margin-top: 42px; margin-bottom: 21px; font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif;" class="">Alternatives considered</h2><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">I believe the forwarding mechanism itself is pretty straightforward and any alternatives would be lose functionality without good reason.&nbsp;</p><p style="color: rgb(17, 17, 17); font-family: 'Helvetica Neue', Helvetica, Arial, Verdana, sans-serif; word-wrap: break-word; margin: 1.3125em 0px; font-size: 1.1429em; line-height: 1.3125em;" class="">The placeholder syntax is of course fair game for bikeshedding. I consider anything reasonably clear and concise to be acceptable.</p></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k6PE08XyqhnW335s7EfoynLnb0RFI23FoJ5evCRSoe08HSSsG6aHPJkERLVoloVv9CZuKKNr0kJqgyyiaVzBhjiZfn-2BetdmRfPMDVc5mNV3QsbWXa78jKmnmumd6MFkpRAxhORq3UfUWCDywp3PNaYscppWoVMp-2FB-2BYo-2BN-2BRRA1ZTgK6DXoBkkXLae-2BtDLv8uY-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<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></blockquote></div><br class=""></div></body></html>