<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><blockquote type="cite" class=""><div class="">On Aug 3, 2017, at 7:20 AM, Tino Heth &lt;<a href="mailto:2th@gmx.de" class="">2th@gmx.de</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="">Hi Daryle,<div class=""><br class=""></div><div class="">I think we agree a lot on the importance of fixed-size arrays, but have a different opinion on which aspect is the most valuable… (so we now only have to agree that mine is better ;-) ;-)</div><div class="">My motivation for FSA is safety and convenience:</div><div class="">I want to iterate over C arrays in a straightforward way, but primarily, I don't want to accidentally multiply a vector of size 3 with a 2×2 matrix.</div></div></div></blockquote><div><br class=""></div><div>Data modeling is important for me too. That’s why the proposal includes multi-dimensionality and why I didn’t just jam in Collection support. We don’t want to add conformance then find out that was a mistake.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Of course, fast is cool, but I don't expect to suffer from bad performance because of implementation details like how, where and when memory allocation happens.</div><div class="">Your focus, on the other hand, seems to be performance:</div><div class="">You don't want to give guarantees about the order because of (hypothetical?) optimisations that could be blocked by that, and avoid initialisation overhead.</div></div></div></blockquote><div><br class=""></div><div>I also don’t want to block parallel/vector processing.</div><div><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div><font face="Monaco" class="">let a: @vector [4; Int] = //…</font></div></div><div><div><font face="Monaco" class="">let b: @vector [4; Int] = //…</font></div></div><div><div><font face="Monaco" class="">var c: @vector [4; Int] = //…</font></div></div><div><div><font face="Monaco" class="">//…</font></div></div><div><div><font face="Monaco" class="">loop: for i in a {</font></div></div><div><div><font face="Monaco" class="">&nbsp; &nbsp; c[ #indexOf(loop) ] = i * b[ #indexOf(loop) ]</font></div></div><div><div><font face="Monaco" class="">}</font></div></div><div><div><font face="Monaco" class="">//…</font></div></div></blockquote><div><div><br class=""></div><div>I want the compiler to potentially be able to see that the elements are being computed in formation and use vector-unit instructions instead of serial processing.</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">You brought "withUnsafeFlattening" to the table to add convenience, but I think that is the wrong direction:</div><div class="">Safe should be default, and it's quite common that you have to live with "unsafe" when you need "fast".</div></div></div></blockquote><div><br class=""></div><div>The name has “Unsafe” because the Collection type used, UnsafeBufferPointer, does. I don’t know enough about what makes the existing “Unsafe” API that way for the flattening function to declared “safe”. It could be safe for all I know.</div><div><br class=""></div><div>A substitute Collection-access function besides “withUnsafeFlattening” would either copy the elements (i.e. be inefficient, especially for large arrays) or somehow secretly maintain a reference to the array in memory. The latter would then be “withUnsafeFlattening” with a prettier name.</div><div><br class=""></div><div>My first reason for “withUnsafeFlattening” was to allow API to use any FSA of a given element type, no matter the shape.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">As you don't want to confirm to Sequence at all, it shouldn't bother you if the iterator sacrifices a tiny bit of performance in exchange for a reliable order, and when you really need&nbsp;piecemeal initialisation, you could take a FSA-Variant that skips initialisation of elements.</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Of course, that wouldn't be ideal, and there should be an "Unsafe" in the name of that type — but I don't think tuple-like delayed initialisation would help when solving real-world problems:</div><div class="">The "x.0 = 0; x.1 = 1" case is trivial and can be done with normal init, and when this isn't enough, you most likely loose all guarantees because you use a loop to fill that array*.</div></div></div></blockquote><div><br class=""></div><div>Using a loop for array initialization is why I suggested we should look into run-time DI, which should be kept to restricted circumstances.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I really appreciate the effort you spend for digging into the low-level details, and hope that we end up with a draft that satisfies your use case.</div><div class=""><br class=""></div><div class="">- Tino</div><div class=""><br class=""></div><div class="">* There are actually cases where you want to compute the value of one element based on another one, but that might as well be an indicator that you are better off with a tuple, instead of using an array.</div><div class=""><br class=""></div><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class="" 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;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">So would you say Dictionary shouldn't conform to Collection either?</div><div class="">Just because a type conforms to a protocol doesn't mean it can't add its own methods on top.</div></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">But the FSA interface and the Sequence/Collection interface would be very similar, basically competing, leading to a schizophrenic interface. Since another part of the overall FSA interface implements Collection, just use that.</div></div></div></div></blockquote><div class="">Yes, I can't argue against the claim that Collection sometimes feels a little bit odd :-( — but it is what it is, and maybe there will be improvements in the future that could take into account the experience with FSA.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><blockquote type="cite" class="" 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;"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">Swift has one-dimensional arrays, and they support Collection... this may sound like nitpicking that only works because there is no explicit "fixed-size" in you statement, but feel free to prove me wrong for FSAs.</div></div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; 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; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Yes, I meant FSAs, not both them and Array; it’s long-winded to keep adding the “fixed-size” part.</div></div></div></div></blockquote><div class="">So we do agree that there is no fundamental reason that stops FSAs from being collections? ;-)</div></div></div></div></div></blockquote><div><br class=""></div><div>Besides that they can’t be Sequences, unless you throw away allowing parallel/vector processing in the future. (That can’t be bolted onto Version 2, since committing to Sequence means you committed to single-thread iteration.) Just found out that C++ 17 (optionally) adds parallel/vector processing to its for-loops. I guess I caught on to a trend.</div><div><br class=""></div><div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">—&nbsp;</div><div class="">Daryle Walker<br class="">Mac, Internet, and Video Game Junkie<br class="">darylew AT mac DOT com&nbsp;</div></div></div><br class=""><div><blockquote type="cite" class=""></blockquote></div></div></div></body></html>