X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=docs%2Fusers_guide%2Fseparate_compilation.xml;h=727a13365504b69faa7be866c8a15ad834116ecb;hb=5892af0e08fdb890b5a0b9a64346d9f7773a6ed8;hp=58726e56d23f6f176947362fea9cbef948743034;hpb=8215287c8c8d19dff36cd20ef71d56341a769d50;p=ghc-hetmet.git diff --git a/docs/users_guide/separate_compilation.xml b/docs/users_guide/separate_compilation.xml index 58726e5..727a133 100644 --- a/docs/users_guide/separate_compilation.xml +++ b/docs/users_guide/separate_compilation.xml @@ -299,7 +299,7 @@ dir. For example: -$ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch` +$ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `uname -m` The object files, Foo.o, @@ -374,6 +374,20 @@ $ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch` + + + dir + + + + The option is shorthand for + the combination + of , , + and . + + + + suffix @@ -565,9 +579,9 @@ $ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch` the same as the old one; this is friendly to make. When an interface does change, it is often enlightening to be informed. The - option will make GHC run - diff on the old and new - .hi files. + option will make GHC + report the differences between the old and + new .hi files. @@ -595,9 +609,9 @@ $ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch` - Where file is the name of + where file is the name of an interface file, dumps the contents of that interface in - a human-readable (ish) format. + a human-readable (ish) format. See . @@ -647,24 +661,24 @@ $ ghc -c parse/Foo.hs parse/Bar.hs gurgle/Bumble.hs -odir `arch` B, say) may conceivably not change B.hi one jot. So now… - GHC keeps a version number on each interface file, and on - each type signature within the interface file. It also keeps in - every interface file a list of the version numbers of everything - it used when it last compiled the file. If the source file's - modification date is earlier than the .o - file's date (i.e. the source hasn't changed since the file was - last compiled), and the recompilation checking is on, GHC will be - clever. It compares the version numbers on the things it needs - this time with the version numbers on the things it needed last - time (gleaned from the interface file of the module being - compiled); if they are all the same it stops compiling rather - early in the process saying “Compilation IS NOT - required”. What a beautiful sight! - - Patrick Sansom had a workshop paper about how all this is - done (though the details have changed quite a bit). Ask him if you want a - copy. + GHC calculates a fingerprint (in fact an MD5 hash) of each + interface file, and of each declaration within the interface + file. It also keeps in every interface file a list of the + fingerprints of everything it used when it last compiled the + file. If the source file's modification date is earlier than + the .o file's date (i.e. the source hasn't + changed since the file was last compiled), and the recompilation + checking is on, GHC will be clever. It compares the fingerprints + on the things it needs this time with the fingerprints + on the things it needed last time (gleaned from the + interface file of the module being compiled); if they are all + the same it stops compiling early in the process saying + “Compilation IS NOT required”. What a beautiful + sight! + + You can read + about how + all this works in the GHC commentary. @@ -702,8 +716,11 @@ module B where hi-boot files Here A imports B, but B imports A with a {-# SOURCE #-} pragma, which breaks the -circular dependency. For every module A.hs that is {-# SOURCE #-}-imported -in this way there must exist a souce file A.hs-boot. This file contains an abbreviated +circular dependency. Every loop in the module import graph must be broken by a {-# SOURCE #-} import; +or, equivalently, the module import graph must be acyclic if {-# SOURCE #-} imports are ignored. + +For every module A.hs that is {-# SOURCE #-}-imported +in this way there must exist a source file A.hs-boot. This file contains an abbreviated version of A.hs, thus: module A where @@ -1040,7 +1057,7 @@ ghc -M -optdep-f -optdep.depend ... - Print a full list of the module depenencies to stdout. + Print a full list of the module dependencies to stdout. (This is the standard verbosity flag, so the list will also be displayed with and ; @@ -1166,7 +1183,8 @@ just in case they contain an instance declaration that matters to M. This would be a disaster in practice, so GHC tries to be clever. In particular, if an instance declaration is in the same module as the definition -of any type or class mentioned in the head of the instance declaration, then +of any type or class mentioned in the head of the instance declaration +(the part after the “=>”; see ), then GHC has to visit that interface file anyway. Example: module A where @@ -1184,8 +1202,31 @@ and GHC has no other reason for visiting the module. Example: class C a where ... Here, neither D nor T is declared in module Orphan. -We call such modules “orphan modules”, -defined thus: +We call such modules “orphan modules”. +GHC identifies orphan modules, and visits the interface file of +every orphan module below the module being compiled. This is usually +wasted work, but there is no avoiding it. You should therefore do +your best to have as few orphan modules as possible. + + +Functional dependencies complicate matters. Suppose we have: + + module B where + instance E T Int where ... + data T = ... + +Is this an orphan module? Apparently not, because T +is declared in the same module. But suppose class E had a +functional dependency: + + module Lib where + class E x y | y -> x where ... + +Then in some importing module M, the constraint (E a Int) should be "improved" by setting +a = T, even though there is no explicit mention +of T in M. + +These considerations lead to the following definition of an orphan module: An orphan module orphan module @@ -1193,12 +1234,21 @@ defined thus: least one orphan rule. An instance declaration in a module M is an orphan instance if - orphan instance - none of the type constructors - or classes mentioned in the instance head (the part after the “=>”) are declared - in M. - - Only the instance head counts. In the example above, it is not good enough for C's declaration + orphan instance + + + The class of the instance declaration is not declared in M, and + + + Either the class has no functional dependencies, and none of the type constructors + in the instance head is declared in M; or there + is a functional dependency for which none of the type constructors mentioned + in the non-determined part of the instance head is defined in M. + + + + Only the instance head + counts. In the example above, it is not good enough for C's declaration to be in module A; it must be the declaration of D or T. @@ -1210,16 +1260,17 @@ defined thus: - GHC identifies orphan modules, and visits the interface file of -every orphan module below the module being compiled. This is usually -wasted work, but there is no avoiding it. You should therefore do -your best to have as few orphan modules as possible. +If you use the flag , GHC will warn you +if you are creating an orphan module. +Like any warning, you can switch the warning off with , +and +will make the compilation fail if the warning is issued. - - You can identify an orphan module by looking in its interface + +You can identify an orphan module by looking in its interface file, M.hi, using the -. If there is a “!” on the + mode. If there is a [orphan module] on the first line, GHC considers it an orphan module.