1 <sect1 id="options-debugging">
2 <title>Debugging the compiler</title>
4 <indexterm><primary>debugging options (for GHC)</primary></indexterm>
6 <para>HACKER TERRITORY. HACKER TERRITORY. (You were warned.)</para>
8 <sect2 id="dumping-output">
9 <title>Dumping out compiler intermediate structures</title>
11 <indexterm><primary>dumping GHC intermediates</primary></indexterm>
12 <indexterm><primary>intermediate passes, output</primary></indexterm>
16 <term><option>-ddump-</option><replaceable>pass</replaceable></term>
17 <indexterm><primary><option>-ddump</option> options</primary></indexterm>
19 <para>Make a debugging dump after pass
20 <literal><pass></literal> (may be common enough to need
21 a short form…). You can get all of these at once
22 (<emphasis>lots</emphasis> of output) by using
23 <option>-v5</option>, or most of them with
24 <option>-v4</option>. Some of the most useful ones
29 <term><option>-ddump-parsed</option>:</term>
31 <para>parser output</para>
36 <term><option>-ddump-rn</option>:</term>
38 <para>renamer output</para>
43 <term><option>-ddump-tc</option>:</term>
45 <para>typechecker output</para>
50 <term><option>-ddump-types</option>:</term>
52 <para>Dump a type signature for each value defined at
53 the top level of the module. The list is sorted
54 alphabetically. Using <option>-dppr-debug</option>
55 dumps a type signature for all the imported and
56 system-defined things as well; useful for debugging the
62 <term><option>-ddump-deriv</option>:</term>
64 <para>derived instances</para>
69 <term><option>-ddump-ds</option>:</term>
71 <para>desugarer output</para>
76 <term><option>-ddump-spec</option>:</term>
78 <para>output of specialisation pass</para>
83 <term><option>-ddump-rules</option>:</term>
85 <para>dumps all rewrite rules (including those generated
86 by the specialisation pass)</para>
91 <term><option>-ddump-simpl</option>:</term>
93 <para>simplifer output (Core-to-Core passes)</para>
98 <term><option>-ddump-inlinings</option>:</term>
100 <para>inlining info from the simplifier</para>
105 <term><option>-ddump-usagesp</option>:</term>
107 <para>UsageSP inference pre-inf and output</para>
112 <term><option>-ddump-cpranal</option>:</term>
114 <para>CPR analyser output</para>
119 <term><option>-ddump-stranal</option>:</term>
121 <para>strictness analyser output</para>
126 <term><option>-ddump-cse</option>:</term>
128 <para>CSE pass output</para>
133 <term><option>-ddump-workwrap</option>:</term>
135 <para>worker/wrapper split output</para>
140 <term><option>-ddump-occur-anal</option>:</term>
142 <para>`occurrence analysis' output</para>
147 <term><option>-ddump-sat</option>:</term>
149 <para>output of “saturate” pass</para>
154 <term><option>-ddump-stg</option>:</term>
156 <para>output of STG-to-STG passes</para>
161 <term><option>-ddump-absC</option>:</term>
163 <para><emphasis>un</emphasis>flattened Abstract C</para>
168 <term><option>-ddump-flatC</option>:</term>
170 <para><emphasis>flattened</emphasis> Abstract C</para>
175 <term><option>-ddump-realC</option>:</term>
177 <para>same as what goes to the C compiler</para>
182 <term><option>-ddump-stix</option>:</term>
184 <para>native-code generator intermediate form</para>
189 <term><option>-ddump-asm</option>:</term>
191 <para>assembly language from the native-code generator</para>
196 <term><option>-ddump-bcos</option>:</term>
198 <para>byte code compiler output</para>
203 <term><option>-ddump-foreign</option>:</term>
205 <para>dump foreign export stubs</para>
211 <indexterm><primary><option>-ddump-absC</option></primary></indexterm>
212 <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
213 <indexterm><primary><option>-ddump-cpranal</option></primary></indexterm>
214 <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
216 <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
217 <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
218 <indexterm><primary><option>-ddump-flatC</option></primary></indexterm>
219 <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
220 <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
221 <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
222 <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
223 <indexterm><primary><option>-ddump-realC</option></primary></indexterm>
224 <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
225 <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
226 <indexterm><primary><option>-ddump-sat</option></primary></indexterm>
227 <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
228 <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
229 <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
230 <indexterm><primary><option>-ddump-stix</option></primary></indexterm>
231 <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
232 <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
234 <indexterm><primary><option>-ddump-usagesp</option></primary></indexterm>
235 <indexterm><primary><option>-ddump-workwrap</option></primary></indexterm>
240 <term><option>-dverbose-core2core</option></term>
241 <term><option>-dverbose-stg2stg</option></term>
242 <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
243 <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
245 <para>Show the output of the intermediate Core-to-Core and
246 STG-to-STG passes, respectively. (<emphasis>Lots</emphasis>
247 of output!) So: when we're really desperate:</para>
250 % ghc -noC -O -ddump-simpl -dverbose-simpl -dcore-lint Foo.hs
257 <term><option>-ddump-simpl-iterations</option>:</term>
258 <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
260 <para>Show the output of each <emphasis>iteration</emphasis>
261 of the simplifier (each run of the simplifier has a maximum
262 number of iterations, normally 4). Used when even
263 <option>-dverbose-simpl</option> doesn't cut it.</para>
268 <term><option>-dppr-debug</option></term>
269 <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
271 <para>Debugging output is in one of several
272 “styles.” Take the printing of types, for
273 example. In the “user” style (the default), the
274 compiler's internal ideas about types are presented in
275 Haskell source-level syntax, insofar as possible. In the
276 “debug” style (which is the default for
277 debugging output), the types are printed in with explicit
278 foralls, and variables have their unique-id attached (so you
279 can check for things that look the same but aren't). This
280 flag makes debugging output appear in the more verbose debug
286 <term><option>-dppr-user-length</option></term>
287 <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
289 <para>In error messages, expressions are printed to a
290 certain “depth”, with subexpressions beyond the
291 depth replaced by ellipses. This flag sets the
297 <term><option>-ddump-simpl-stats</option></term>
298 <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
300 <para>Dump statistics about how many of each kind of
301 transformation too place. If you add
302 <option>-dppr-debug</option> you get more detailed
308 <term><option>-ddump-rn-trace</option></term>
309 <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
311 <para>Make the renamer be *real* chatty about what it is
317 <term><option>-ddump-rn-stats</option></term>
318 <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
320 <para>Print out summary of what kind of information the renamer
321 had to bring in.</para>
326 <term><option>-dshow-unused-imports</option></term>
327 <indexterm><primary><option>-dshow-unused-imports</option></primary></indexterm>
329 <para>Have the renamer report what imports does not
336 <sect2 id="checking-consistency">
337 <title>Checking for consistency</title>
339 <indexterm><primary>consistency checks</primary></indexterm>
340 <indexterm><primary>lint</primary></indexterm>
345 <term><option>-dcore-lint</option></term>
346 <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
348 <para>Turn on heavyweight intra-pass sanity-checking within
349 GHC, at Core level. (It checks GHC's sanity, not yours.)</para>
354 <term><option>-dstg-lint</option>:</term>
355 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
357 <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
362 <term><option>-dusagesp-lint</option>:</term>
363 <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
365 <para>Turn on checks around UsageSP inference
366 (<option>-fusagesp</option>). This verifies various simple
367 properties of the results of the inference, and also warns
368 if any identifier with a used-once annotation before the
369 inference has a used-many annotation afterwards; this could
370 indicate a non-worksafe transformation is being
378 <title>How to read Core syntax (from some <option>-ddump</option>
381 <indexterm><primary>reading Core syntax</primary></indexterm>
382 <indexterm><primary>Core syntax, how to read</primary></indexterm>
384 <para>Let's do this by commenting an example. It's from doing
385 <option>-ddump-ds</option> on this code:
388 skip2 m = m : skip2 (m+2)
391 Before we jump in, a word about names of things. Within GHC,
392 variables, type constructors, etc., are identified by their
393 “Uniques.” These are of the form `letter' plus
394 `number' (both loosely interpreted). The `letter' gives some idea
395 of where the Unique came from; e.g., <literal>_</literal>
396 means “built-in type variable”; <literal>t</literal>
397 means “from the typechecker”; <literal>s</literal>
398 means “from the simplifier”; and so on. The `number'
399 is printed fairly compactly in a `base-62' format, which everyone
400 hates except me (WDP).</para>
402 <para>Remember, everything has a “Unique” and it is
403 usually printed out when debugging, in some form or another. So
404 here we go…</para>
408 Main.skip2{-r1L6-} :: _forall_ a$_4 =>{{Num a$_4}} -> a$_4 -> [a$_4]
410 --# `r1L6' is the Unique for Main.skip2;
411 --# `_4' is the Unique for the type-variable (template) `a'
412 --# `{{Num a$_4}}' is a dictionary argument
416 --# `_NI_' means "no (pragmatic) information" yet; it will later
417 --# evolve into the GHC_PRAGMA info that goes into interface files.
420 /\ _4 -> \ d.Num.t4Gt ->
423 +.t4Hg :: _4 -> _4 -> _4
425 +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt
427 fromInt.t4GS :: Int{-2i-} -> _4
429 fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt
431 --# The `+' class method (Unique: r3JH) selects the addition code
432 --# from a `Num' dictionary (now an explicit lamba'd argument).
433 --# Because Core is 2nd-order lambda-calculus, type applications
434 --# and lambdas (/\) are explicit. So `+' is first applied to a
435 --# type (`_4'), then to a dictionary, yielding the actual addition
436 --# function that we will use subsequently...
438 --# We play the exact same game with the (non-standard) class method
439 --# `fromInt'. Unsurprisingly, the type `Int' is wired into the
449 } in fromInt.t4GS ds.d4Qz
451 --# `I# 2#' is just the literal Int `2'; it reflects the fact that
452 --# GHC defines `data Int = I# Int#', where Int# is the primitive
453 --# unboxed type. (see relevant info about unboxed types elsewhere...)
455 --# The `!' after `I#' indicates that this is a *saturated*
456 --# application of the `I#' data constructor (i.e., not partially
459 skip2.t3Ja :: _4 -> [_4]
463 let { ds.d4QQ :: [_4]
469 ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
470 } in skip2.t3Ja ds.d4QY
478 <para>(“It's just a simple functional language” is an
479 unregisterised trademark of Peyton Jones Enterprises, plc.)</para>
484 <title>Unregisterised compilation</title>
485 <indexterm><primary>unregisterised compilation</primary></indexterm>
487 <para>The term "unregisterised" really means "compile via vanilla
488 C", disabling some of the platform-specific tricks that GHC
489 normally uses to make programs go faster. When compiling
490 unregisterised, GHC simply generates a C file which is compiled
493 <para>Unregisterised compilation can be useful when porting GHC to
494 a new machine, since it reduces the prerequisite tools to
495 <command>gcc</command>, <command>as</command>, and
496 <command>ld</command> and nothing more, and furthermore the amount
497 of platform-specific code that needs to be written in order to get
498 unregisterised compilation going is usually fairly small.</para>
502 <term><option>-unreg</option>:</term>
503 <indexterm><primary><option>-unreg</option></primary></indexterm>
505 <para>Compile via vanilla ANSI C only, turning off
506 platform-specific optimisations. NOTE: in order to use
507 <option>-unreg</option>, you need to have a set of libraries
508 (including the RTS) built for unregisterised compilation.
509 This amounts to building GHC with way "u" enabled.</para>
518 ;;; Local Variables: ***
520 ;;; sgml-parent-document: ("users_guide.sgml" "book" "chapter" "sect1") ***