<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=""><div class="">1: Collection Composition</div><div class=""><br class=""></div><div class="">As much as the high-level picture is focused on safety, I’d just like to request a strong focus on making sure the eventual ownership system addresses the common issues like avoiding copies when mutating through optionals, or when nesting collections, and so on.</div><div class=""><br class=""></div><div class="">Point fixes like the custom `.values` collection on `Dictionary` that just got approved are useful, but hopefully ownership can provide a general solution.</div><div class=""><br class=""></div><div class="">2: Mutating Iteration &amp; Granularity</div><div class=""><br class=""></div><div class="">If I understood the mutating-iteration section right it reads as if `for inout` would only be available on `MutableCollection`. Is that correct?</div><div class=""><br class=""></div><div class="">If so that does seem limiting, as e.g. for a&nbsp;`Dictionary` it’d be nice if something like this were expressible:</div><div class=""><br class=""></div><div class="">&nbsp; for (key, inout value) in someDictionary {</div><div class="">&nbsp; }</div><div class=""><br class=""></div><div class="">…assuming there’s not some insurmountable technical obstacle.</div><div class=""><br class=""></div><div class="">3: Mutable Views</div><div class=""><br class=""></div><div class="">Currently a major pain point of Swift has been exposing “mutable views” into a type in a reasonable way. Apologies for length, but here’s an extended example:</div><div class=""><br class=""></div><div class="">&nbsp; /// Implements a 2D grid (of size fixed upon initialization).</div><div class="">&nbsp; /// **Not** a `Collection` itself but has many *views* into it that *are* `Collection`s.</div><div class="">&nbsp; ///</div><div class=""><div class="">&nbsp; struct Grid2D&lt;T&gt; {</div><div class="">&nbsp; &nbsp; // typical CoW backing storage</div><div class="">&nbsp; &nbsp; fileprivate var storage: Grid2DStorage&lt;T&gt;</div><div class="">&nbsp; &nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; /// Obtain a linear traversal of our grid:</div><div class="">&nbsp; &nbsp; /// - parameter corner: The corner at which we start (e.g. `northWest`)</div><div class="">&nbsp; &nbsp; /// - parameter motion: The order in which we travel (`latitudeThenLongitude` or `longitudeThanLatitude`)</div><div class="">&nbsp; &nbsp; ///</div><div class="">&nbsp; &nbsp; /// - returns: A read-only `Collection` that visits each grid location in `self`, following the requested traversal</div><div class="">&nbsp; &nbsp; func traversal(from corner: Grid2DCorner, following motion: Grid2DMotion) -&gt; Grid2DTraversal&lt;T&gt;</div><div class="">&nbsp; }</div></div><div class=""><br class=""></div><div class="">…wherein `Grid2DTraversal&lt;T&gt;` is, as noted, a "read-only view” into its parent that also adopts `Collection`.</div><div class=""><br class=""></div><div class="">What would be nice is to be able to make that `Grid2DTraversal&lt;T&gt;` into a mutable view in a way that’s also *safe*; what I mean is something like:</div><div class=""><br class=""></div><div class="">&nbsp; extension Grid2D {</div><div class="">&nbsp;&nbsp;</div><div class="">&nbsp; &nbsp; mutating func mutatingTraversal&lt;T&gt;(from corner: Grid2DCorner, following motion: Grid2DMotion, _ mutator: (inout Grid2DTraversal&lt;T&gt;) -&gt; R) -&gt; R {</div><div class="">&nbsp; &nbsp; &nbsp; var t = self.traversal(from: corner, following: motion)</div><div class="">&nbsp; &nbsp; &nbsp; return mutator(&amp;t)</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">&nbsp; }</div><div class=""><br class=""></div><div class="">…with the specific goals of (a) having mutations applied via `Grid2DTraversal` get directly written-through to the underlying storage (w/out pointless copying) but also (b) making `Grid2DTraversal` generally act safely in all other contexts.</div><div class=""><br class=""></div><div class="">As it is the “best” way to squeeze this into the type system at this time is arguably:</div><div class=""><br class=""></div><div class="">- define Grid2DTraversal:</div><div class="">&nbsp; - to have as a strong reference to the backing storage</div><div class="">&nbsp; - as only having the read-only methods</div><div class="">- *also* define MutableGrid2DTraversal:</div><div class="">&nbsp; - to have an unowned reference to the backing storage</div><div class="">&nbsp; - also include the mutating methods</div><div class=""><br class=""></div><div class="">…and then just be careful with API design and patterns of use; in particular only provide access to `MutableGrid2DTraversal&lt;T&gt;` values in the context of closures passed into dedicated functions like `mutatingTraversal`, above…and then just be disciplined never to extract those passed-in values.</div><div class=""><br class=""></div><div class="">Needless to say this isn’t a very satisfactory state of affairs—it is well into “why am I bothering with all this?” territory—and it’d be *far* nicer if the ownership system would allow for `Grid2DTraversal`:</div><div class=""><br class=""></div><div class="">- to adopt `Collection` without restriction</div><div class="">- to adopt `MutableCollection` only in certain ownership contexts</div><div class="">- to have reasonable control over where those contexts apply&nbsp;</div><div class=""><br class=""></div><div class="">Anyways, it’s not clear to me, personally, whether or not the above is within the scope of any likely, concrete ownership system that’d follow from the manifesto or not…but if at all possible I’d prefer the eventual ownership system make it reasonable—and reasonably safe—to implement “small-c ‘collection’s that can safely-and-efficiently expose various *mutable* views as big-C `Collection`s”.</div><div class=""><br class=""></div><div class="">Apologies if all of the above considerations have answers that follow trivially from the manifesto; it’s just unclear personally whether the features described in the manifesto would work together to allow something like the above to be implemented more-reasonably than currently the case.</div><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 17, 2017, at 11:08 AM, John McCall 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 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=""><blockquote type="cite" class="" style="margin: 15px 0px;"><div class="">On Feb 17, 2017, at 4:50 AM, Adrian Zubarev &lt;<a href="mailto:adrian.zubarev@devandartist.com" class="" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">adrian.zubarev@devandartist.com</a>&gt; wrote:</div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="bloop_markdown"><p class="" style="margin: 15px 0px; -webkit-margin-before: 0px;">Hi John, would you mind creating a markdown document for this manifesto in<span class="Apple-converted-space">&nbsp;</span><a href="https://github.com/apple/swift/tree/master/docs" class="" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none; -webkit-margin-before: 0px;">https://github.com/apple/swift/tree/master/docs</a>? :)</p><div class=""><br class="" style="-webkit-margin-before: 0px;"></div></div></div></div></blockquote>Yes, it should go in the repository. &nbsp;That commit is pending, but the in meantime, you can see the document properly rendered at:</div><div 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="">&nbsp;&nbsp;<a href="https://github.com/rjmccall/swift/blob/4c67c1d45b6f9649cc39bbb296d63663c1ef841f/docs/OwnershipManifesto.md" class="" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">https://github.com/rjmccall/swift/blob/4c67c1d45b6f9649cc39bbb296d63663c1ef841f/docs/OwnershipManifesto.md</a></div><div 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 class=""></div><div 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=""><font face="Helvetica Neue, Helvetica, Arial, sans-serif" class="">John.</font></div><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="">_______________________________________________</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=""><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="">swift-evolution mailing list</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=""><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=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></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=""><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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span></div></blockquote></div><br class=""></body></html>