Changes between Version 33 and Version 34 of Commentary/Compiler/HscMain
- Timestamp:
- 11/02/07 03:18:15 (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Commentary/Compiler/HscMain
v33 v34 10 10 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 (in [[GhcFile(compiler/main/HscMain.lhs)]]). Here are the steps it goes through: 11 11 12 * The program is initially parsed intothe [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]]12 * The '''FrontEnd''' 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]] 13 13 * The '''Parser''' produces {{{HsSyn}}} parameterised by '''[wiki:Commentary/Compiler/RdrNameType RdrName]'''. To a first approximation, a {{{RdrName}}} is just a string.[[BR]][[BR]] 14 14 * The '''[wiki:Commentary/Compiler/Renamer Renamer]''' transforms this to {{{HsSyn}}} parameterised by '''[wiki:Commentary/Compiler/NameType Name]'''. To a first appoximation, a {{{Name}}} is a string plus a {{{Unique}}} (number) that uniquely identifies it. In particular, the renamer associates each identifier with its binding instance and ensures that all occurrences which associate to the same binding instance share a single {{{Unique}}}.[[BR]][[BR]] … … 17 17 These three passes can all discover programmer errors, which are sorted and reported to the user. 18 18 19 * 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. 20 [[BR]][[BR]]19 * 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.[[BR]][[BR]] 20 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]] 21 21 This late desugaring is somewhat unusual. It is much more common to desugar the program before typechecking, or renaming, becuase that presents the renamer and typechecker with a much smaller language to deal with. However, GHC's organisation means that 22 * error messages can display precisely the syntax that the user wrote; and 23 * desugaring is not required to preserve type-inference properties.[[BR]] 24 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)]]). 22 * error messages can display precisely the syntax that the user wrote; and 23 * desugaring is not required to preserve type-inference properties.[[BR]][[BR]] 25 24 26 * 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]] 25 26 * 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]] 27 27 * 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)].[[BR]][[BR]] 28 28 * 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]] … … 44 44 45 45 * 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]. 46 * 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)]].47 * The second step, ''' CoreToStg''', moves to the {{{StgSyn}}} data type (the code is in [[[GhcFile(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}}}.46 * 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)]]. 47 * The second step, '''!CoreToStg''', moves to the {{{StgSyn}}} data type (the code is in [[[GhcFile(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}}}. 48 48 49 * Next, the '''[wiki:C Ommentary/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)]]49 * 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)]] 50 50 51 51 * Now the path forks again:
