<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 Jan 19, 2017, at 11:11 PM, Slava Pestov via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 19, 2017, at 10:52 PM, rintaro ishizaki via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="m_2220125713830145999m_-5113574630879694870gmail_msg"><div class="m_2220125713830145999m_-5113574630879694870gmail_msg"><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:-apple-system,blinkmacsystemfont,&quot;segoe ui&quot;,helvetica,arial,sans-serif,&quot;apple color emoji&quot;,&quot;segoe ui emoji&quot;,&quot;segoe ui symbol&quot;;font-size:16px" class="m_2220125713830145999m_-5113574630879694870gmail_msg">From the perspective of the caller, I think, this behavior is counterintuitive because we use "reference types" with an expectation: the referencing address would never be changed&nbsp;<em class="m_2220125713830145999m_-5113574630879694870gmail_msg" style="box-sizing: border-box;">unless</em>&nbsp;we explicitly replace the object by re-assigning to the variable in call sites, e.g.,</p><div class=""><br class=""></div></div></div></div></div></div></blockquote><div class=""><br class=""></div>Well, there’s no real difficulty here, other than potential user confusion. The ‘self’ parameter for a mutating method is passed inout, so this behaves as if you called a global function with an inout argument. The difference is of course when you pass a non-self inout argument, the compiler requires you to use the explicit &amp; syntax at the call site.</div><div class=""><br class=""></div><div class="">Is your proposal to ban calls to such mutating methods on a type that is known to be a reference type at compile time altogether? This will create an inconsistency between code that operates on concrete types and code that operates on generic parameters (in the latter case the compiler of course has no way to statically guarantee that the value is not a reference type).</div><div class=""><br class=""></div><div class="">The last time this quirk came up in internal discussions, the thought some of us had was that it might be worthwhile to prohibit classes from conforming to protocols with mutating requirements altogether. If you think about it, this makes some amount of sense — it seems like it would be quite hard to write code that can operate on both mutable values and mutable references generically, since the latter do not have value semantics:</div></div></div></blockquote><div><br class=""></div><div>Right now you could consider mutable vs non-mutable functions as “advisory” for reference types since it is up to you to fulfill that contract. &nbsp;</div><div><br class=""></div><div>I suppose you could say that reference type members can’t do any stores to self unless the function is decorated in some way to advise the compiler that the mutation is intended but that’s a big change and not terribly useful. It would still be on the programmer to use the special decoration only in appropriate places that obey the mutability invariant (think a LRU cache doing a read() where mutation is not observable by the caller).</div><div><br class=""></div><div>The alternate world where I can’t have value and reference types conform to the same protocol if the protocol has any mutating methods is a bit stifling.</div><div><br class=""></div><div><br class=""></div><div>IMHO in this case the consistency is more important than the quirk.&nbsp;</div><div><br class=""></div><div><br class=""></div><div>Russ</div></div><br class=""></body></html>