emacs.d/clones/docs.racket-lang.org/reference/compiler.html
2022-08-24 19:36:32 +02:00

70 lines
No EOL
20 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"/><meta name="viewport" content="width=device-width, initial-scale=0.8"/><title>18.7&nbsp;Controlling and Inspecting Compilation</title><link rel="stylesheet" type="text/css" href="../scribble.css" title="default"/><link rel="stylesheet" type="text/css" href="extras.css" title="default"/><link rel="stylesheet" type="text/css" href="../racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-style.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../manual-racket.css" title="default"/><link rel="stylesheet" type="text/css" href="../doc-site.css" title="default"/><script type="text/javascript" src="../scribble-common.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../manual-racket.js"></script><script type="text/javascript" src="../doc-site.js"></script><script type="text/javascript" src="../local-redirect/local-redirect.js"></script><script type="text/javascript" src="../local-redirect/local-user-redirect.js"></script><!--[if IE 6]><style type="text/css">.SIEHidden { overflow: hidden; }</style><![endif]--></head><body id="doc-racket-lang-org"><div class="tocset"><div class="tocview"><div class="tocviewlist tocviewlisttopspace"><div class="tocviewtitle"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_0&quot;);">&#9658;</a></td><td></td><td><a href="index.html" class="tocviewlink" data-pltdoc="x">The Racket Reference</a></td></tr></table></div><div class="tocviewsublisttop" style="display: none;" id="tocview_0"><table cellspacing="0" cellpadding="0"><tr><td align="right">1&nbsp;</td><td><a href="model.html" class="tocviewlink" data-pltdoc="x">Language Model</a></td></tr><tr><td align="right">2&nbsp;</td><td><a href="notation.html" class="tocviewlink" data-pltdoc="x">Notation for Documentation</a></td></tr><tr><td align="right">3&nbsp;</td><td><a href="syntax.html" class="tocviewlink" data-pltdoc="x">Syntactic Forms</a></td></tr><tr><td align="right">4&nbsp;</td><td><a href="data.html" class="tocviewlink" data-pltdoc="x">Datatypes</a></td></tr><tr><td align="right">5&nbsp;</td><td><a href="structures.html" class="tocviewlink" data-pltdoc="x">Structures</a></td></tr><tr><td align="right">6&nbsp;</td><td><a href="mzlib_class.html" class="tocviewlink" data-pltdoc="x">Classes and Objects</a></td></tr><tr><td align="right">7&nbsp;</td><td><a href="mzlib_unit.html" class="tocviewlink" data-pltdoc="x">Units</a></td></tr><tr><td align="right">8&nbsp;</td><td><a href="contracts.html" class="tocviewlink" data-pltdoc="x">Contracts</a></td></tr><tr><td align="right">9&nbsp;</td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">Pattern Matching</a></td></tr><tr><td align="right">10&nbsp;</td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">Control Flow</a></td></tr><tr><td align="right">11&nbsp;</td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc="x">Concurrency and Parallelism</a></td></tr><tr><td align="right">12&nbsp;</td><td><a href="Macros.html" class="tocviewlink" data-pltdoc="x">Macros</a></td></tr><tr><td align="right">13&nbsp;</td><td><a href="input-and-output.html" class="tocviewlink" data-pltdoc="x">Input and Output</a></td></tr><tr><td align="right">14&nbsp;</td><td><a href="security.html" class="tocviewlink" data-pltdoc="x">Reflection and Security</a></td></tr><tr><td align="right">15&nbsp;</td><td><a href="os.html" class="tocviewlink" data-pltdoc="x">Operating System</a></td></tr><tr><td align="right">16&nbsp;</td><td><a href="memory.html" class="tocviewlink" data-pltdoc="x">Memory Management</a></td></tr><tr><td align="right">17&nbsp;</td><td><a href="unsafe.html" class="tocviewlink" data-pltdoc="x">Unsafe Operations</a></td></tr><tr><td align="right">18&nbsp;</td><td><a href="running.html" class="tocviewselflink" data-pltdoc="x">Running Racket</a></td></tr><tr><td align="right"></td><td><a href="doc-bibliography.html" class="tocviewlink" data-pltdoc="x">Bibliography</a></td></tr><tr><td align="right"></td><td><a href="doc-index.html" class="tocviewlink" data-pltdoc="x">Index</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_1&quot;);">&#9660;</a></td><td>18&nbsp;</td><td><a href="running.html" class="tocviewlink" data-pltdoc="x">Running Racket</a></td></tr></table><div class="tocviewsublist" style="display: block;" id="tocview_1"><table cellspacing="0" cellpadding="0"><tr><td align="right">18.1&nbsp;</td><td><a href="running-sa.html" class="tocviewlink" data-pltdoc="x">Running Racket or GRacket</a></td></tr><tr><td align="right">18.2&nbsp;</td><td><a href="collects.html" class="tocviewlink" data-pltdoc="x">Libraries and Collections</a></td></tr><tr><td align="right">18.3&nbsp;</td><td><a href="Interactive_Help.html" class="tocviewlink" data-pltdoc="x">Interactive Help</a></td></tr><tr><td align="right">18.4&nbsp;</td><td><a href="interaction-info.html" class="tocviewlink" data-pltdoc="x">Interaction Configuration</a></td></tr><tr><td align="right">18.5&nbsp;</td><td><a href="interactive.html" class="tocviewlink" data-pltdoc="x">Interactive Module Loading</a></td></tr><tr><td align="right">18.6&nbsp;</td><td><a href="debugging.html" class="tocviewlink" data-pltdoc="x">Debugging</a></td></tr><tr><td align="right">18.7&nbsp;</td><td><a href="compiler.html" class="tocviewselflink" data-pltdoc="x">Controlling and Inspecting Compilation</a></td></tr><tr><td align="right">18.8&nbsp;</td><td><a href="Kernel_Forms_and_Functions.html" class="tocviewlink" data-pltdoc="x">Kernel Forms and Functions</a></td></tr></table></div></div><div class="tocviewlist"><table cellspacing="0" cellpadding="0"><tr><td style="width: 1em;"><a href="javascript:void(0);" title="Expand/Collapse" class="tocviewtoggle" onclick="TocviewToggle(this,&quot;tocview_2&quot;);">&#9658;</a></td><td>18.7&nbsp;</td><td><a href="compiler.html" class="tocviewselflink" data-pltdoc="x">Controlling and Inspecting Compilation</a></td></tr></table><div class="tocviewsublistbottom" style="display: none;" id="tocview_2"><table cellspacing="0" cellpadding="0"><tr><td align="right">18.7.1&nbsp;</td><td><a href="compiler.html#%28part._compiler-modes%29" class="tocviewlink" data-pltdoc="x">Compilation Modes</a></td></tr><tr><td align="right">18.7.2&nbsp;</td><td><a href="compiler.html#%28part._compiler-inspect%29" class="tocviewlink" data-pltdoc="x">Inspecting Compiler Passes</a></td></tr></table></div></div></div><div class="tocsub"><div class="tocsubtitle">On this page:</div><table class="tocsublist" cellspacing="0"><tr><td><span class="tocsublinknumber">18.7.1<tt>&nbsp;</tt></span><a href="compiler.html#%28part._compiler-modes%29" class="tocsubseclink" data-pltdoc="x">Compilation Modes</a></td></tr><tr><td><span class="tocsublinknumber">18.7.1.1<tt>&nbsp;</tt></span><a href="compiler.html#%28part._3m-compiler-modes%29" class="tocsubseclink" data-pltdoc="x">BC Compilation Modes</a></td></tr><tr><td><span class="tocsublinknumber">18.7.1.2<tt>&nbsp;</tt></span><a href="compiler.html#%28part._cs-compiler-modes%29" class="tocsubseclink" data-pltdoc="x">CS Compilation Modes</a></td></tr><tr><td><span class="tocsublinknumber">18.7.2<tt>&nbsp;</tt></span><a href="compiler.html#%28part._compiler-inspect%29" class="tocsubseclink" data-pltdoc="x">Inspecting Compiler Passes</a></td></tr></table></div></div><div class="maincolumn"><div class="main"><div class="navsettop"><span class="navleft"><form class="searchform"><input class="searchbox" id="searchbox" type="text" tabindex="1" placeholder="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;8.6&quot;, &quot;../&quot;);"/></form>&nbsp;&nbsp;<a href="https://docs.racket-lang.org/index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;8.6&quot;);">top</a><span class="tocsettoggle">&nbsp;&nbsp;<a href="javascript:void(0);" title="show/hide table of contents" onclick="TocsetToggle();">contents</a></span></span><span class="navright">&nbsp;&nbsp;<a href="debugging.html" title="backward to &quot;18.6 Debugging&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="running.html" title="up to &quot;18 Running Racket&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="Kernel_Forms_and_Functions.html" title="forward to &quot;18.8 Kernel Forms and Functions&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div><h4 x-source-module="(lib &quot;scribblings/reference/reference.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;compiler&quot;">18.7<tt>&nbsp;</tt><a name="(part._compiler)"></a>Controlling and Inspecting Compilation</h4><p>Racket programs and expressions are compiled automatically and
on-the-fly. The <span class="stt">raco make</span> tool (see <a href="https://download.racket-lang.org/releases/8.6/doc/local-redirect/index.html?doc=raco&amp;rel=make.html&amp;version=8.6" class="Sq" data-pltdoc="x"><span class="stt">raco make</span>: Compiling Source to Bytecode</a>) can compile a Racket module to a compiled <span class="stt">".zo"</span>
file, but that kind of ahead-to-time compilation simply allows a
program takes to start more quickly, and it does not affect the
performance of a Racket program.</p><h5 x-source-module="(lib &quot;scribblings/reference/reference.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;compiler-modes&quot;">18.7.1<tt>&nbsp;</tt><a name="(part._compiler-modes)"></a>Compilation Modes</h5><p>All Racket variants suppose a machine-independent compilation mode,
which generates compiled <span class="stt">".zo"</span> files that work with all
Racket variants on all platforms. To select machine-independent
compilation mode, set the <span class="RktSym"><a href="eval.html#%28def._%28%28quote._~23~25kernel%29._current-compile-target-machine%29%29" class="RktValLink" data-pltdoc="x">current-compile-target-machine</a></span>
parameter to <span class="RktVal">#f</span> or supplying the <span class="nobreak"><span class="stt">--compile-any</span></span>/<span class="nobreak"><span class="stt">-M</span></span>
flag on startup. See <span class="RktSym"><a href="eval.html#%28def._%28%28quote._~23~25kernel%29._current-compile-target-machine%29%29" class="RktValLink" data-pltdoc="x">current-compile-target-machine</a></span> for more
information.</p><p>Other compilation modes depend on the Racket implementation (see
<a href="implementations.html" data-pltdoc="x">Implementations</a>).</p><h5 x-source-module="(lib &quot;scribblings/reference/reference.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;3m-compiler-modes&quot;">18.7.1.1<tt>&nbsp;</tt><a name="(part._3m-compiler-modes)"></a>BC Compilation Modes</h5><p>The <a href="implementations.html#%28tech._bc%29" class="techoutside" data-pltdoc="x"><span class="techinside">BC</span></a> implementation of Racket supports two
compilation modes: bytecode and machine-independent. The bytecode
format is also machine-independent in the sense that it works the same
on all operating systems for the BC implementation
of Racket, but it does not work with the CS implementation of Racket.</p><p>Bytecode is further compiled to machine code at run time, unless the
JIT compiler is disabled. See <span class="RktSym"><a href="eval.html#%28def._%28%28quote._~23~25kernel%29._eval-jit-enabled%29%29" class="RktValLink" data-pltdoc="x">eval-jit-enabled</a></span>.</p><h5 x-source-module="(lib &quot;scribblings/reference/reference.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;cs-compiler-modes&quot;">18.7.1.2<tt>&nbsp;</tt><a name="(part._cs-compiler-modes)"></a>CS Compilation Modes</h5><p>The <a href="implementations.html#%28tech._c%29" class="techoutside" data-pltdoc="x"><span class="techinside">CS</span></a> implementation of Racket supports several compilation modes:
machine code, machine-independent, interpreted, and JIT. Machine code
is the primary mode, and the machine-independent mode is the same as
for BC. Interpreted mode uses an interpreter at
the level of core <a href="linklets.html#%28tech._linklet%29" class="techoutside" data-pltdoc="x"><span class="techinside">linklet</span></a> forms with no compilation. JIT mode
triggers compilation of individual function forms on demand.</p><p>The default mode is a hybrid of machine-code and interpreter modes,
where interpreter mode is used only for the outer contour of an
especially large linklet, and machine-code mode is used for functions
that are small enough within that outer contour. &ldquo;Small enough&rdquo; is
determined by the <a name="(idx._(gentag._564._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_CS_COMPILE_LIMIT</span> environment
variable, and the default value of 10000 means that most Racket
modules have no interpreted component.</p><p>JIT compilation mode is used only if the <a name="(idx._(gentag._565._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_CS_JIT</span>
environment variable is set on startup, otherwise pure interpreter
mode is used only if <a name="(idx._(gentag._566._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_CS_INTERP</span> is set on startup,
and the default hybrid machine code and interpreter mode is used if
<a name="(idx._(gentag._567._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_CS_MACH</span> is set and <span class="stt">PLT_CS_JIT</span> is not set
or if none of those environment variables is set. A module compiled in
any mode can be loaded into the CS variant of Racket independent of
the current compilation mode.</p><p>The <span class="stt">PLT_CS_DEBUG</span> environment variable, as described in
<a href="debugging.html" data-pltdoc="x">Debugging</a>, affects only compilation in machine-code mode.
Generated machine code is much larger when <span class="stt">PLT_CS_DEBUG</span> is
enabled, but performance is not otherwise affected.</p><h5 x-source-module="(lib &quot;scribblings/reference/reference.scrbl&quot;)" x-source-pkg="racket-doc" x-part-tag="&quot;compiler-inspect&quot;">18.7.2<tt>&nbsp;</tt><a name="(part._compiler-inspect)"></a>Inspecting Compiler Passes</h5><p>When the <a name="(idx._(gentag._568._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW</span> environment variable is set
on startup, the Racket process&rsquo;s standard output shows intermediate
compiled forms whenever a Racket form is compiled. For all Racket
variants, the output shows one or more <a href="linklets.html#%28tech._linklet%29" class="techoutside" data-pltdoc="x"><span class="techinside">linklets</span></a> that are
generated from the original Racket form.</p><p>For the <a href="implementations.html#%28tech._c%29" class="techoutside" data-pltdoc="x"><span class="techinside">CS</span></a> implementation of Racket, a &ldquo;schemified&rdquo; version of the linklet
is also shown as the translation of the <span class="RktSym">linklet</span> form to a
Chez Scheme procedure form. The following environment variables imply
<span class="stt">PLT_LINKLET_SHOW</span> and show additional intermediate compiled
forms or adjust the way forms are displayed:</p><ul><li><p><a name="(idx._(gentag._569._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_GENSYM</span> &#8212;<wbr></wbr> prints full
generated names, instead of abbreviations that may conflate
different symbols</p></li><li><p><a name="(idx._(gentag._570._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_PRE_JIT</span> &#8212;<wbr></wbr> shows a
schemified forms before a transformation to JIT mode, which
applies only when <span class="stt">PLT_CS_JIT</span> is set</p></li><li><p><a name="(idx._(gentag._571._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_LAMBDA</span> &#8212;<wbr></wbr> shows individual
schemified forms that are compiled within a larger form that
has an interpreted outer contour</p></li><li><p><a name="(idx._(gentag._572._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_POST_LAMBDA</span> &#8212;<wbr></wbr> shows an
outer form after inner individual forms are compiled</p></li><li><p><a name="(idx._(gentag._573._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_POST_INTERP</span> &#8212;<wbr></wbr> shows an
outer form after its transformation to interpretable form</p></li><li><p><a name="(idx._(gentag._574._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_JIT_DEMAND</span> &#8212;<wbr></wbr> shows JIT
compilation of form that were previously prepared by
compilation with <span class="stt">PLT_CS_JIT</span> set</p></li><li><p><a name="(idx._(gentag._575._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_PATHS</span> &#8212;<wbr></wbr> show lifted
path and serialization information alongside a schemified form</p></li><li><p><a name="(idx._(gentag._576._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_KNOWN</span> &#8212;<wbr></wbr> show recorded
known-binding information alongside a schemified form</p></li><li><p><a name="(idx._(gentag._577._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_CP0</span> &#8212;<wbr></wbr> show a schemified
form after transformation by Chez Scheme&rsquo;s front-end
optimizer</p></li><li><p><a name="(idx._(gentag._578._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_PASSES</span> &#8212;<wbr></wbr> show the
intermediate form of a schemified linklet after the specified
passes (listed space-separated) in Chez Scheme&rsquo;s internal
representation</p></li><li><p><a name="(idx._(gentag._579._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_SHOW_ASSEMBLY</span> &#8212;<wbr></wbr> show the
compiled form of a schemified linklet in Chez Scheme&rsquo;s
abstraction of machine instructions</p></li></ul><p>When the <a name="(idx._(gentag._580._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_LINKLET_TIMES</span> environment variable is
set on startup, then Racket prints cumulative timing information about
compilation and evaluation times on exit. When the
<a name="(idx._(gentag._581._(lib._scribblings/reference/reference..scrbl)))"></a><span class="stt">PLT_EXPANDER_TIMES</span> environment variable is set,
information about macro-expansion time is printed on exit.</p><div class="navsetbottom"><span class="navleft"><form class="searchform"><input class="searchbox" id="searchbox" type="text" tabindex="1" placeholder="...search manuals..." title="Enter a search string to search the manuals" onkeypress="return DoSearchKey(event, this, &quot;8.6&quot;, &quot;../&quot;);"/></form>&nbsp;&nbsp;<a href="https://docs.racket-lang.org/index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot(&quot;8.6&quot;);">top</a><span class="tocsettoggle">&nbsp;&nbsp;<a href="javascript:void(0);" title="show/hide table of contents" onclick="TocsetToggle();">contents</a></span></span><span class="navright">&nbsp;&nbsp;<a href="debugging.html" title="backward to &quot;18.6 Debugging&quot;" data-pltdoc="x">&larr; prev</a>&nbsp;&nbsp;<a href="running.html" title="up to &quot;18 Running Racket&quot;" data-pltdoc="x">up</a>&nbsp;&nbsp;<a href="Kernel_Forms_and_Functions.html" title="forward to &quot;18.8 Kernel Forms and Functions&quot;" data-pltdoc="x">next &rarr;</a></span>&nbsp;</div></div></div><div id="contextindicator">&nbsp;</div></body></html>