<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 28, 2017 at 7:59 PM, Andrew Trick <span dir="ltr"><<a href="mailto:atrick@apple.com" target="_blank">atrick@apple.com</a>></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;line-break:after-white-space"><span><br><div><blockquote type="cite"><div>On Sep 6, 2017, at 10:15 PM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>> wrote:</div><br class="m_-4760639243348783802m_-7775641474127287529Apple-interchange-newline"><div><div dir="ltr">okay so I think so far what’s been agreed on is <br><br><div><b>1</b>. rename “Bytes” to “Memory” in the raw pointer API. Note: this brings the `<span style="font-family:monospace,monospace">copyBytes<C>(from:)</span>` collection method into the scope of this proposal<br></div><div><br></div><b>2</b>. change raw offsets to be in terms of bytes, not typed strides. This argument will be called `<span style="font-family:monospace,monospace">atByteOffset:</span>` and will only appear in <span style="font-family:monospace,monospace">UnsafeMutableRawBufferPointer</span>. “<span style="font-family:monospace,monospace">at:</span>” arguments are no longer needed in <span style="font-family:monospace,monospace">UnsafeMutableRawPointer</span>, since we can just use pointer arithmetic now.<br><div><div><br><br></div><b>3</b>. move <span style="font-family:monospace,monospace">UnsafeMutableBufferPointer</span>’s `<span style="font-family:monospace,monospace">at:</span>` arguments to the front of the parameter list. mostly cause any pointer arithmetic happens in the front so structurally we want to mirror that.</div><div><br></div><div><b>4</b>. add dual (to:) single element initializers and assigners to <span style="font-family:monospace,monospace">UnsafeMutablePointer</span>, but not <span style="font-family:monospace,monospace">UnsafeMutableRawPointer</span> because it’s apparently not useful there. <span style="font-family:monospace,monospace">`UnsafeMutableRawPointer.initi<wbr>alizeMemory<T>(as:</span><span style="font-family:monospace,monospace">repeating:<wbr>count:)</span>` still loses its default count to prevent confusion with its buffer variant.<br></div><div><br></div><div><b>5</b>. memory deallocation on buffer pointers is clearly documented to only be defined behavior when the buffer matches a whole heap block. <br></div></div>
</div></blockquote></div><div><br></div></span>Kelvin,<div><br><div><div>Attempting to limit the scope of this proposal backfired. I was hoping to avoid discussing changes to the slice API, instead providing basic functionality within the buffer API itself. However, Dave Abrahams has argued that once the slice API is extended, the positional arguments are extraneous and less clear.</div><div><br></div><div>Instead of</div><div><br></div><div> buf.intialize(at: i, from: source)</div><div><br></div><div>We want to force a more obvious idiom:</div><div><br></div><div> buf[i..<n].intialize(from: source)</div><div><br></div><div>I think this is a reasonable argument and convinced myself that it's possible to extend the slice API. I'm also convinced now that we don't need overloads to handle an UnsafeBufferPointer source, instead we can provide a single generic entry point on both UnsafeMutableBufferPointer and its slice, optimized within the implementation:</div><div><br></div><div> `initialize<S : Sequence>(from: S) -> (S.Iterator, Index)</div><div><br></div><div>We can always drop down to the UnsafePointer API to get back to a direct unsafe implementation as a temporary workaround for performance issues.</div><div><br></div><div>Let's set aside for now whether we support full or partial initialization/assignment, how to handle moveInitialize, and whether we need to return the Iterator/Index. This is going to require another iteration on swift-evolution, which <b>we should discuss in a separate thread</b>. </div><div><br></div><div>At this point, I suggest removing the controversial aspects of SE-0184 so that we can put the other changes behind us and focus future discussion around a smaller follow-up proposal.</div><div><br></div><div>Here I've summarized the changes that I think could be accepted as-is:</div><div><a href="https://gist.github.com/atrick/c1ed7afb598e5cc943bdac7683914e3e" target="_blank">https://gist.github.com/atrick<wbr>/c1ed7afb598e5cc943bdac7683914<wbr>e3e</a></div><div><br></div><div>If you amend SE-0184 accordingly and file a new PR, I think it can be quickly approved.</div><div><br></div><div>-Andy</div></div><div><br></div></div></div></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Part one of SE-0184 is <a href="https://github.com/kelvin13/swift-evolution/blob/improved-pointers/proposals/0184a-unsafe-pointers-part-1.md">here as SE-0184 A</a> <br></div><div class="gmail_extra">I’ll implement it tomorrow and then make the PR<br></div></div>