<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word"><div dir="auto" style="word-wrap:break-word"><div><div><div>My migration guide landed on <a href="http://swift.org" target="_blank">swift.org</a> today! I think it will be a big help.</div><div><a href="https://swift.org/migration-guide/se-0107-migrate.html" target="_blank">https://swift.org/migration-<wbr>guide/se-0107-migrate.html</a></div><div><br></div><div>-Andy</div></div></div></div></div></blockquote><div><br></div><div>Thanks Andy, this is great!</div><div><br></div><div>I hope that over time, even more accessible material is added for newcomers. I still feel I would have a hard time answering the question of what bindMemory &quot;does&quot;, if someone asked me. My impression is that all these methods are really just hints to the compiler about which kinds of transformations/optimizations are allowed and which are not — making it aware of aliasing.</div><div><br></div><div>The example below (from your proposal) is a good, practical showcase of what might go wrong with aliasing. But what <b>should</b> this look like when using the new API / how do the changes help prevent these problems? The example shows only the &quot;old version&quot;.</div><div><br></div><div><pre style="box-sizing:border-box;font-family:consolas,&quot;liberation mono&quot;,menlo,courier,monospace;font-size:13.6px;margin-top:0px;margin-bottom:0px;font-stretch:normal;line-height:1.45;word-wrap:normal;padding:16px;overflow:auto;background-color:rgb(247,247,247);border-radius:3px;word-break:normal;color:rgb(51,51,51)"><span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// --- old version ---</span>
<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">testUndefinedExecution</span>() {
  <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">let</span> pA <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeMutablePointer</span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span>A<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;.</span>allocate(capacity: <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">1</span>)
  pA[<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>] <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> A(value:<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">42</span>)
  <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">if</span> pA[<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>]<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">.</span><span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">value</span> <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">!=</span> <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">42</span> {
    <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// Code path should never execute...</span>
    releaseDemons()
  }
  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// This compiler may inline this, and hoist the store above the</span>
  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// previous check.</span>
  unforeseenCode(pA)
}

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">releaseDemons</span>() {
  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// Something that should never be executed...</span>
}

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">assignB</span>(<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="gmail-pl-smi" style="box-sizing:border-box">pB</span>: <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeMutablePointer</span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span>B<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span>) {
  pB[<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">0</span>] <span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">=</span> B(value:<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">13</span>)
}

<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">func</span> <span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">unforeseenCode</span>(<span class="gmail-pl-en" style="box-sizing:border-box;color:rgb(121,93,163)">_</span> <span class="gmail-pl-smi" style="box-sizing:border-box">pA</span>: <span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeMutablePointer</span><span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&lt;</span>A<span class="gmail-pl-k" style="box-sizing:border-box;color:rgb(167,29,93)">&gt;</span>) {
  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// At some arbitrary point in the future, the same memory is</span>
  <span class="gmail-pl-c" style="box-sizing:border-box;color:rgb(150,152,150)">// innocuously assigned to B.</span>
  assignB(<span class="gmail-pl-c1" style="box-sizing:border-box;color:rgb(0,134,179)">UnsafeMutablePointer</span>(pA))
}</pre></div><div><br></div></div><br></div></div>