<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 Aug 8, 2017, at 5:49 PM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" class="">kelvin13ma@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br 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=""><div 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; -webkit-text-stroke-width: 0px;">On Tue, Aug 8, 2017 at 7:53 PM, Andrew Trick<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:atrick@apple.com" target="_blank" class="">atrick@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><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 style="overflow-wrap: break-word;" class=""><span class="gmail-"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 8, 2017, at 9:52 AM, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class="gmail-m_-4271691199891306538Apple-interchange-newline"><div class=""><div dir="ltr" class="">Since Swift 5 just got opened up for proposals, SE-184 Improved Pointers is ready for community review, and I encourage everyone to look it over and provide feedback. Thank you!<br class=""><<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0184-improved-pointers.md" target="_blank" class="">https://github.com/apple/<wbr class="">swift-evolution/blob/master/<wbr class="">proposals/0184-improved-<wbr class="">pointers.md</a>><br class=""></div></div></blockquote></div><div class=""><br class=""></div></span><div class=""><div class="">Excellent. Thanks for patiently iterating on this. I know it's time consuming.</div></div></div></blockquote><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 style="overflow-wrap: break-word;" class=""><div class=""><div class=""><br class=""></div><div class="">> add a default value of 1 to all size parameters on</div><div class="">> UnsafeMutablePointer and applicable size parameters on</div><div class="">> UnsafeMutableRawPointer</div><div class=""><br class=""></div><div class="">I'm generally ok with this if you have seen the benefit of it in real</div><div class="">code. However, I do not think any `repeating:` methods should have a</div><div class="">default count.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Actually, i believe<span class="Apple-converted-space"> </span><span style="font-family: monospace, monospace;" class="">initialize(to:count:)</span><span class="Apple-converted-space"> </span>is currently the one method that already<span class="Apple-converted-space"> </span><i class="">has</i><span class="Apple-converted-space"> </span>a default count. That’s probably because the standard library calls this method with a count argument of 1 more than any other memorystate method. I don’t know if this decision was only made for the sake of the stdlib or if it had an API justification.<br class=""></div></div></div></blockquote><div><br class=""></div><div>Right you are. I had just noticed that none of the other `repeating` APIs had a default. But if this default argument simplifies real code patterns then I’m fine with it.</div><div><br class=""></div><blockquote type="cite" class=""><div 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; -webkit-text-stroke-width: 0px;"><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 style="overflow-wrap: break-word;" class=""><div class=""><div class="">> UnsafeMutableRawBufferPointer.<wbr class="">allocate(bytes:alignedTo:)</div><div class=""><br class=""></div><div class="">Well, I think it's somewhat ridiculous for users to write this every time they allocate a buffer:</div><div class=""><br class=""></div><div class="">`<wbr class="">UnsafeMutableRawBufferPointer.<wbr class="">allocate(bytes: size, alignedTo: MemoryLayout<UInt>.alignment)`</div><div class=""><br class=""></div><div class="">If anyone reading the code is unsure about the Swift API's alignment</div><div class="">guarantee, it's trivial to check the API docs.</div><div class=""><br class=""></div><div class="">You could introduce a clearly documented default `alignedTo`</div><div class="">argument. The reason I didn't do that is that the runtime won't</div><div class="">respect it anyway. But I think it would be fair to go ahead with the</div><div class="">API and file a bug against the runtime.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Default argument of<span class="Apple-converted-space"> </span><span style="font-family: monospace, monospace;" class="">MemoryLayout<Int>.alignment</span><span class="Apple-converted-space"> </span>is the way to go but as you said i don’t know if that is actually allowed/works. An alternative is to have two allocate methods each, one that takes an alignment argument and one that doesn’t (and aligns to pointer alignment) but that feels inelegant. Default arguments would be better.<br class=""></div></div></blockquote><div><br class=""></div><div>Default argument makes sense to me too. Then the raw buffer pointer and regular raw pointer APIs can be consistent with each other.</div><div><br class=""></div><div>Runtime bug: <a href="https://bugs.swift.org/browse/SR-5664" class="">https://bugs.swift.org/browse/SR-5664</a></div><br class=""><blockquote type="cite" class=""><div 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; -webkit-text-stroke-width: 0px;"><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 style="overflow-wrap: break-word;" class=""><div class=""><div class="">> and initializeMemory<Element>(as:<wbr class="">at:repeating:count:),</div><div class="">> initializeMemory<Element>(as:<wbr class="">from:count:)</div><div class="">> moveInitializeMemory<Element>(<wbr class="">as:from:count:), and</div><div class="">> bindMemory<Element>(to:count:) to UnsafeMutableRawBufferPointer</div><div class=""><br class=""></div><div class="">I think you should move the raw pointer changes to a separate bullet point.</div><div class=""><br class=""></div><div class="">Presumably the raw buffer capacity must match or exceed count * stride?</div><div class=""><br class=""></div><div class="">-Andy</div></div></div></blockquote><div class=""><br class=""></div><div class="">The reason the raw buffer pointers don’t fill in their own size is the destination type might not line up with the raw buffer size, and then there’s questions of rounding and whatnot.<span class="Apple-converted-space"> </span><span style="font-family: monospace, monospace;" class="">bindMemory(to:count:)</span><span class="Apple-converted-space"> </span>would also have to perform integer division or some other defined behavior. Though if people think computing the strided count inside the buffer pointer method is the right way to go, I’m open to that.</div></div></blockquote><br class=""></div><div>No, I think your API is fine. I just wanted to clarify that we will trap if the raw buffer is too small to fit the requested elements.</div><div><br class=""></div><div>-Andy</div><br class=""></body></html>