70 lines
20 KiB
HTML
70 lines
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 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,"tocview_0");">►</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 </td><td><a href="model.html" class="tocviewlink" data-pltdoc="x">Language Model</a></td></tr><tr><td align="right">2 </td><td><a href="notation.html" class="tocviewlink" data-pltdoc="x">Notation for Documentation</a></td></tr><tr><td align="right">3 </td><td><a href="syntax.html" class="tocviewlink" data-pltdoc="x">Syntactic Forms</a></td></tr><tr><td align="right">4 </td><td><a href="data.html" class="tocviewlink" data-pltdoc="x">Datatypes</a></td></tr><tr><td align="right">5 </td><td><a href="structures.html" class="tocviewlink" data-pltdoc="x">Structures</a></td></tr><tr><td align="right">6 </td><td><a href="mzlib_class.html" class="tocviewlink" data-pltdoc="x">Classes and Objects</a></td></tr><tr><td align="right">7 </td><td><a href="mzlib_unit.html" class="tocviewlink" data-pltdoc="x">Units</a></td></tr><tr><td align="right">8 </td><td><a href="contracts.html" class="tocviewlink" data-pltdoc="x">Contracts</a></td></tr><tr><td align="right">9 </td><td><a href="match.html" class="tocviewlink" data-pltdoc="x">Pattern Matching</a></td></tr><tr><td align="right">10 </td><td><a href="control.html" class="tocviewlink" data-pltdoc="x">Control Flow</a></td></tr><tr><td align="right">11 </td><td><a href="concurrency.html" class="tocviewlink" data-pltdoc="x">Concurrency and Parallelism</a></td></tr><tr><td align="right">12 </td><td><a href="Macros.html" class="tocviewlink" data-pltdoc="x">Macros</a></td></tr><tr><td align="right">13 </td><td><a href="input-and-output.html" class="tocviewlink" data-pltdoc="x">Input and Output</a></td></tr><tr><td align="right">14 </td><td><a href="security.html" class="tocviewlink" data-pltdoc="x">Reflection and Security</a></td></tr><tr><td align="right">15 </td><td><a href="os.html" class="tocviewlink" data-pltdoc="x">Operating System</a></td></tr><tr><td align="right">16 </td><td><a href="memory.html" class="tocviewlink" data-pltdoc="x">Memory Management</a></td></tr><tr><td align="right">17 </td><td><a href="unsafe.html" class="tocviewlink" data-pltdoc="x">Unsafe Operations</a></td></tr><tr><td align="right">18 </td><td><a href="run
|
||
|
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&rel=make.html&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 "scribblings/reference/reference.scrbl")" x-source-pkg="racket-doc" x-part-tag=""compiler-modes"">18.7.1<tt> </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 "scribblings/reference/reference.scrbl")" x-source-pkg="racket-doc" x-part-tag=""3m-compiler-modes"">18.7.1.1<tt> </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 "scribblings/reference/reference.scrbl")" x-source-pkg="racket-doc" x-part-tag=""cs-compiler-modes"">18.7.1.2<tt> </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. “Small enough” 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 "scribblings/reference/reference.scrbl")" x-source-pkg="racket-doc" x-part-tag=""compiler-inspect"">18.7.2<tt> </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’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 “schemified” 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> —<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> —<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> —<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> —<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> —<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> —<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> —<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> —<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> —<wbr></wbr> show a schemified
|
||
|
form after transformation by Chez Scheme’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> —<wbr></wbr> show the
|
||
|
intermediate form of a schemified linklet after the specified
|
||
|
passes (listed space-separated) in Chez Scheme’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> —<wbr></wbr> show the
|
||
|
compiled form of a schemified linklet in Chez Scheme’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, "8.6", "../");"/></form> <a href="https://docs.racket-lang.org/index.html" title="up to the documentation top" data-pltdoc="x" onclick="return GotoPLTRoot("8.6");">top</a><span class="tocsettoggle"> <a href="javascript:void(0);" title="show/hide table of contents" onclick="TocsetToggle();">contents</a></span></span><span class="navright"> <a href="debugging.html" title="backward to "18.6 Debugging"" data-pltdoc="x">← prev</a> <a href="running.html" title="up to "18 Running Racket"" data-pltdoc="x">up</a> <a href="Kernel_Forms_and_Functions.html" title="forward to "18.8 Kernel Forms and Functions"" data-pltdoc="x">next →</a></span> </div></div></div><div id="contextindicator"> </div></body></html>
|