<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="">On May 7, 2016, at 3:53 PM, Dave Abrahams &lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Sat May 07 2016, Matthew Johnson &lt;<a href="http://matthew-at-anandabits.com" class="">matthew-AT-anandabits.com</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class="">Sent from my iPad<br class=""><br class="">On May 7, 2016, at 2:21 AM, Andrew Trick via swift-evolution<br class="">&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;On May 6, 2016, at 5:48 PM, Dave Abrahams via swift-evolution<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I don’t mean to imply that it is the *only* valuable<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property. However, it I (and many others) do believe it is an<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;extremely valuable<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property in many cases. Do you disagree?<br class=""><br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I think I do. What is valuable about such a protocol? What generic<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;algorithms could you write that work on models of PureValue but don't<br class=""> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;work just as well on Array&lt;Int&gt;?<br class=""><br class=""> &nbsp;&nbsp;&nbsp;class Storage {<br class=""> &nbsp;&nbsp;&nbsp;var element: Int = 0<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;struct Value {<br class=""> &nbsp;&nbsp;&nbsp;var storage: Storage<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;func amIPure(v: Value) -&gt; Int {<br class=""> &nbsp;&nbsp;&nbsp;v.storage.element = 3<br class=""> &nbsp;&nbsp;&nbsp;return v.storage.element<br class=""> &nbsp;&nbsp;&nbsp;}<br class=""><br class=""> &nbsp;&nbsp;&nbsp;I (the optimizer) want to know if 'amIPure' is a pure function. The<br class=""> &nbsp;&nbsp;&nbsp;developer needs to tell me where the boundaries of the value lie. Does<br class=""> &nbsp;&nbsp;&nbsp;'storage' lie inside the Value, or outside? If it is inside, then Value is a<br class=""> &nbsp;&nbsp;&nbsp;'PureValue' and 'amIPure' is a pure function. To enforce that, the developer<br class=""> &nbsp;&nbsp;&nbsp;will need to implement CoW, or we need add some language features.<br class=""><br class="">Thank you for this clear exposition of how PureValue relates to pure functions.<br class="">This is the exact intuition I have about it but you have stated it much more<br class="">clearly.<br class=""><br class="">Language features to help automate CoW would be great. It would eliminate<br class="">boilerplate, but more importantly it would likely provide more information to<br class="">the compiler.<br class=""></blockquote><br class="">Whoa; Andy never suggested this would help automate CoW. &nbsp;Are you<br class="">suggesting that? &nbsp;How would it work?<br class=""></div></div></blockquote><div><br class=""></div><div>Quoting Andy:</div><div><br class=""></div><div>"<span style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">I (the optimizer) want to know if 'amIPure' is a pure function. The developer needs to tell me where the boundaries of the value lie. Does 'storage' lie inside the Value, or outside? If it is inside, then Value is a 'PureValue' and 'amIPure' is a pure function. To enforce that, <b class="">the developer will need to implement CoW, or we need add some language features</b>.</span>"</div><div><br class=""></div><div>I was referring to new language features that eliminate the need for the developer to implement CoW manually while preserving the same semantics. &nbsp;</div><div><br class=""></div><div>I don’t know about the general case, but in simple cases I can imagine a feature such as “indirect struct” or Box&lt;T: ValueType&gt; which would contain a reference to a struct on the heap. &nbsp;Any time a mutating operation was performed on a non-uniquely referenced struct it would be copied first and the internal reference updated to point to the new copy on the heap. &nbsp;This is the kind of thing I had in mind when I said “automating CoW”.</div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class="">-- <br class="">-Dave<br class=""></div></div></blockquote></div><br class=""></body></html>