Legend:

Probably the most important phase in the frontend is the type checker, which is located at [[GhcFile(compiler/typecheck/)]]. GHC type checks programs in their original Haskell form before the desugarer converts them into Core code. This complicates the type checker as it has to handle the much more verbose Haskell AST, but it improves error messages, as those message are based on the same structure that the user sees.

4

4

5

GHC defines the abstract syntax of Haskell programs in [[GhcModule(compiler/hsSyn/HsSyn.lhs)]] using a structure that abstracts over the concrete representation of bound occurences of identifiers and patterns. The module [[GhcModule(compiler/typecheck/TcHsSyn.lhs)]] defines a number of helper function required by the type checker. Note that the type [[GhcModule(compiler/typecheck/TcRnTypes.lhs)]].`TcId` used to represent identifiers in some signatures during type checking is, in fact, nothing but a synonym for a [http://darcs.haskell.org/ghc/docs/comm/the-beast/vars.html plain Id] (TODO: Point at new commentary equivalent).

5

GHC defines the abstract syntax of Haskell programs in [[GhcModule(compiler/hsSyn/HsSyn.lhs)]] using a structure that abstracts over the concrete representation of bound occurences of identifiers and patterns. The module [[GhcModule(compiler/typecheck/TcHsSyn.lhs)]] defines a number of helper function required by the type checker. Note that the type [[GhcModule(compiler/typecheck/TcRnTypes.lhs)]].`TcId` used to represent identifiers in some signatures during type checking is, in fact, nothing but a synonym for a [wiki:Commentary/Compiler/EntityTypes#Typevariablesandtermvariables plain Id].

6

6

7

It is also noteworthy, that the representations of types changes during type checking from `HsType` to `TypeRep.Type`. The latter is a [http://darcs.haskell.org/ghc/docs/comm/the-beast/types.html hybrid type] (TODO: Point at new commentary equivalent) representation that is used to type Core, but still contains sufficient information to recover source types. In particular, the type checker maintains and compares types in their `Type` form.

7

It is also noteworthy, that the representations of types changes during type checking from `HsType` to `TypeRep.Type`. The latter is a [wiki:Commentary/Compiler/TypeType hybrid type] representation that is used to type Core, but still contains sufficient information to recover source types. In particular, the type checker maintains and compares types in their `Type` form.

The interface of the type checker (and [http://darcs.haskell.org/ghc/docs/comm/the-beast/renamer.html renamer] (TODO: Point at new commentary equivalent)) to the rest of the compiler is provided by [[GhcModule(compiler/typecheck/TcRnDriver.lhs)]]. Entire modules are processed by calling `tcRnModule` and GHCi uses `tcRnStmt`, `tcRnExpr`, and `tcRnType` to typecheck statements and expressions, and to kind check types, respectively. Moreover, `tcRnExtCore` is provided to typecheck external Core code. Moreover, `tcTopSrcDecls` is used by Template Haskell - more specifically by `TcSplice.tc_bracket` - to type check the contents of declaration brackets.

13

The interface of the type checker (and [wiki:Commentary/Compiler/Renamer renamer]) to the rest of the compiler is provided by [[GhcModule(compiler/typecheck/TcRnDriver.lhs)]]. Entire modules are processed by calling `tcRnModule` and GHCi uses `tcRnStmt`, `tcRnExpr`, and `tcRnType` to typecheck statements and expressions, and to kind check types, respectively. Moreover, `tcRnExtCore` is provided to typecheck external Core code. Moreover, `tcTopSrcDecls` is used by Template Haskell - more specifically by `TcSplice.tc_bracket` - to type check the contents of declaration brackets.

Expressions are type checked by [[GhcModule(compiler/typecheck/TcExpr)]].

63

63

64

Usage occurences of identifiers are processed by the function tcId whose main purpose is to [http://darcs.haskell.org/ghc/docs/comm/the-beast/typecheck.html#inst instantiate overloaded identifiers] (TODO: Point at new commentary equivalent). It essentially calls `TcInst.instOverloadedFun` once for each universally quantified set of type constraints. It should be noted that overloaded identifiers are replaced by new names that are first defined in the LIE (Local Instance Environment?) and later promoted into top-level bindings.

64

Usage occurences of identifiers are processed by the function tcId whose main purpose is to [#HandlingofDictionariesandMethodInstances instantiate overloaded identifiers]. It essentially calls `TcInst.instOverloadedFun` once for each universally quantified set of type constraints. It should be noted that overloaded identifiers are replaced by new names that are first defined in the LIE (Local Instance Environment?) and later promoted into top-level bindings.