Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>GHC Core is the <a href="http://research.microsoft.com/~simonpj/papers/ext-f/" rel="noreferrer">System FC</a> language into which all Haskell is translated. The (approximate) grammar for Core is given by:</p> <p><img src="https://i.stack.imgur.com/RP6fQ.png" alt="enter image description here"></p> <p>Core is closely related to the simpler and better known <a href="http://en.wikipedia.org/wiki/System_F" rel="noreferrer">System F</a>. All <a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/comp-by-trans-scp.ps.gz" rel="noreferrer">transformations GHC does on the Core level</a> are type-preserving refactorings of this Core representation, to improve performance. And, not so well known, you can write directly in Core to program GHC.</p> <p>GHC Core fits in the compiler pipeline (as it was in 2002, sans-LLVM and CMM):</p> <p><img src="https://i.stack.imgur.com/PtsCf.png" alt="enter image description here"></p> <p>The primary documents to learn about GHC Core are:</p> <ul> <li><strong><a href="http://www.haskell.org/ghc/docs/papers/core.ps.gz" rel="noreferrer">An External Representation for the GHC Core Language</a>, Tolmach, 2001</strong></li> <li><a href="https://github.com/ghc/ghc/blob/master/compiler/coreSyn/CoreSyn.hs#L141" rel="noreferrer">ghc/compiler/CoreSyn</a>, the GHC definition itself</li> <li><strong><a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/inlining/inline-jfp.ps.gz" rel="noreferrer">Secrets of the Glasgow Haskell Compiler inliner</a></strong>, Peyton Jones and Marlow, 1999. Core is described in Section 2.3, including details on the occurrence analysis annotations.</li> <li><strong><a href="http://research.microsoft.com/pubs/67064/comp-by-trans-scp.ps.gz" rel="noreferrer">A transformation-based optimiser for Haskell</a></strong>, Peyton Jones and Santos, 1998. Core is described in S3, including a discussion of polymorphism and operational readings of Core.</li> </ul> <p>Related material that can aid understanding:</p> <ul> <li>The <a href="http://www.haskell.org/ghc/docs/latest/html/users_guide/ext-core.html" rel="noreferrer">GHC -fext-core output</a></li> <li>I spent a lot of time learning Core by reading GHC source. Some is described in my <a href="https://web.archive.org/web/20170118091715/https://www.cse.unsw.edu.au/~pls/thesis/dons-thesis.ps.gz" rel="noreferrer">undergraduate thesis</a> from 2002, from page 16.</li> <li>From using the <a href="http://hackage.haskell.org/package/ghc-core" rel="noreferrer">ghc-core</a> tool, to generate Core in a format I find pleasing.</li> </ul> <p>Core in turn is translated into STG code, which looks something like:</p> <p><img src="https://i.stack.imgur.com/Gaj9X.png" alt="enter image description here"></p> <p>The funny names in Core are encoded in the "Z-encoding":</p> <p><img src="https://i.stack.imgur.com/J9pqR.png" alt="enter image description here"></p> <p>GHC Core's types and kinds (from Tolmach's paper):</p> <p><img src="https://i.stack.imgur.com/eNvd2.png" alt="enter image description here"></p> <p>Finally, GHC's <a href="https://ghc.haskell.org/trac/ghc/wiki/Commentary/PrimOps" rel="noreferrer">primops</a> appear regularly in GHC Core output, when you have optimized your Haskell down to the basic instructions GHC knows about. The primop set is given as a set of Core functions in <a href="https://ghc.haskell.org/trac/ghc/browser/ghc/compiler/prelude/primops.txt.pp#L12" rel="noreferrer">a pre-processed file.</a> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload