<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 5, 2017 at 5:36 PM, Andrew Trick <span dir="ltr">&lt;<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><blockquote type="cite"><div><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div><br></div><div>In the new raw initializeMemory methods, Xiaodi and I agreed to make</div><div>it more clear that the offset is in terms of `self` rather than</div><div>`from`, and to further reduce ambiguity by forcing manual stride</div><div>computation and using an explicit &quot;offset&quot; label. The call site will</div><div>be just as explicit as dropping down to `baseAddress` but without any</div><div>pointer conversion boilerplate.</div><div><br></div><div>UMRBP (raw buffer):</div><div>+++ func initializeMemory&lt;T&gt;(<wbr>atByteOffset:as:from:)</div><div>+++ func moveInitializeMemory&lt;T&gt;(<wbr>atByteOffset:as:from:)</div><div><br></div></div></div></blockquote><div><br></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div>Agree, but the label should just be `<span style="font-family:monospace,monospace">atByte:</span>`, not `<span style="font-family:monospace,monospace">atByteOffset:</span>`. after all, we don’t use `<span style="font-family:monospace,monospace">atOffset:</span>` in the strided case; its obvious that it’s an offset</div></div></div></div></blockquote><div dir="auto" 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"><br></div><div dir="auto" 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">The existing APIs use the terminology &quot;byte offset&quot;--for example, URP.load(fromByteOffset:as:). The rationale is that &quot;at&quot; without a noun that follows implies, per Swift API naming guidelines, &quot;at index.&quot; If you want to specify, as we do here, what the index _is_, then it&#39;s written out in full.</div></div></blockquote><div><br></div></span>Yes, it seems overly cumbersome, but I was following existing conventions which were intentionally very explicit. <br></div></div></blockquote><div><br></div><div>it’s visually cumbersome because the “atByteOffset” overwhelms the other two arguments but I guess i could live with it. <br></div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div></div><div><span class=""><br><blockquote type="cite"><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_extra"><div class="gmail_quote"><div></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div><br></div></div></div></blockquote></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><div></div><div>We don&#39;t have a consensus, but I think the suggestion to distinguish</div><div>between single value vs. multiple semantics was good. Otherwise,</div><div>adding the default count could be very misleading. Normally, we try to</div><div>minimize surface area, but adding two methods for the single-value case</div><div>avoids ambiguity between the buffer and pointer semantics:</div><div><br></div><div>UMP (pointer)</div><div>--- func initialize(to:count:(=1))</div><div>+++ func initialize(to:)</div><div>+++ func initialize(repeating:count:) // no default count</div><div>+++ func assign(to:)</div><div>+++ func assign(repeating:count:) // no default count</div><div><br></div><div>UMRP (raw pointer):</div><div>--- func initializeMemory&lt;T&gt;(as:at:(=0)<wbr>count:(1)to:)</div><div>+++ func initializeMemory&lt;T&gt;(as:<wbr>repeating:count:) // remove default count<span class="m_-1264289912044773242Apple-converted-space"> </span><br></div></div></div></blockquote><div><br></div></div></div></div><div><div class="gmail_extra"><div class="gmail_quote"><div>still extremely suspicious of this but i’m willing to compromise. also there should be an `<span style="font-family:monospace,monospace">initializeMemory&lt;T&gt;(at:to:)</span>` to match the typed methods</div></div></div></div></blockquote><div dir="auto" 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"><br></div><div dir="auto" 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">Do you mean initializeMemory&lt;T&gt;(as:to:)?</div></blockquote><div><br></div></span><div>I don’t think it’s necessary since raw buffers are not normally used to hold a single typed element. We don’t need symmetry between raw and typed pointers and I wouldn’t want to add an API that will never be used. So, I would be ok with it only if there’s some use case that I’m overlooking.</div></div></div></blockquote><div><br></div><div>The only case i can think of is initializing a buffer header but then again i rarely use raw pointers so i’m not sure how much this feature would be used. However, this function is <a href="https://developer.apple.com/documentation/swift/unsafemutablerawpointer/2427589-initializememory">already</a> in the API (with a default count of 1 and offset of 0) so there’s that.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><span class=""><div><br></div><div>-Andy</div><div><br></div><blockquote type="cite"><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div><span class="m_-1264289912044773242m_868930590277175530gmail-"><div><br></div><blockquote type="cite"><div><div class="gmail_extra"><div class="gmail_quote">On Tue, Sep 5, 2017 at 11:31 AM, Andrew Trick<span class="m_-1264289912044773242Apple-converted-space"> </span><span>&lt;<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>&gt;</span><span class="m_-1264289912044773242Apple-converted-space"> </span>wrote<wbr>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div>I think we’ve agreed to a few minor updates to this proposal. Since there hasn’t been any other feedback on the thread it may be worth posting an amended proposal so we all know what we’ve agreed on.<div><br></div><div>-Andy<br><div><br><div><blockquote type="cite"><div><div class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191h5"><div>On Sep 3, 2017, at 8:23 PM, Andrew Trick via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-interchange-newline"></div></div><div><div><div class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191h5"><div><br><div><blockquote type="cite"><div>On Sep 3, 2017, at 8:05 PM, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-interchange-newline"><div><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_extra"><div class="gmail_quote"><div>If we use byte offset, then the<span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span><span style="font-family:monospace,monospace">at</span><span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span>parameter in<span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span><span style="font-family:monospace,monospace">UnsafeMutableRawPointer</span><span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span>sho<wbr>uld be removed, since pointer arithmetic can be used instead (just like with<span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span><span style="font-family:monospace,monospace">UnsafeMutablePointer</span>).</div></div></div></div></blockquote><div dir="auto" 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"><br></div><div dir="auto" 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">I agree that it seems quite sensible to remove the ‘at’ parameter altogether from the UMRP method.</div></div></blockquote><div><br></div>No code in tree or on github is using the `at` argument. I think it can be removed. A fixit should still be possible.</div><div><br><blockquote type="cite"><div><blockquote class="gmail_quote" 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;margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div><div class="gmail_extra"><div class="gmail_quote"><div>Not convinced moving the<span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span><span style="font-family:monospace,monospace">at:</span><span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span>argument to come before the<span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span><span style="font-family:monospace,monospace">as:</span><span class="m_-1264289912044773242m_868930590277175530gmail-m_-5448707016195622191m_5074952175224083149Apple-converted-space"> </span>argument is worth it in terms of source breakage.</div></div></div></div></blockquote><div dir="auto" 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"><br></div><div dir="auto" 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">Since much of this proposal involves shuffling and relabeling arguments, I’d argue it’s better to break slight more source in one go for the optimal API than to break slightly less for a slightly less optimal API, no? (This is assuming there is agreement that ‘at:as:’ is less prone to misinterpretation than ‘as:at:’.)</div></div></blockquote></div><div><br></div><div>To be clear, we’re just talking about <wbr>UnsafeMutableRawBufferPointer.<wbr>initializeMemory now, so this is purely additive.</div><div>I think the label needs to be `atByteOffset`, and placing it before `as` makes a lot of sense because it no longer depends on the type’s stride. </div><div><br></div><div>-Andy</div></div></div></div><span>______________________________<wbr>_________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a></span></div></blockquote></div></div></div></div></blockquote></div></div></div></blockquote></span></div></div></blockquote></div></div></div></blockquote></blockquote></span></div><br></div></blockquote></div><br></div></div>