import{_ as i,c as a,o as s,ae as t}from"./chunks/framework.l7bN90nj.js";const m=JSON.parse('{"title":"Compilation","description":"","frontmatter":{},"headers":[],"relativePath":"design/compilation.md","filePath":"en/design/compilation.md"}'),n={name:"design/compilation.md"};function l(o,e,r,p,c,h){return s(),a("div",null,[...e[0]||(e[0]=[t(`<h1 id="compilation" tabindex="-1">Compilation <a class="header-anchor" href="#compilation" aria-label="Permalink to &quot;Compilation&quot;">​</a></h1><h2 id="incremental-parsing" tabindex="-1">Incremental Parsing <a class="header-anchor" href="#incremental-parsing" aria-label="Permalink to &quot;Incremental Parsing&quot;">​</a></h2><p>Every time you modify code, clice must re-parse the file. clice uses a mechanism called preamble to implement incremental compilation to speed up re-parsing. Preamble can be considered a special case of <a href="https://clang.llvm.org/docs/PCHInternals.html" target="_blank" rel="noreferrer">Precompiled Header</a> (embedded in source files). When opening a file, it builds the first few preprocessor directives at the beginning of the file (called preamble) into a PCH cache on disk. Later, when parsing, it can directly load the PCH file, thus skipping the first few preprocessor directives, which can greatly reduce the amount of code that needs to be re-parsed.</p><p>For example, for the following code:</p><div class="language-cpp vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">cpp</span><pre class="shiki shiki-themes github-light github-dark vp-code" tabindex="0"><code><span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#include</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &lt;iostream&gt;</span></span>
<span class="line"></span>
<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> main</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> () {</span></span>
<span class="line"><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;">    std</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">::cout </span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">&lt;&lt;</span><span style="--shiki-light:#032F62;--shiki-dark:#9ECBFF;"> &quot;Hello world!&quot;</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;"> &lt;&lt;</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> std</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">::endl;</span></span>
<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">}</span></span></code></pre></div><p>The <code>iostream</code> header file has about 20,000 lines of code. clice will first build the line <code>#include &lt;iostream&gt;</code> into a PCH file, and after completion, use this PCH file to parse the subsequent code. This way, the amount of code that needs to be re-parsed later is reduced to just 5 lines instead of the original 20,000 lines, making it very fast. Unless you modify the code in the preamble section, which requires building a new preamble.</p><h2 id="cancel-compilation" tabindex="-1">Cancel Compilation <a class="header-anchor" href="#cancel-compilation" aria-label="Permalink to &quot;Cancel Compilation&quot;">​</a></h2>`,7)])])}const k=i(n,[["render",l]]);export{m as __pageData,k as default};
