|Version 6 (modified by ezyang, 2 years ago) (diff)|
An interface file supports separate compilation by recording the information gained by compiling M.hs in its interface file M.hi. Morally speaking, the interface file M.hi is part of the object file M.o; it's like a super symbol-table for M.o.
Interface files are kept in binary, GHC-specific format. The format of these files changes with each GHC release, but not with patch-level releases. The contents of the interface file is, however, completely independent of the back end you are using (-fviaC, -fasm, -fcmm etc).
Although interface files are kept in binary format, you can print them in human-readable form using the command:
ghc --show-iface M.hi
This textual format is not particularly designed for machine parsing. Doing so might be possible, but if you want to read GHC interface files you are almost certainly better off using the GHC API to do so.
Here are some of the things stored in an interface file M.hi
- The version of GHC used to compile the module, as well as the compilation way and other knick-knacks
- A list of what M exports.
- The types of exported functions, definition of exported types, and so on.
- Version information, used to drive the recompilation checker.
- The strictness, arity, and unfolding of exported functions. This is crucial for cross-module optimisation; but it is only included when you compile with -O.
The contents of an interface file is the result of serialising the IfaceSyn family of data types. The data types are in compiler/iface/IfaceSyn.lhs and compiler/iface/IfaceType.lhs; the binary serialisation code is in compiler/iface/BinIface.hs. The definition of a module interface is the ModIface data type in compiler/main/HscTypes.lhs.
Details of some of the types involved in GHC's representation of Modules and Interface files can be found here.