<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 Nov 2, 2016, at 11:38 AM, John McCall &lt;<a href="mailto:rjmccall@apple.com" class="">rjmccall@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">On Nov 2, 2016, at 9:05 AM, Joe Groff via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><blockquote type="cite" class="">On Nov 1, 2016, at 9:23 PM, Slava Pestov &lt;<a href="mailto:spestov@apple.com" class="">spestov@apple.com</a>&gt; wrote:<br class=""><br class=""><blockquote type="cite" class=""><br class="">On Nov 1, 2016, at 11:00 AM, Jordan Rose via swift-dev &lt;<a href="mailto:swift-dev@swift.org" class="">swift-dev@swift.org</a>&gt; wrote:<br class=""><br class="">- Does this help us with the nested dictionary CoW problem? `foo["bar"]["baz"] += 1`<br class=""></blockquote><br class="">My understanding is that this problem arises because we don’t have ‘optional addressors’. A dictionary lookup might return nil. If addressors had a way to return an optional wrapping a pointer, and optional evaluation supported this, we could do in-place updates of this kind. For Apple people: I have a radar that I think describes this problem (<a href="rdar://17509619" class="">rdar://17509619</a>).<br class=""></blockquote><br class="">I think our long-term goal here is to let the property definition fully control the `inout` access with a coroutine-like definition, something like:<br class=""><br class="">var foo: T {<br class="">get { return /*value for read-only access*/ }<br class="">set { _foo = /*write-only access*/ }<br class="">mutate {<br class="">&nbsp;&nbsp;var tmp = prepareForMutation()<br class="">&nbsp;&nbsp;yield &amp;tmp // continue nested inout access<br class="">&nbsp;&nbsp;reconcileMutation(tmp)<br class="">}<br class="">}<br class=""><br class="">This should let the dictionary implementation do whatever it needs to present a moved Optional value to the chained access. If Dictionary can't store Optionals directly inline in all cases, we ought to still be able to rely on enforced inout uniqueness to get away with moving in and out of a temporary.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">It's tricky, because if Dictionary is going to support non-movable values, then we also want the non-mutating accessor to be able to return a Borrowed&lt;Optional&lt;V&gt;&gt;, which it can't do if that representation has to be a pointer to an Optional&lt;V&gt;. &nbsp;It can returned an Optional&lt;Borrowed&lt;V&gt;&gt; just fine, of course.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">This relates to the earlier conversation we had about borrowed tuples. &nbsp;We may have to make the representation of a Borrowed&lt;T&gt; potentially different from just a T*, and that really stinks.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></div></blockquote></div><br class=""><div class="">Being able to model an access as Optional&lt;borrowed T&gt; or Optional&lt;inout T&gt; might fit better with the move-only types model for dictionaries, and would be useful for other things like optional protocol members and properties found on AnyObject. Dictionaries have the "delete" operation to shoehorn into the `inout Optional&lt;T&gt;` model and give `foo["bar"] = nil` meaning, but there are other mutation interfaces for which that isn't true. (Even for dictionaries, I've always felt it was a bit of a hack.)</div><div class=""><br class=""></div><div class="">-Joe</div></body></html>