<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 8:29 PM, Taylor Swift &lt;<a href="mailto:kelvin13ma@gmail.com" class="">kelvin13ma@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="gmail_extra" 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;"><br class="Apple-interchange-newline"><br class=""><div class="gmail_quote">On Tue, Aug 8, 2017 at 11:24 PM, Andrew Trick<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:atrick@apple.com" target="_blank" class="">atrick@apple.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</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="word-wrap: break-word;" class=""><div class=""><div class="h5"><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Aug 8, 2017, at 6:51 PM, Taylor Swift &lt;<a href="mailto:kelvin13ma@gmail.com" target="_blank" class="">kelvin13ma@gmail.com</a>&gt; wrote:</div><br class="m_-67376284151341790Apple-interchange-newline"><div class=""><div dir="ltr" class=""><br class=""><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Aug 8, 2017 at 9:38 PM, Andrew Trick<span class="Apple-converted-space">&nbsp;</span><span dir="ltr" class="">&lt;<a href="mailto:atrick@apple.com" target="_blank" class="">atrick@apple.com</a>&gt;</span><span class="Apple-converted-space">&nbsp;</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="word-wrap: break-word;" class=""><div class=""><span class=""><div class=""><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;"><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 class=""><div class=""><div class="">&gt; 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="">`UnsafeMutableRawBufferPointer<wbr class="">.allocate(bytes: size, alignedTo: MemoryLayout&lt;UInt&gt;.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="m_-67376284151341790m_7821494737473580892Apple-converted-space">&nbsp;</span><span style="font-family: monospace, monospace;" class="">MemoryLayout&lt;Int&gt;.alignment</span><span class="m_-67376284151341790m_7821494737473580892Apple-converted-space"><wbr class="">&nbsp;</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 class=""><br class=""></div></span><div class="">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 class=""><br class=""></div><div class="">Runtime bug:<span class="Apple-converted-space">&nbsp;</span><a href="https://bugs.swift.org/browse/SR-5664" target="_blank" class="">https://bugs.swift.org/browse/<wbr class="">SR-5664</a></div><span class=""></span><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">yikes i was not aware of this. I don’t think it’s bad enough to warrant dropping the argument like with<span class="Apple-converted-space">&nbsp;</span><span style="font-family: monospace, monospace;" class="">deallocate(capacity:)</span><span class="Apple-converted-space">&nbsp;</span>but I can imagine bad things happening to code that crams extra inhabitants into pointers.<br class=""></div></div></div></div></div></blockquote></div><br class=""></div></div><div class="">If we ever need to do pointer adjustment during deallocation to accommodate alignment, then I think the Swift runtime can track that. I see no reason to muddy the UnsafeRawPointer API with it. So, I agree with your proposed change to drop `alignedTo` there.</div><div class=""><br class=""></div><div class="">-Andy</div></div></blockquote></div><br class=""></div><div class="gmail_extra" 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;">oh lol I was talking about assuming the pointer returned by<span class="Apple-converted-space">&nbsp;</span><span style="font-family: monospace, monospace;" class="">allocate(bytes:alignedTo:)</span><span class="Apple-converted-space">&nbsp;</span>is a multiple of<span class="Apple-converted-space">&nbsp;</span><span style="font-family: monospace, monospace;" class="">alignedTo</span>. Some code might be relying on the last few bits of the pointer being zero; i.e. sticking bit flags there like how some implementations store the red/black color information in a red-black tree node.</div></div></blockquote><br class=""></div><div>Oh, sure. But I think it will be easy to fix the runtime. We could probably do it before the proposal is accepted if necessary.</div><div>-Andy</div><br class=""></body></html>