... | ... | @@ -22,6 +22,8 @@ The `HsSyn` modules live in the [compiler/hsSyn](/trac/ghc/browser/ghc/compiler/ |
|
|
|
|
|
There is significant mutual recursion between modules, and hence a couple of `lhs-boot` files. Look at [ModuleDependencies](module-dependencies) to see the dependencies.
|
|
|
|
|
|
## Decorating `HsSyn` with type information
|
|
|
|
|
|
|
|
|
The type checker adds type information to the syntax tree, otherwise leaving it as undisturbed as possible. This is done in two ways:
|
|
|
|
... | ... | @@ -38,6 +40,17 @@ The type checker adds type information to the syntax tree, otherwise leaving it |
|
|
|
|
|
An `ExplicitList` represents the explicit list construct in Haskell (e.g. "`[2, 4, 1]`"). The parser fills the `PostTcType` field with an error thunk `HsTypes.placeHolderType`; and the renamer does not touch it. The typechecker figures out the type, and fills in the value. So until the type checker, we cannot examine or print the `PostTcType` fields.
|
|
|
|
|
|
>
|
|
|
> The error thunks mean that we can't conveniently pretty-print the `PostTcType` fields, because the pretty-printer would poke the error thunks when run on pre-typchecked code. We could have defined `PostTcType` to be `Maybe Type`, but that would have meant unwrapping lots of `Just` constructors, which is messy. It would be nicer to parameterise `HsSyn` over the `PostTcType` fields. Thus:
|
|
|
>
|
|
|
> ```wiki
|
|
|
> type RnHsBinds = HsBinds Name () -- After renaming
|
|
|
> type TcHsBines = HsBinds Id Type -- After type checking
|
|
|
> ```
|
|
|
>
|
|
|
>
|
|
|
> This would be a Good Thing to do.
|
|
|
|
|
|
- In a few cases, the typechecker moves from one constructor to another. Example:
|
|
|
|
|
|
```wiki
|
... | ... | @@ -59,9 +72,32 @@ The type checker adds type information to the syntax tree, otherwise leaving it |
|
|
|
|
|
- There are a few constructors added by type checker (rather than replacing an input constructor), particularly:
|
|
|
|
|
|
- `HsCoerce`, in the `HsExpr` type.
|
|
|
- `HsWrap`, in the `HsExpr` type.
|
|
|
- `AbsBinds`, in the `HsBinds` type.
|
|
|
SLPJ: These are invariably to do with type abstraction and application, since Haskell source is implicitly generalized and instantiated, whereas GHC's intermediate form is explicitly generalized and instantiated.
|
|
|
|
|
|
>
|
|
|
> These are invariably to do with type abstraction and application, since Haskell source is implicitly generalized and instantiated, whereas GHC's intermediate form is explicitly generalized and instantiated.
|
|
|
|
|
|
## Source Locations
|
|
|
|
|
|
`HsSyn` makes heavy use of the `Located` type ([compiler/BasicTypes/SrcLoc](/trac/ghc/browser/ghc/compiler/BasicTypes/SrcLoc)):
|
|
|
|
|
|
```wiki
|
|
|
data Located e = L SrcSpan e
|
|
|
```
|
|
|
|
|
|
|
|
|
A `Located t` is just a pair of a `SrcSpan` (which describes the source location of `t`) and a syntax tree `t`. The module `SrcLoc` defines two other types:
|
|
|
|
|
|
- `SrcLoc` specifies a particular source location: (filename, line number, character position)
|
|
|
- `SrcSpan` specifes a range of source locations: (filename, start line number and character position, end line number and character position)
|
|
|
|
|
|
|
|
|
More details in [compiler/BasicTypes/SrcLoc](/trac/ghc/browser/ghc/compiler/BasicTypes/SrcLoc).
|
|
|
|
|
|
|
|
|
Naming convention within the code: "`LHs`" means located Haskell, e.g.
|
|
|
|
|
|
Naming convention within the code: LHs means located Haskell, i.e., data wrapped with the Located constructor. |
|
|
```wiki
|
|
|
type LHsBinds n = Located (HsBinds n)
|
|
|
``` |
|
|
\ No newline at end of file |