1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <sect1 id="options-debugging">
3 <title>Debugging the compiler</title>
5 <indexterm><primary>debugging options (for GHC)</primary></indexterm>
7 <para>HACKER TERRITORY. HACKER TERRITORY. (You were warned.)</para>
9 <sect2 id="dumping-output">
10 <title>Dumping out compiler intermediate structures</title>
12 <indexterm><primary>dumping GHC intermediates</primary></indexterm>
13 <indexterm><primary>intermediate passes, output</primary></indexterm>
17 <term><option>-ddump-</option><replaceable>pass</replaceable></term>
18 <indexterm><primary><option>-ddump</option> options</primary></indexterm>
20 <para>Make a debugging dump after pass
21 <literal><pass></literal> (may be common enough to need
22 a short form…). You can get all of these at once
23 (<emphasis>lots</emphasis> of output) by using
24 <option>-v5</option>, or most of them with
25 <option>-v4</option>. Some of the most useful ones
30 <term><option>-ddump-parsed</option>:</term>
32 <para>parser output</para>
37 <term><option>-ddump-rn</option>:</term>
39 <para>renamer output</para>
44 <term><option>-ddump-tc</option>:</term>
46 <para>typechecker output</para>
51 <term><option>-ddump-types</option>:</term>
53 <para>Dump a type signature for each value defined at
54 the top level of the module. The list is sorted
55 alphabetically. Using <option>-dppr-debug</option>
56 dumps a type signature for all the imported and
57 system-defined things as well; useful for debugging the
63 <term><option>-ddump-deriv</option>:</term>
65 <para>derived instances</para>
70 <term><option>-ddump-ds</option>:</term>
72 <para>desugarer output</para>
77 <term><option>-ddump-spec</option>:</term>
79 <para>output of specialisation pass</para>
84 <term><option>-ddump-rules</option>:</term>
86 <para>dumps all rewrite rules (including those generated
87 by the specialisation pass)</para>
92 <term><option>-ddump-simpl</option>:</term>
94 <para>simplifer output (Core-to-Core passes)</para>
99 <term><option>-ddump-inlinings</option>:</term>
101 <para>inlining info from the simplifier</para>
106 <term><option>-ddump-usagesp</option>:</term>
108 <para>UsageSP inference pre-inf and output</para>
113 <term><option>-ddump-cpranal</option>:</term>
115 <para>CPR analyser output</para>
120 <term><option>-ddump-stranal</option>:</term>
122 <para>strictness analyser output</para>
127 <term><option>-ddump-cse</option>:</term>
129 <para>CSE pass output</para>
134 <term><option>-ddump-workwrap</option>:</term>
136 <para>worker/wrapper split output</para>
141 <term><option>-ddump-occur-anal</option>:</term>
143 <para>`occurrence analysis' output</para>
148 <term><option>-ddump-sat</option>:</term>
150 <para>output of “saturate” pass</para>
155 <term><option>-ddump-stg</option>:</term>
157 <para>output of STG-to-STG passes</para>
162 <term><option>-ddump-absC</option>:</term>
164 <para><emphasis>un</emphasis>flattened Abstract C</para>
169 <term><option>-ddump-flatC</option>:</term>
171 <para><emphasis>flattened</emphasis> Abstract C</para>
176 <term><option>-ddump-realC</option>:</term>
178 <para>same as what goes to the C compiler</para>
183 <term><option>-ddump-stix</option>:</term>
185 <para>native-code generator intermediate form</para>
190 <term><option>-ddump-asm</option>:</term>
192 <para>assembly language from the native-code generator</para>
197 <term><option>-ddump-bcos</option>:</term>
199 <para>byte code compiler output</para>
204 <term><option>-ddump-foreign</option>:</term>
206 <para>dump foreign export stubs</para>
212 <indexterm><primary><option>-ddump-absC</option></primary></indexterm>
213 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
214 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
215 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
217 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
218 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
219 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
220 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
221 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
222 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
223 <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
224 <indexterm><primary><option>-ddump-realC</option></primary></indexterm>
225 <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
226 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
227 <indexterm><primary><option>-ddump-sat</option></primary></indexterm>
228 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
229 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
230 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
231 <indexterm><primary><option>-ddump-stix</option></primary></indexterm>
232 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
233 <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
235 <indexterm><primary><option>-ddump-usagesp</option></primary></indexterm>
236 <indexterm><primary><option>-ddump-workwrap</option></primary></indexterm>
241 <term><option>-dverbose-core2core</option></term>
242 <term><option>-dverbose-stg2stg</option></term>
243 <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
244 <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
246 <para>Show the output of the intermediate Core-to-Core and
247 STG-to-STG passes, respectively. (<emphasis>Lots</emphasis>
248 of output!) So: when we're really desperate:</para>
251 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
258 <term><option>-ddump-simpl-iterations</option>:</term>
259 <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
261 <para>Show the output of each <emphasis>iteration</emphasis>
262 of the simplifier (each run of the simplifier has a maximum
263 number of iterations, normally 4). Used when even
264 <option>-dverbose-simpl</option> doesn't cut it.</para>
269 <term><option>-dppr-debug</option></term>
270 <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
272 <para>Debugging output is in one of several
273 “styles.” Take the printing of types, for
274 example. In the “user” style (the default), the
275 compiler's internal ideas about types are presented in
276 Haskell source-level syntax, insofar as possible. In the
277 “debug” style (which is the default for
278 debugging output), the types are printed in with explicit
279 foralls, and variables have their unique-id attached (so you
280 can check for things that look the same but aren't). This
281 flag makes debugging output appear in the more verbose debug
287 <term><option>-dppr-user-length</option></term>
288 <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
290 <para>In error messages, expressions are printed to a
291 certain “depth”, with subexpressions beyond the
292 depth replaced by ellipses. This flag sets the
298 <term><option>-ddump-simpl-stats</option></term>
299 <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
301 <para>Dump statistics about how many of each kind of
302 transformation too place. If you add
303 <option>-dppr-debug</option> you get more detailed
309 <term><option>-ddump-rn-trace</option></term>
310 <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
312 <para>Make the renamer be *real* chatty about what it is
318 <term><option>-ddump-rn-stats</option></term>
319 <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
321 <para>Print out summary of what kind of information the renamer
322 had to bring in.</para>
327 <term><option>-dshow-unused-imports</option></term>
328 <indexterm><primary><option>-dshow-unused-imports</option></primary></indexterm>
330 <para>Have the renamer report what imports does not
337 <sect2 id="checking-consistency">
338 <title>Checking for consistency</title>
340 <indexterm><primary>consistency checks</primary></indexterm>
341 <indexterm><primary>lint</primary></indexterm>
346 <term><option>-dcore-lint</option></term>
347 <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
349 <para>Turn on heavyweight intra-pass sanity-checking within
350 GHC, at Core level. (It checks GHC's sanity, not yours.)</para>
355 <term><option>-dstg-lint</option>:</term>
356 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
358 <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
363 <term><option>-dusagesp-lint</option>:</term>
364 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
366 <para>Turn on checks around UsageSP inference
367 (<option>-fusagesp</option>). This verifies various simple
368 properties of the results of the inference, and also warns
369 if any identifier with a used-once annotation before the
370 inference has a used-many annotation afterwards; this could
371 indicate a non-worksafe transformation is being
379 <title>How to read Core syntax (from some <option>-ddump</option>
382 <indexterm><primary>reading Core syntax</primary></indexterm>
383 <indexterm><primary>Core syntax, how to read</primary></indexterm>
385 <para>Let's do this by commenting an example. It's from doing
386 <option>-ddump-ds</option> on this code:
389 skip2 m = m : skip2 (m+2)
392 Before we jump in, a word about names of things. Within GHC,
393 variables, type constructors, etc., are identified by their
394 “Uniques.” These are of the form `letter' plus
395 `number' (both loosely interpreted). The `letter' gives some idea
396 of where the Unique came from; e.g., <literal>_</literal>
397 means “built-in type variable”; <literal>t</literal>
398 means “from the typechecker”; <literal>s</literal>
399 means “from the simplifier”; and so on. The `number'
400 is printed fairly compactly in a `base-62' format, which everyone
401 hates except me (WDP).</para>
403 <para>Remember, everything has a “Unique” and it is
404 usually printed out when debugging, in some form or another. So
405 here we go…</para>
409 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
411 --# `r1L6' is the Unique for Main.skip2;
412 --# `_4' is the Unique for the type-variable (template) `a'
413 --# `{{Num a$_4}}' is a dictionary argument
417 --# `_NI_' means "no (pragmatic) information" yet; it will later
418 --# evolve into the GHC_PRAGMA info that goes into interface files.
421 /\ _4 -> \ d.Num.t4Gt ->
424 +.t4Hg :: _4 -> _4 -> _4
426 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
428 fromInt.t4GS :: Int{-2i-} -> _4
430 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
432 --# The `+' class method (Unique: r3JH) selects the addition code
433 --# from a `Num' dictionary (now an explicit lamba'd argument).
434 --# Because Core is 2nd-order lambda-calculus, type applications
435 --# and lambdas (/\) are explicit. So `+' is first applied to a
436 --# type (`_4'), then to a dictionary, yielding the actual addition
437 --# function that we will use subsequently...
439 --# We play the exact same game with the (non-standard) class method
440 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
450 } in fromInt.t4GS ds.d4Qz
452 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
453 --# GHC defines `data Int = I# Int#', where Int# is the primitive
454 --# unboxed type. (see relevant info about unboxed types elsewhere...)
456 --# The `!' after `I#' indicates that this is a *saturated*
457 --# application of the `I#' data constructor (i.e., not partially
460 skip2.t3Ja :: _4 -> [_4]
464 let { ds.d4QQ :: [_4]
470 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
471 } in skip2.t3Ja ds.d4QY
479 <para>(“It's just a simple functional language” is an
480 unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
485 <title>Unregisterised compilation</title>
486 <indexterm><primary>unregisterised compilation</primary></indexterm>
488 <para>The term "unregisterised" really means "compile via vanilla
489 C", disabling some of the platform-specific tricks that GHC
490 normally uses to make programs go faster. When compiling
491 unregisterised, GHC simply generates a C file which is compiled
494 <para>Unregisterised compilation can be useful when porting GHC to
495 a new machine, since it reduces the prerequisite tools to
496 <command>gcc</command>, <command>as</command>, and
497 <command>ld</command> and nothing more, and furthermore the amount
498 of platform-specific code that needs to be written in order to get
499 unregisterised compilation going is usually fairly small.</para>
503 <term><option>-unreg</option>:</term>
504 <indexterm><primary><option>-unreg</option></primary></indexterm>
506 <para>Compile via vanilla ANSI C only, turning off
507 platform-specific optimisations. NOTE: in order to use
508 <option>-unreg</option>, you need to have a set of libraries
509 (including the RTS) built for unregisterised compilation.
510 This amounts to building GHC with way "u" enabled.</para>
519 ;;; Local Variables: ***
521 ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***