... | @@ -8,24 +8,24 @@ Video: [GHC Core language](http://www.youtube.com/watch?v=EQA69dvkQIk&list=PLBkR |
... | @@ -8,24 +8,24 @@ Video: [GHC Core language](http://www.youtube.com/watch?v=EQA69dvkQIk&list=PLBkR |
|
The Core language is GHC's central data types. Core is a very small, explicitly-typed, variant of System F. The exact variant is called [System FC](commentary/compiler/fc), which embodies equality constraints and coercions.
|
|
The Core language is GHC's central data types. Core is a very small, explicitly-typed, variant of System F. The exact variant is called [System FC](commentary/compiler/fc), which embodies equality constraints and coercions.
|
|
|
|
|
|
|
|
|
|
The `CoreSyn` type, and the functions that operate over it, gets an entire directory [compiler/coreSyn](/trac/ghc/browser/ghc/compiler/coreSyn):
|
|
The `CoreSyn` type, and the functions that operate over it, gets an entire directory [compiler/coreSyn](/ghc/ghc/tree/master/ghc/compiler/coreSyn):
|
|
|
|
|
|
- [compiler/coreSyn/CoreSyn.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreSyn.hs): the data type itself.
|
|
- [compiler/coreSyn/CoreSyn.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreSyn.hs): the data type itself.
|
|
|
|
|
|
- [compiler/coreSyn/PprCore.hs](/trac/ghc/browser/ghc/compiler/coreSyn/PprCore.hs): pretty-printing.
|
|
- [compiler/coreSyn/PprCore.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/PprCore.hs): pretty-printing.
|
|
- [compiler/coreSyn/CoreFVs.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreFVs.hs): finding free variables.
|
|
- [compiler/coreSyn/CoreFVs.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreFVs.hs): finding free variables.
|
|
- [compiler/coreSyn/CoreSubst.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreSubst.hs): substitution.
|
|
- [compiler/coreSyn/CoreSubst.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreSubst.hs): substitution.
|
|
- [compiler/coreSyn/CoreUtils.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreUtils.hs): a variety of other useful functions over Core.
|
|
- [compiler/coreSyn/CoreUtils.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreUtils.hs): a variety of other useful functions over Core.
|
|
|
|
|
|
- [compiler/coreSyn/CoreUnfold.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreUnfold.hs): dealing with "unfoldings".
|
|
- [compiler/coreSyn/CoreUnfold.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreUnfold.hs): dealing with "unfoldings".
|
|
|
|
|
|
- [compiler/coreSyn/CoreLint.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreLint.hs): type-check the Core program. This is an incredibly-valuable consistency check, enabled by the flag `-dcore-lint`.
|
|
- [compiler/coreSyn/CoreLint.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreLint.hs): type-check the Core program. This is an incredibly-valuable consistency check, enabled by the flag `-dcore-lint`.
|
|
|
|
|
|
- [compiler/coreSyn/CoreTidy.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreTidy.hs): part of the [the CoreTidy pass](commentary/compiler/hsc-main) (the rest is in [compiler/main/TidyPgm.hs](/trac/ghc/browser/ghc/compiler/main/TidyPgm.hs)).
|
|
- [compiler/coreSyn/CoreTidy.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreTidy.hs): part of the [the CoreTidy pass](commentary/compiler/hsc-main) (the rest is in [compiler/main/TidyPgm.hs](/trac/ghc/browser/ghc/compiler/main/TidyPgm.hs)).
|
|
- [compiler/coreSyn/CorePrep.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CorePrep.hs): [the CorePrep pass](commentary/compiler/hsc-main)
|
|
- [compiler/coreSyn/CorePrep.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CorePrep.hs): [the CorePrep pass](commentary/compiler/hsc-main)
|
|
|
|
|
|
|
|
|
|
Here is the entire Core type [compiler/coreSyn/CoreSyn.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreSyn.hs):
|
|
Here is the entire Core type [compiler/coreSyn/CoreSyn.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreSyn.hs):
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
type CoreExpr = Expr Var
|
|
type CoreExpr = Expr Var
|
... | @@ -56,7 +56,7 @@ That's it. All of Haskell gets compiled through this tiny core. |
... | @@ -56,7 +56,7 @@ That's it. All of Haskell gets compiled through this tiny core. |
|
If you want to learn more about such AST-parametrization, I encourage you to read a blog post about it: [http://blog.ezyang.com/2013/05/the-ast-typing-problem](http://blog.ezyang.com/2013/05/the-ast-typing-problem) .
|
|
If you want to learn more about such AST-parametrization, I encourage you to read a blog post about it: [http://blog.ezyang.com/2013/05/the-ast-typing-problem](http://blog.ezyang.com/2013/05/the-ast-typing-problem) .
|
|
|
|
|
|
|
|
|
|
Binder is used (as the name suggest) to bind a variable to an expression. The `Expr` data type is parametrized by the binder type. The most common one is the `type CoreBndr = Var` where `Var` comes from [compiler/basicTypes/Var.hs](/trac/ghc/browser/ghc/compiler/basicTypes/Var.hs), which in fact is a `Name` with some extra informations attached (like types).
|
|
Binder is used (as the name suggest) to bind a variable to an expression. The `Expr` data type is parametrized by the binder type. The most common one is the `type CoreBndr = Var` where `Var` comes from [compiler/basicTypes/Var.hs](/ghc/ghc/tree/master/ghc/compiler/basicTypes/Var.hs), which in fact is a `Name` with some extra informations attached (like types).
|
|
|
|
|
|
|
|
|
|
Here are some notes about the individual constructors of `Expr`.
|
|
Here are some notes about the individual constructors of `Expr`.
|
... | @@ -175,7 +175,7 @@ allowed. In other words, it is possible to come across a definition of a |
... | @@ -175,7 +175,7 @@ allowed. In other words, it is possible to come across a definition of a |
|
variable that has the same name (`realUnique`) as some other one that is
|
|
variable that has the same name (`realUnique`) as some other one that is
|
|
already in scope. One of the possible ways to deal with that is to
|
|
already in scope. One of the possible ways to deal with that is to
|
|
use `Subst` (substitution environment from
|
|
use `Subst` (substitution environment from
|
|
[compiler/coreSyn/CoreSubst.hs](/trac/ghc/browser/ghc/compiler/coreSyn/CoreSubst.hs)), which maintains the list of
|
|
[compiler/coreSyn/CoreSubst.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/CoreSubst.hs)), which maintains the list of
|
|
variables in scope and makes it possible to clone (i.e. rename) only the
|
|
variables in scope and makes it possible to clone (i.e. rename) only the
|
|
variables that actually capture names of some earlier ones. For some more
|
|
variables that actually capture names of some earlier ones. For some more
|
|
explanations about this approach see
|
|
explanations about this approach see
|
... | @@ -185,4 +185,4 @@ explanations about this approach see |
... | @@ -185,4 +185,4 @@ explanations about this approach see |
|
## Human readable Core generation
|
|
## Human readable Core generation
|
|
|
|
|
|
|
|
|
|
If you are interested in the way Core is translated into human readable form, you should check the sources for [compiler/coreSyn/PprCore.hs](/trac/ghc/browser/ghc/compiler/coreSyn/PprCore.hs). It is especially usefull if you want to see how the Core data types are being built, especially when there is no Show instance defined for them. |
|
If you are interested in the way Core is translated into human readable form, you should check the sources for [compiler/coreSyn/PprCore.hs](/ghc/ghc/tree/master/ghc/compiler/coreSyn/PprCore.hs). It is especially usefull if you want to see how the Core data types are being built, especially when there is no Show instance defined for them. |