debugging.xml 24.2 KB
Newer Older
1
<?xml version="1.0" encoding="iso-8859-1"?>
2 3 4 5 6 7 8
<sect1 id="options-debugging">
  <title>Debugging the compiler</title>

  <indexterm><primary>debugging options (for GHC)</primary></indexterm>

  <para>HACKER TERRITORY. HACKER TERRITORY.  (You were warned.)</para>

9
  <sect2 id="dumping-output">
10
    <title>Dumping out compiler intermediate structures</title>
daniel.is.fischer's avatar
daniel.is.fischer committed
11

12 13
    <indexterm><primary>dumping GHC intermediates</primary></indexterm>
    <indexterm><primary>intermediate passes, output</primary></indexterm>
daniel.is.fischer's avatar
daniel.is.fischer committed
14

15 16
    <variablelist>
      <varlistentry>
17 18 19 20
	<term>
          <option>-ddump-</option><replaceable>pass</replaceable>
          <indexterm><primary><option>-ddump</option> options</primary></indexterm>
        </term>
21 22 23 24 25
	<listitem>
	  <para>Make a debugging dump after pass
        <literal>&lt;pass&gt;</literal> (may be common enough to need
        a short form&hellip;).  You can get all of these at once
        (<emphasis>lots</emphasis> of output) by using
26
        <option>-v5</option>, or most of them with
Edward Z. Yang's avatar
Edward Z. Yang committed
27 28 29
        <option>-v4</option>.  You can prevent them from clogging up
        your standard output by passing <option>-ddump-to-file</option>.
        Some of the most useful ones are:</para>
30 31 32

	  <variablelist>
	    <varlistentry>
33 34 35 36
	      <term>
	        <option>-ddump-parsed</option>:
                <indexterm><primary><option>-ddump-parsed</option></primary></indexterm>
	      </term>
37 38 39 40 41 42
	      <listitem>
		<para>parser output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
43 44 45 46
	      <term>
	        <option>-ddump-rn</option>:
                <indexterm><primary><option>-ddump-rn</option></primary></indexterm>
	      </term>
47 48 49 50 51 52
	      <listitem>
		<para>renamer output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
53 54 55 56
	      <term>
	        <option>-ddump-tc</option>:
                <indexterm><primary><option>-ddump-tc</option></primary></indexterm>
	      </term>
57 58 59 60 61
	      <listitem>
		<para>typechecker output</para>
	      </listitem>
	    </varlistentry>

62 63 64 65 66 67 68 69 70 71 72
	    <varlistentry>
	      <term>
	        <option>-ddump-splices</option>:
                <indexterm><primary><option>-ddump-splices</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>Dump Template Haskell expressions that we splice in,
                and what Haskell code the expression evaluates to.</para>
	      </listitem>
	    </varlistentry>

73
	    <varlistentry>
74 75 76 77
	      <term>
	        <option>-ddump-types</option>:
                <indexterm><primary><option>-ddump-types</option></primary></indexterm>
	      </term>
78 79 80 81 82 83 84 85 86 87 88
	      <listitem>
		<para>Dump a type signature for each value defined at
              the top level of the module.  The list is sorted
              alphabetically.  Using <option>-dppr-debug</option>
              dumps a type signature for all the imported and
              system-defined things as well; useful for debugging the
              compiler.</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
89 90 91 92
	      <term>
	        <option>-ddump-deriv</option>:
                <indexterm><primary><option>-ddump-deriv</option></primary></indexterm>
	      </term>
93 94 95 96 97 98
	      <listitem>
		<para>derived instances</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
99 100 101 102
	      <term>
	        <option>-ddump-ds</option>:
                <indexterm><primary><option>-ddump-ds</option></primary></indexterm>
	      </term>
103 104 105 106 107 108
	      <listitem>
		<para>desugarer output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
109 110 111 112
	      <term>
	        <option>-ddump-spec</option>:
                <indexterm><primary><option>-ddump-spec</option></primary></indexterm>
	      </term>
113 114 115 116 117 118
	      <listitem>
		<para>output of specialisation pass</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
119 120 121 122
	      <term>
	        <option>-ddump-rules</option>:
                <indexterm><primary><option>-ddump-rules</option></primary></indexterm>
	      </term>
123
	      <listitem>
daniel.is.fischer's avatar
daniel.is.fischer committed
124
		<para>dumps all rewrite rules specified in this module;
125 126
                      see <xref linkend="controlling-rules"/>.
                </para>
127 128 129
	      </listitem>
	    </varlistentry>

130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	    <varlistentry>
	      <term>
	        <option>-ddump-rule-firings</option>:
                <indexterm><primary><option>-ddump-rule-firings</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>dumps the names of all rules that fired in this module</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
	      <term>
	        <option>-ddump-rule-rewrites</option>:
                <indexterm><primary><option>-ddump-rule-rewrites</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>dumps detailed information about all rules that fired in
		      this module
		</para>
	      </listitem>
	    </varlistentry>

152 153 154 155 156 157 158 159 160 161 162
	    <varlistentry>
	      <term>
	        <option>-ddump-vect</option>:
                <indexterm><primary><option>-ddump-vect</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>dumps the output of the vectoriser.
                </para>
	      </listitem>
	    </varlistentry>

163
	    <varlistentry>
164 165 166 167
	      <term>
	        <option>-ddump-simpl</option>:
                <indexterm><primary><option>-ddump-simpl</option></primary></indexterm>
	      </term>
168
	      <listitem>
ross's avatar
ross committed
169
		<para>simplifier output (Core-to-Core passes)</para>
170 171 172 173
	      </listitem>
	    </varlistentry>

	    <varlistentry>
174 175 176 177
	      <term>
	        <option>-ddump-inlinings</option>:
                <indexterm><primary><option>-ddump-inlinings</option></primary></indexterm>
	      </term>
178 179 180 181 182 183
	      <listitem>
		<para>inlining info from the simplifier</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
184 185 186 187
	      <term>
	        <option>-ddump-stranal</option>:
                <indexterm><primary><option>-ddump-stranal</option></primary></indexterm>
	      </term>
188 189 190 191 192
	      <listitem>
		<para>strictness analyser output</para>
	      </listitem>
	    </varlistentry>

Joachim Breitner's avatar
Joachim Breitner committed
193 194 195 196 197 198 199 200 201 202
	    <varlistentry>
	      <term>
	        <option>-ddump-strsigs</option>:
                <indexterm><primary><option>-ddump-strsigs</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>strictness signatures</para>
	      </listitem>
	    </varlistentry>

203
	    <varlistentry>
204 205 206 207
	      <term>
	        <option>-ddump-cse</option>:
                <indexterm><primary><option>-ddump-cse</option></primary></indexterm>
	      </term>
208 209 210 211 212 213
	      <listitem>
		<para>CSE pass output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
214
	      <term>
shelarcy's avatar
shelarcy committed
215 216
	        <option>-ddump-worker-wrapper</option>:
                <indexterm><primary><option>-ddump-worker-wrapper</option></primary></indexterm>
217
	      </term>
218 219 220 221 222 223
	      <listitem>
		<para>worker/wrapper split output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
224 225 226 227
	      <term>
	        <option>-ddump-occur-anal</option>:
                <indexterm><primary><option>-ddump-occur-anal</option></primary></indexterm>
	      </term>
228 229 230 231 232
	      <listitem>
		<para>`occurrence analysis' output</para>
	      </listitem>
	    </varlistentry>

233 234 235 236 237 238 239 240 241 242
	    <varlistentry>
	      <term>
	        <option>-ddump-prep</option>:
                <indexterm><primary><option>-ddump-prep</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>output of core preparation pass</para>
	      </listitem>
	    </varlistentry>

243
	    <varlistentry>
244 245 246 247
	      <term>
	        <option>-ddump-stg</option>:
                <indexterm><primary><option>-ddump-stg</option></primary></indexterm>
	      </term>
248 249 250 251 252
	      <listitem>
		<para>output of STG-to-STG passes</para>
	      </listitem>
	    </varlistentry>

253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
	    <varlistentry>
	      <term>
	        <option>-ddump-cmm</option>:
                <indexterm><primary><option>-ddump-cmm</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>Print the C-- code out.</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
	      <term>
	        <option>-ddump-opt-cmm</option>:
                <indexterm><primary><option>-ddump-opt-cmm</option></primary></indexterm>
	      </term>
	      <listitem>
		<para>Dump the results of C-- to C-- optimising passes.</para>
	      </listitem>
	    </varlistentry>

273
	    <varlistentry>
274 275 276 277
	      <term>
	        <option>-ddump-asm</option>:
                <indexterm><primary><option>-ddump-asm</option></primary></indexterm>
	      </term>
278
	      <listitem>
dterei's avatar
dterei committed
279 280
            <para>assembly language from the
              <link linkend="native-code-gen">native code generator</link></para>
281 282 283
	      </listitem>
	    </varlistentry>

dterei's avatar
dterei committed
284 285 286 287 288 289
	    <varlistentry>
	      <term>
	        <option>-ddump-llvm</option>:
                <indexterm><primary><option>-ddump-llvm</option></primary></indexterm>
	      </term>
	      <listitem>
dterei's avatar
dterei committed
290 291
	        <para>LLVM code from the <link linkend="llvm-code-gen">LLVM code
	          generator</link></para>
dterei's avatar
dterei committed
292 293 294
	      </listitem>
	    </varlistentry>

295
	    <varlistentry>
296 297 298 299
	      <term>
	        <option>-ddump-bcos</option>:
                <indexterm><primary><option>-ddump-bcos</option></primary></indexterm>
	      </term>
300 301 302 303 304 305
	      <listitem>
		<para>byte code compiler output</para>
	      </listitem>
	    </varlistentry>

	    <varlistentry>
306 307 308 309
	      <term>
	        <option>-ddump-foreign</option>:
                <indexterm><primary><option>-ddump-foreign</option></primary></indexterm>
	      </term>
310 311 312 313 314 315 316
	      <listitem>
		<para>dump foreign export stubs</para>
	      </listitem>
	    </varlistentry>
	  </variablelist>
	</listitem>
      </varlistentry>
daniel.is.fischer's avatar
daniel.is.fischer committed
317

318 319 320 321 322 323 324 325
      <varlistentry>
	<term>
          <option>-ddump-simpl-iterations</option>:
          <indexterm><primary><option>-ddump-simpl-iterations</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Show the output of each <emphasis>iteration</emphasis>
        of the simplifier (each run of the simplifier has a maximum
326 327
        number of iterations, normally 4).  This outputs even more information
        than <option>-ddump-simpl-phases</option>.</para>
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
	</listitem>
      </varlistentry>

      <varlistentry>
	<term>
          <option>-ddump-simpl-stats</option>
          <indexterm><primary><option>-ddump-simpl-stats option</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Dump statistics about how many of each kind of
        transformation too place.  If you add
        <option>-dppr-debug</option> you get more detailed
        information.</para>
	</listitem>
      </varlistentry>

344 345 346 347 348 349 350
      <varlistentry>
	<term>
          <option>-ddump-if-trace</option>
          <indexterm><primary><option>-ddump-if-trace</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Make the interface loader be *real* chatty about what it is
daniel.is.fischer's avatar
daniel.is.fischer committed
351
	up to.</para>
352 353 354 355
	</listitem>
      </varlistentry>

      <varlistentry>
356
  <term>
357 358 359
          <option>-ddump-tc-trace</option>
          <indexterm><primary><option>-ddump-tc-trace</option></primary></indexterm>
        </term>
360 361
  <listitem>
    <para>Make the type checker be *real* chatty about what it is
daniel.is.fischer's avatar
daniel.is.fischer committed
362
  up to.</para>
363 364 365 366 367 368 369 370 371 372
  </listitem>
      </varlistentry>

      <varlistentry>
  <term>
          <option>-ddump-vt-trace</option>
          <indexterm><primary><option>-ddump-tv-trace</option></primary></indexterm>
        </term>
  <listitem>
    <para>Make the vectoriser be *real* chatty about what it is
daniel.is.fischer's avatar
daniel.is.fischer committed
373
  up to.</para>
374
  </listitem>
375 376
      </varlistentry>

377 378 379 380 381 382 383
      <varlistentry>
	<term>
          <option>-ddump-rn-trace</option>
          <indexterm><primary><option>-ddump-rn-trace</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Make the renamer be *real* chatty about what it is
daniel.is.fischer's avatar
daniel.is.fischer committed
384
	up to.</para>
385 386 387 388 389 390 391 392 393 394 395 396 397 398
	</listitem>
      </varlistentry>

      <varlistentry>
	<term>
          <option>-ddump-rn-stats</option>
          <indexterm><primary><option>-dshow-rn-stats</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Print out summary of what kind of information the renamer
        had to bring in.</para>
	</listitem>
      </varlistentry>

399
      <varlistentry>
400 401 402 403 404 405 406 407
	<term>
          <option>-dverbose-core2core</option>
          <indexterm><primary><option>-dverbose-core2core</option></primary></indexterm>
        </term>
	<term>
          <option>-dverbose-stg2stg</option>
          <indexterm><primary><option>-dverbose-stg2stg</option></primary></indexterm>
        </term>
408 409 410 411 412
	<listitem>
	  <para>Show the output of the intermediate Core-to-Core and
        STG-to-STG passes, respectively.  (<emphasis>Lots</emphasis>
        of output!) So: when we're really desperate:</para>

413
	  <screen>
414
% ghc -noC -O -ddump-simpl -dverbose-core2core -dcore-lint Foo.hs
415
</screen>
rrt's avatar
rrt committed
416

417 418
	</listitem>
      </varlistentry>
daniel.is.fischer's avatar
daniel.is.fischer committed
419

420 421 422 423 424 425 426 427 428 429
      <varlistentry>
	<term>
          <option>-dshow-passes</option>
          <indexterm><primary><option>-dshow-passes</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Print out each pass name as it happens.</para>
	</listitem>
      </varlistentry>

430 431 432 433 434 435 436 437 438 439 440
      <varlistentry>
	<term>
          <option>-ddump-core-stats</option>
          <indexterm><primary><option>-ddump-core-stats</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Print a one-line summary of the size of the Core program
                     at the end of the optimisation pipeline.</para>
	</listitem>
      </varlistentry>

Ian Lynagh's avatar
Ian Lynagh committed
441 442 443 444 445 446 447
      <varlistentry>
	<term>
          <option>-dfaststring-stats</option>
          <indexterm><primary><option>-dfaststring-stats</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Show statistics for the usage of fast strings by the
448
          compiler.</para>
Ian Lynagh's avatar
Ian Lynagh committed
449 450 451
	</listitem>
      </varlistentry>

452
      <varlistentry>
453 454 455 456
	<term>
          <option>-dppr-debug</option>
          <indexterm><primary><option>-dppr-debug</option></primary></indexterm>
        </term>
457 458 459 460 461 462 463 464 465 466 467 468 469
	<listitem>
	  <para>Debugging output is in one of several
          &ldquo;styles.&rdquo; Take the printing of types, for
          example.  In the &ldquo;user&rdquo; style (the default), the
          compiler's internal ideas about types are presented in
          Haskell source-level syntax, insofar as possible.  In the
          &ldquo;debug&rdquo; style (which is the default for
          debugging output), the types are printed in with explicit
          foralls, and variables have their unique-id attached (so you
          can check for things that look the same but aren't).  This
          flag makes debugging output appear in the more verbose debug
          style.</para>
	</listitem>
470
      </varlistentry>
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
    </variablelist>
  </sect2>

  <sect2 id="formatting dumps">
    <title>Formatting dumps</title>

    <indexterm><primary>formatting dumps</primary></indexterm>

     <variablelist>
      <varlistentry>
	<term>
          <option>-dppr-user-length</option>
          <indexterm><primary><option>-dppr-user-length</option></primary></indexterm>
        </term>
	<listitem>
	  <para>In error messages, expressions are printed to a
	  certain &ldquo;depth&rdquo;, with subexpressions beyond the
	  depth replaced by ellipses.  This flag sets the
	  depth.  Its default value is 5.</para>
	</listitem>
      </varlistentry>

      <varlistentry>
	<term>
          <option>-dppr-colsNNN</option>
          <indexterm><primary><option>-dppr-colsNNN</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Set the width of debugging output. Use this if your code is wrapping too much.
		For example: <option>-dppr-cols200</option>.</para>
	</listitem>
      </varlistentry>

      <varlistentry>
	<term>
          <option>-dppr-case-as-let</option>
          <indexterm><primary><option>-dppr-case-as-let</option></primary></indexterm>
        </term>
	<listitem>
daniel.is.fischer's avatar
daniel.is.fischer committed
510
	  <para>Print single alternative case expressions as though they were strict
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
		let expressions. This is helpful when your code does a lot of unboxing.</para>
	</listitem>
      </varlistentry>

      <varlistentry>
        <term>
          <option>-dno-debug-output</option>
          <indexterm><primary><option>-dno-debug-output</option></primary></indexterm>
        </term>
        <listitem>
          <para>Suppress any unsolicited debugging output.  When GHC
            has been built with the <literal>DEBUG</literal> option it
            occasionally emits debug output of interest to developers.
            The extra output can confuse the testing framework and
            cause bogus test failures, so this flag is provided to
            turn it off.</para>
        </listitem>
      </varlistentry>
     </variablelist>

  </sect2>

533
  <sect2 id="suppression">
534 535 536 537 538 539 540 541 542 543 544 545 546 547
    <title>Suppressing unwanted information</title>

    <indexterm><primary>suppression</primary></indexterm>

    Core dumps contain a large amount of information. Depending on what you are doing, not all of it will be useful.
    Use these flags to suppress the parts that you are not interested in.

    <variablelist>
      <varlistentry>
	<term>
          <option>-dsuppress-all</option>
          <indexterm><primary><option>-dsuppress-all</option></primary></indexterm>
        </term>
	<listitem>
daniel.is.fischer's avatar
daniel.is.fischer committed
548
	  <para>Suppress everything that can be suppressed, except for unique ids as this often
549 550 551 552
		makes the printout ambiguous. If you just want to see the overall structure of
		the code, then start here.</para>
	</listitem>
      </varlistentry>
553 554 555 556 557 558 559

      <varlistentry>
	<term>
          <option>-dsuppress-uniques</option>
          <indexterm><primary><option>-dsuppress-uniques</option></primary></indexterm>
        </term>
	<listitem>
daniel.is.fischer's avatar
daniel.is.fischer committed
560
	  <para>Suppress the printing of uniques. This may make
561 562 563 564 565
	  the printout ambiguous (e.g. unclear where an occurrence of 'x' is bound), but
	  it makes the output of two compiler runs have many fewer gratuitous differences,
	    so you can realistically apply <command>diff</command>.  Once <command>diff</command>
	  has shown you where to look, you can try again without <option>-dsuppress-uniques</option></para>
	</listitem>
566 567 568 569
      </varlistentry>

      <varlistentry>
	<term>
570 571
          <option>-dsuppress-idinfo</option>
          <indexterm><primary><option>-dsuppress-idinfo</option></primary></indexterm>
572 573
        </term>
	<listitem>
574
	  <para>Suppress extended information about identifiers where they are bound. This includes
daniel.is.fischer's avatar
daniel.is.fischer committed
575
		strictness information and inliner templates. Using this flag can cut the size
576
		of the core dump in half, due to the lack of inliner templates</para>
577
	</listitem>
578 579
      </varlistentry>

580 581 582 583 584 585
      <varlistentry>
	<term>
          <option>-dsuppress-module-prefixes</option>
          <indexterm><primary><option>-dsuppress-module-prefixes</option></primary></indexterm>
        </term>
	<listitem>
586 587
          <para>Suppress the printing of module qualification prefixes.
	        This is the <constant>Data.List</constant> in <constant>Data.List.length</constant>.</para>
588 589 590
	</listitem>
      </varlistentry>

591
      <varlistentry>
592
	<term>
593 594
          <option>-dsuppress-type-signatures</option>
          <indexterm><primary><option>-dsuppress-type-signatures</option></primary></indexterm>
595
        </term>
596
	<listitem>
597
          <para>Suppress the printing of type signatures.</para>
598 599 600 601
	</listitem>
      </varlistentry>

      <varlistentry>
602 603 604
	<term>
          <option>-dsuppress-type-applications</option>
          <indexterm><primary><option>-dsuppress-type-applications</option></primary></indexterm>
605
        </term>
606 607 608 609 610 611 612 613 614 615 616 617 618
	<listitem>
          <para>Suppress the printing of type applications.</para>
	</listitem>
      </varlistentry>

      <varlistentry>
	<term>
          <option>-dsuppress-coercions</option>
          <indexterm><primary><option>-dsuppress-coercions</option></primary></indexterm>
        </term>
	<listitem>
          <para>Suppress the printing of type coercions.</para>
	</listitem>
619 620 621 622 623 624 625 626 627 628 629 630 631
      </varlistentry>
    </variablelist>
  </sect2>

  <sect2 id="checking-consistency">
    <title>Checking for consistency</title>

    <indexterm><primary>consistency checks</primary></indexterm>
    <indexterm><primary>lint</primary></indexterm>

    <variablelist>

      <varlistentry>
632 633 634 635
	<term>
          <option>-dcore-lint</option>
          <indexterm><primary><option>-dcore-lint</option></primary></indexterm>
        </term>
636 637 638 639 640 641 642
	<listitem>
	  <para>Turn on heavyweight intra-pass sanity-checking within
          GHC, at Core level.  (It checks GHC's sanity, not yours.)</para>
	</listitem>
      </varlistentry>

      <varlistentry>
643 644 645 646
	<term>
          <option>-dstg-lint</option>:
          <indexterm><primary><option>-dstg-lint</option></primary></indexterm>
        </term>
647 648 649 650 651
	<listitem>
	  <para>Ditto for STG level. (NOTE: currently doesn't work).</para>
	</listitem>
      </varlistentry>

652 653 654 655 656 657 658 659 660 661
      <varlistentry>
	<term>
          <option>-dcmm-lint</option>:
          <indexterm><primary><option>-dcmm-lint</option></primary></indexterm>
        </term>
	<listitem>
	  <para>Ditto for C-- level.</para>
	</listitem>
      </varlistentry>

662 663 664 665 666 667 668 669 670 671 672 673
    </variablelist>
  </sect2>

  <sect2>
    <title>How to read Core syntax (from some <option>-ddump</option>
    flags)</title>

    <indexterm><primary>reading Core syntax</primary></indexterm>
    <indexterm><primary>Core syntax, how to read</primary></indexterm>

    <para>Let's do this by commenting an example.  It's from doing
    <option>-ddump-ds</option> on this code:
rrt's avatar
rrt committed
674

675
<programlisting>
rrt's avatar
rrt committed
676
skip2 m = m : skip2 (m+2)
677
</programlisting>
rrt's avatar
rrt committed
678

679 680 681 682 683 684 685 686 687 688 689 690 691 692 693
    Before we jump in, a word about names of things.  Within GHC,
    variables, type constructors, etc., are identified by their
    &ldquo;Uniques.&rdquo; These are of the form `letter' plus
    `number' (both loosely interpreted).  The `letter' gives some idea
    of where the Unique came from; e.g., <literal>&lowbar;</literal>
    means &ldquo;built-in type variable&rdquo;; <literal>t</literal>
    means &ldquo;from the typechecker&rdquo;; <literal>s</literal>
    means &ldquo;from the simplifier&rdquo;; and so on.  The `number'
    is printed fairly compactly in a `base-62' format, which everyone
    hates except me (WDP).</para>

    <para>Remember, everything has a &ldquo;Unique&rdquo; and it is
    usually printed out when debugging, in some form or another.  So
    here we go&hellip;</para>

694
<programlisting>
rrt's avatar
rrt committed
695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719
Desugared:
Main.skip2{-r1L6-} :: _forall_ a$_4 =&#62;{{Num a$_4}} -&#62; a$_4 -&#62; [a$_4]

--# `r1L6' is the Unique for Main.skip2;
--# `_4' is the Unique for the type-variable (template) `a'
--# `{{Num a$_4}}' is a dictionary argument

_NI_

--# `_NI_' means "no (pragmatic) information" yet; it will later
--# evolve into the GHC_PRAGMA info that goes into interface files.

Main.skip2{-r1L6-} =
    /\ _4 -&#62; \ d.Num.t4Gt -&#62;
        let {
          {- CoRec -}
          +.t4Hg :: _4 -&#62; _4 -&#62; _4
          _NI_
          +.t4Hg = (+{-r3JH-} _4) d.Num.t4Gt

          fromInt.t4GS :: Int{-2i-} -&#62; _4
          _NI_
          fromInt.t4GS = (fromInt{-r3JX-} _4) d.Num.t4Gt

--# The `+' class method (Unique: r3JH) selects the addition code
ross's avatar
ross committed
720
--# from a `Num' dictionary (now an explicit lambda'd argument).
rrt's avatar
rrt committed
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
--# Because Core is 2nd-order lambda-calculus, type applications
--# and lambdas (/\) are explicit.  So `+' is first applied to a
--# type (`_4'), then to a dictionary, yielding the actual addition
--# function that we will use subsequently...

--# We play the exact same game with the (non-standard) class method
--# `fromInt'.  Unsurprisingly, the type `Int' is wired into the
--# compiler.

          lit.t4Hb :: _4
          _NI_
          lit.t4Hb =
              let {
                ds.d4Qz :: Int{-2i-}
                _NI_
                ds.d4Qz = I#! 2#
              } in  fromInt.t4GS ds.d4Qz

--# `I# 2#' is just the literal Int `2'; it reflects the fact that
--# GHC defines `data Int = I# Int#', where Int# is the primitive
--# unboxed type.  (see relevant info about unboxed types elsewhere...)

--# The `!' after `I#' indicates that this is a *saturated*
--# application of the `I#' data constructor (i.e., not partially
--# applied).

          skip2.t3Ja :: _4 -&#62; [_4]
          _NI_
          skip2.t3Ja =
              \ m.r1H4 -&#62;
                  let { ds.d4QQ :: [_4]
                        _NI_
                        ds.d4QQ =
                    let {
                      ds.d4QY :: _4
                      _NI_
                      ds.d4QY = +.t4Hg m.r1H4 lit.t4Hb
                    } in  skip2.t3Ja ds.d4QY
                  } in
                  :! _4 m.r1H4 ds.d4QQ

          {- end CoRec -}
        } in  skip2.t3Ja
764
</programlisting>
rrt's avatar
rrt committed
765

766 767 768 769
    <para>(&ldquo;It's just a simple functional language&rdquo; is an
    unregisterised trademark of Peyton Jones Enterprises, plc.)</para>

  </sect2>
rrt's avatar
rrt committed
770

771
</sect1>
772 773 774

<!-- Emacs stuff:
     ;;; Local Variables: ***
775
     ;;; sgml-parent-document: ("users_guide.xml" "book" "chapter" "sect1") ***
776 777
     ;;; End: ***
 -->