<div dir="ltr"><span class="im" style="font-size:13px">> * What is your evaluation of the proposal?<br><br></span>+0.5 A good improvement. I think it could be made less special-case, but that can be built on top of this. See my next comments for more details.<br style="font-size:13px"><span class="im" style="font-size:13px"><br>> * Is the problem being addressed significant enough to warrant a change to Swift?<br><br></span>Not a major problem, but an incremental improvement with easy migration and no negative impact.<br style="font-size:13px"><span class="im" style="font-size:13px"><br>> * Does this proposal fit well with the feel and direction of Swift?<br><br></span><span style="font-size:13px">Yes, although I think it needs a little more work before it's properly Swifty.</span><div><span style="font-size:13px"><br></span></div><div>We are now saying it's part of the argument's type, but that type is *only* an argument type, you cannot use that type elsewhere. I can see this as being confusing for people unfamiliar with inout. When it's part of the label it's obvious it's only usable as an argument.</div><div><br></div><div>If we can do this:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">func foo(a: B)</font></div><div><font face="monospace, monospace">var b: B</font></div></blockquote><div><br></div><div>Why can't we do this?</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">func foo(a: inout B)</font></div></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><font face="monospace, monospace">var b: inout B</font></div></blockquote><div><br></div><div>I'd like to see a reference modifier for types that can be used elsewhere.</div><div><br></div><div><div>It seems reasonable to be able to refer to the inout type outside of an argument context.</div><div><div><br></div><div>I presume that this:</div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">func</span> test(<span style="color:rgb(187,44,162)">inout</span> a: <span style="color:rgb(112,61,170)">Int</span>) {</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> a = <span style="color:rgb(39,42,216)">456</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span> a = <span style="color:rgb(39,42,216)">123</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)">test<span style="color:rgb(0,0,0)">(&</span><span style="color:rgb(79,129,135)">a</span><span style="color:rgb(0,0,0)">)</span></p></blockquote><div><div><br></div><div>Is roughly equivalent to something like this:</div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">class</span> Reference<T> {</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">var</span> value: <span style="color:rgb(112,61,170)">T</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">init</span>(value: <span style="color:rgb(112,61,170)">T</span>) { <span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(79,129,135)">value</span> = value }</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">func</span> test(a: <span style="color:rgb(79,129,135)">Reference</span><<span style="color:rgb(112,61,170)">Int</span>>) {</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> a.<span style="color:rgb(79,129,135)">value</span> = <span style="color:rgb(39,42,216)">456</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">}</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span> b = <span style="color:rgb(39,42,216)">123</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span> bRef = <span style="color:rgb(79,129,135)">Reference</span>(value: <span style="color:rgb(79,129,135)">b</span>)</p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)">test<span style="color:rgb(0,0,0)">(</span><span style="color:rgb(79,129,135)">bRef</span><span style="color:rgb(0,0,0)">)</span></p></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)">b<span style="color:rgb(0,0,0)"> = </span>bRef<span style="color:rgb(0,0,0)">.</span>value</p></div></blockquote><div><div><br></div><div>I'd be happy if <b><font face="monospace, monospace">inout</font></b> it was implemented something like this, and there were optimisations introduced to ensure this was done as efficiently as inout currently is.</div></div></div></div><div><span class="im" style="font-size:13px"><br></span></div><div><span class="im" style="font-size:13px">See </span><b>potential future work</b> below for details.</div><div><span class="im" style="font-size:13px"><br>> * If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?<br><br></span>It's roughly similar to a few other languages I've used, it seems consistent to make it about the argument's type.<br style="font-size:13px"><span class="im" style="font-size:13px"><br>> * How much effort did you put into your review? A glance, a quick reading, or an in-depth study?<br><br></span>I read through and considered the implications of making inout more explicitly part of the argument type, instead of just the function's type.<div><div><div><div><br></div><div><b>Potential future work:</b><br></div><div><br></div><div>It seems to me that <b><font face="monospace, monospace">inout</font></b>/<b><font face="monospace, monospace">&</font></b> are to <b><font face="monospace, monospace">?</font></b> what <b><font face="monospace, monospace">Reference<T></font></b> is to <b><font face="monospace, monospace">Optional<T></font></b>. We already have the <b><font face="monospace, monospace">indirect</font></b> keyword on enums, perhaps <b><font face="monospace, monospace">indirect</font>, </b><b><font face="monospace, monospace">inout</font></b>, and <b><font face="monospace, monospace">&</font></b> should all be combined into one concept. </div></div></div><div><br></div><div><font face="monospace, monospace">&Type</font> is equivalent to:</div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)">Reference<span style="color:rgb(0,0,0)"><</span>Type<span style="color:rgb(0,0,0)">></span></p></div></blockquote><font face="Menlo"><span style="font-size:11px"><br></span></font><div><div><span style="font-family:Menlo;font-size:11px">test(&foo)</span> is equivalent to:</div></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span> fooRef = <span style="color:rgb(79,129,135)">Reference</span>(value: <span style="color:rgb(79,129,135)">foo</span>)</p></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(49,89,93)">test</span><span style="color:rgb(0,0,0)">(</span>fooRef<span style="color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">
</p><span style="color:rgb(79,129,135);font-family:Menlo;font-size:11px">foo</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)"> = </span><span style="color:rgb(79,129,135);font-family:Menlo;font-size:11px">fooRef</span><span style="font-family:Menlo;font-size:11px;color:rgb(0,0,0)">.</span><span style="color:rgb(79,129,135);font-family:Menlo;font-size:11px">value</span></blockquote><div><div><div><br></div><div>Similar to optionals you could have syntactic sugar to get and set the value, simplifying this to:</div><div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span> fooRef = &<span style="color:rgb(79,129,135)">foo</span></p></blockquote><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(49,89,93)">test</span><span style="color:rgb(0,0,0)">(</span>fooRef<span style="color:rgb(0,0,0)">)</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)">foo<span style="color:rgb(0,0,0)"> = </span>fooRef</p></blockquote><font color="#4f8187" face="Menlo"><span style="font-size:11px"><div><font color="#4f8187" face="Menlo"><span style="font-size:11px"><br></span></font></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small">With an enum instead of using indirect you could use Reference<T>.</span><font color="#4f8187" face="Menlo"><span style="font-size:11px"><br></span></font></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small"><b>Potential issues:</b></span></div><br></span></font>I'm not sure if it will be confusing that using <b><font face="monospace, monospace">&</font></b> in a declaration makes a copy; using <b><font face="monospace, monospace">&</font></b> in an argument makes a copy, then copies it back after the call. Also this could be confusing if you're used to pointers/references and expect changing foo to change the value of `fooRef`. This may be solved if foo is aliased to fooRef for the lifetime of fooRef, however that may be confusing for users that aren't used to pointers/references.<font color="#4f8187" face="Menlo"><span style="font-size:11px"><br></span></font><div><div></div></div></div><div><br></div><div>There's also the issue of what to do if someone writes <span style="font-family:Menlo;font-size:11px">&&</span><span style="font-family:Menlo;font-size:11px;color:rgb(79,129,135)">foo</span>, does this make any sense as it's not really a pointer, and you cannot offset it? I think that calling & on a reference type would have to be identity.</div><div><br></div><div><b>Potential future-future work:</b></div><div>Make the distinction between struct and class stop at SIL, implement them on top of a Reference<T> style type (with compiler support), then use something akin to property behaviours to implement inheritance, overloading, etc.</div><div><br></div><div>Any simplifications/generalisations like this should only really be done if they don't make it harder to interpret error messages.</div><div><br></div><div>On Friday, 12 February 2016, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hello Swift community,<br>
<br>
The review of "Adjusting inout Declarations for Type Decoration" begins now and runs through February 15th. The proposal is available here:<br>
<br>
<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md</a><br>
<br>
Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at<br>
<br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
or, if you would like to keep your feedback private, directly to the review manager.<br>
<br>
What goes into a review?<br>
<br>
The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:<br>
<br>
* What is your evaluation of the proposal?<br>
* Is the problem being addressed significant enough to warrant a change to Swift?<br>
* Does this proposal fit well with the feel and direction of Swift?<br>
* If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?<br>
* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?<br>
<br>
More information about the Swift evolution process is available at<br>
<br>
<a href="https://github.com/apple/swift-evolution/blob/master/process.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/process.md</a><br>
<br>
Thank you,<br>
<br>
-Chris Lattner<br>
Review Manager<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a>swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div></div>
</div></div></div>