Changes between Version 46 and Version 47 of Commentary/Compiler/HscMain


Ignore:
Timestamp:
May 9, 2011 8:37:48 PM (3 years ago)
Author:
dterei
Comment:

Fix up source links

Legend:

Unmodified
Added
Removed
Modified
  • Commentary/Compiler/HscMain

    v46 v47  
    66You can also watch a '''video''' of Simon Peyton-Jones explaining the compilation pipeline here: [http://video.google.com/videoplay?docid=5254545394467397086 Compiler Pipeline II] (10'16") 
    77 
    8 Look at the picture first.  The yellow boxes are compiler passes, while the blue stuff on the left gives the data type that moves from one phase to the next.  The entire pipeline for a single module is run by a module called !HscMain ([[GhcFile(compiler/main/HscMain)]]).  Each data type's representation can be dumped for further inspection using a `-ddump-*` flag.  Here are the steps it goes through: 
     8Look at the picture first.  The yellow boxes are compiler passes, while the blue stuff on the left gives the data type that moves from one phase to the next.  The entire pipeline for a single module is run by a module called !HscMain ([[GhcFile(compiler/main/HscMain.lhs)]]).  Each data type's representation can be dumped for further inspection using a `-ddump-*` flag.  Here are the steps it goes through: 
    99 
    1010 * The '''Front End''' processes the program in the [wiki:Commentary/Compiler/HsSynType big HsSyn type]. {{{HsSyn}}} is parameterised over the types of the term variables it contains.  The first three passes (the front end) of the compiler work like this:[[BR]][[BR]] 
     
    1515 These three passes can all discover programmer errors, which are sorted and reported to the user. 
    1616  
    17  * The '''Desugarer''' ([[GhcFile(compiler/deSugar/Desugar)]]) converts from the massive {{{HsSyn}}} type to [wiki:Commentary/Compiler/CoreSynType GHC's intermediate language, CoreSyn].  This Core-language data type is unusually tiny: just eight constructors.) (`-ddump-ds`)[[BR]][[BR]] 
    18    Generally speaking, the desugarer produces few user errors or warnings. But it does produce ''some''.  In particular, (a) pattern-match overlap warnings are produced here; and (b) when desugaring Template Haskell code quotations, the desugarer may find that `THSyntax` is not expressive enough.  In that case, we must produce an error ([[GhcFile(compiler/deSugar/DsMeta)]]).[[BR]][[BR]] 
     17 * The '''Desugarer''' ([[GhcFile(compiler/deSugar/Desugar.lhs)]]) converts from the massive {{{HsSyn}}} type to [wiki:Commentary/Compiler/CoreSynType GHC's intermediate language, CoreSyn].  This Core-language data type is unusually tiny: just eight constructors.) (`-ddump-ds`)[[BR]][[BR]] 
     18   Generally speaking, the desugarer produces few user errors or warnings. But it does produce ''some''.  In particular, (a) pattern-match overlap warnings are produced here; and (b) when desugaring Template Haskell code quotations, the desugarer may find that `THSyntax` is not expressive enough.  In that case, we must produce an error ([[GhcFile(compiler/deSugar/DsMeta.hs)]]).[[BR]][[BR]] 
    1919   This late desugaring is somewhat unusual.  It is much more common to desugar the program before typechecking, or renaming, because that presents the renamer and typechecker with a much smaller language to deal with.  However, GHC's organisation means that 
    2020    * error messages can display precisely the syntax that the user wrote; and  
     
    2222 
    2323 
    24  * The '''!SimplCore''' pass ([[GhcFile(simplCore/SimplCore.lhs)]]) is a bunch of Core-to-Core passes that optimise the program; see [http://research.microsoft.com/%7Esimonpj/Papers/comp-by-trans-scp.ps.gz A transformation-based optimiser for Haskell (SCP'98)] for a more-or-less accurate overview.  The main passes are:[[BR]][[BR]] 
     24 * The '''!SimplCore''' pass ([[GhcFile(compiler/simplCore/SimplCore.lhs)]]) is a bunch of Core-to-Core passes that optimise the program; see [http://research.microsoft.com/%7Esimonpj/Papers/comp-by-trans-scp.ps.gz A transformation-based optimiser for Haskell (SCP'98)] for a more-or-less accurate overview.  The main passes are:[[BR]][[BR]] 
    2525    * The '''Simplifier''', which applies lots of small, local optimisations to the program.  The simplifier is big and complicated, because it implements a ''lot'' of transformations; and tries to make them cascade nicely.  The transformation-based optimiser paper gives lots of details, but two other papers are particularly relevant: [http://research.microsoft.com/%7Esimonpj/Papers/inlining/index.htm Secrets of the Glasgow Haskell Compiler inliner (JFP'02)] and [http://research.microsoft.com/%7Esimonpj/Papers/rules.htm Playing by the rules: rewriting as a practical optimisation technique in GHC (Haskell workshop 2001)].  (`-ddump-simpl`)[[BR]][[BR]] 
    2626    * The '''float-out''' and '''float-in''' transformations, which move let-bindings outwards and inwards respectively.  See [http://research.microsoft.com/%7Esimonpj/papers/float.ps.gz Let-floating: moving bindings to give faster programs (ICFP '96)].[[BR]][[BR]] 
     
    3838  * At this point, the data flow forks.  First, the tidied program is dumped into an interface file.  This part happens in two stages: 
    3939    * It is '''converted to {{{IfaceSyn}}}''' (defined in [[GhcFile(compiler/iface/IfaceSyn.lhs)]] and [[GhcFile(compiler/iface/IfaceType.lhs)]]). 
    40     * The {{{IfaceSyn}}} is '''serialised into a binary output file''' ([[GhcFile(compiler/iface/BinIface.lhs)]]). 
     40    * The {{{IfaceSyn}}} is '''serialised into a binary output file''' ([[GhcFile(compiler/iface/BinIface.hs)]]). 
    4141  The serialisation does (pretty much) nothing except serialise.  All the intelligence is in the `Core`-to-`IfaceSyn` conversion; or, rather, in the reverse of that step. 
    4242 
    4343  * The same, tidied Core program is now fed to the Back End.  First there is a two-stage conversion from {{{CoreSyn}}} to [wiki:Commentary/Compiler/StgSynType GHC's intermediate language, StgSyn]. 
    4444    * The first step is called '''!CorePrep''', a Core-to-Core pass that puts the program into A-normal form (ANF).  In ANF, the argument of every application is a variable or literal; more complicated arguments are let-bound.  Actually `CorePrep` does quite a bit more: there is a detailed list at the top of the file [[GhcFile(compiler/coreSyn/CorePrep.lhs)]]. 
    45     * The second step, '''!CoreToStg''', moves to the {{{StgSyn}}} data type ([[[GhcFile(compiler/stgSyn/CoreToStg.lhs)]]].  The output of !CorePrep is carefully arranged to exactly match what {{{StgSyn}}} allows (notably ANF), so there is very little work to do. However, {{{StgSyn}}} is decorated with lots of redundant information (free variables, let-no-escape indicators), which is generated on-the-fly by {{{CoreToStg}}}. 
     45    * The second step, '''!CoreToStg''', moves to the {{{StgSyn}}} data type ([[GhcFile(compiler/stgSyn/CoreToStg.lhs)]]).  The output of !CorePrep is carefully arranged to exactly match what {{{StgSyn}}} allows (notably ANF), so there is very little work to do. However, {{{StgSyn}}} is decorated with lots of redundant information (free variables, let-no-escape indicators), which is generated on-the-fly by {{{CoreToStg}}}. 
    4646 
    4747  * Next, the '''[wiki:Commentary/Compiler/CodeGen Code Generator]''' converts the STG program to a {{{C--}}} program.  The code generator is a Big Mother, and lives in directory [[GhcFile(compiler/codeGen)]]