Go to the first, previous, next, last section, table of contents.
When GHC compiles a source module `A', it generates an object `A.o', and a
companion interface file `A.hi'. The interface file
contains information needed by the compiler when it compiles any module `B' that
imports `A', whether directly or indirectly. When compiling `B', GHC will
read `A.hi' to find the details that it needs to know about things defined in `A'.
Furthermore, when compiling module `C' which imports `B', GHC may decide that it
needs to know something about `A' -- for example, `B' might export a function
that involves a type defined in `A'. In this case, GHC will go and read `A.hi' even
though `C' does not explicitly import `A' at all.
The interface file may contain all sorts of things that aren't explicitly
exported from `A' by the programmer. For example, even though a data type is exported
abstractly, `A.hi' will contain the full data type definition. For small function
definitions, `A.hi' will contain the complete definition of the function. For
bigger functions, `A.hi' will contain strictness information about the function. And so on.
GHC puts much more information into `.hi' files when you use `-O'. Without `-O'
it puts in just the minimum; with `-O' it lobs in a whole pile of stuff.
`A.hi' should really be thought of as a compiler-readable version of `A.o'.
If you use a `.hi' file that wasn't generated by the same compilation run that
generates the `.o' file the compiler may assume all sorts of incorrect things about `A',
resulting in core dumps and other unpleasant happenings.
In the olden days, GHC compared the newly-generated `.hi' file with the previous version;
if they were identical, it left the old one alone and didn't change its modification date.
In consequence, importers of a module with an unchanged output `.hi' file were not recompiled.
This doesn't work any more. In our earlier example, module `C' does
not import module `A' directly, yet changes to `A.hi' should force a
recompilation of `C'. And some changes to `A' (changing the
definition of a function that appears in an inlining of a function
exported by `B', say) may conceivably not change `B.hi' one jot. So
now
Go to the first, previous, next, last section, table of contents.