<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Compiler on Shai Asher</title><link>https://slow-is-smooth.io/tags/compiler/</link><description>Recent content in Compiler on Shai Asher</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 24 Jun 2018 09:00:00 +0300</lastBuildDate><atom:link href="https://slow-is-smooth.io/tags/compiler/index.xml" rel="self" type="application/rss+xml"/><item><title>The Compiler Decides What Escapes</title><link>https://slow-is-smooth.io/blog/the-compiler-decides-what-escapes/</link><pubDate>Sun, 24 Jun 2018 09:00:00 +0300</pubDate><guid>https://slow-is-smooth.io/blog/the-compiler-decides-what-escapes/</guid><description>&lt;p&gt;Add one &lt;code&gt;fmt.Println&lt;/code&gt; to a Go function that never allocated, and every call to it now allocates.&#10;Nothing in the source says where a variable lives. Go has no &lt;code&gt;new&lt;/code&gt; that means &amp;ldquo;heap&amp;rdquo; and no&#10;declaration that means &amp;ldquo;stack&amp;rdquo;. The compiler decides, one variable at a time, by working out&#10;whether anything could still refer to the variable after its function returns. If something could,&#10;the variable &lt;em&gt;escapes&lt;/em&gt; and goes on the heap. If nothing could, it stays in the stack frame and costs&#10;nothing to free. The debugging line made a variable escape, and the compiler moved it without&#10;saying a word.&lt;/p&gt;</description></item></channel></rss>