From: simonpj Date: Wed, 4 Apr 2001 13:56:09 +0000 (+0000) Subject: [project @ 2001-04-04 13:56:09 by simonpj] X-Git-Tag: Approximately_9120_patches~2204 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=5a5359fc702e109cdbf8b6062cf150e3f46de4fb;p=ghc-hetmet.git [project @ 2001-04-04 13:56:09 by simonpj] Document orphan modules --- diff --git a/ghc/docs/users_guide/separate_compilation.sgml b/ghc/docs/users_guide/separate_compilation.sgml index b49a109..008e942 100644 --- a/ghc/docs/users_guide/separate_compilation.sgml +++ b/ghc/docs/users_guide/separate_compilation.sgml @@ -603,6 +603,74 @@ __export A TA; recursive modules properly without the manual construction of interface files, is (allegedly) in the works. + + + + Orphan modules and instance declarations + + Haskell specifies that when compiling module M, any instance +declaration in any module "below" M is visible. (Module A is "below" +M if A is imported directly by M, or if A is below a module that M imports directly.) +In principle, GHC must therefore read the interface files of every module below M, +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 +GHC has to visit that interface file anyway. Example: + + module A where + instance C a = D (T a) where ... + data T a = ... + + The instance declaration is only relevant if the type T is in use, and if +so, GHC will have visited A's interface file to find T's definition. + + The only problem comes when a module contains an instance declaration +and GHC has no other reason for visiting the module. Example: + + module Orphan where + instance C a = D (T a) where ... + class C a where ... + +Here, neither D nor T is declared in module Orphan. +We call such modules ``orphan modules'', +defined thus: + + An orphan module + orphan module + contains at least one orphan instance or at + 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 + to be in module A; it must be the declaration of D or T. + + + A rewrite rule in a module M is an orphan rule + orphan rule + if none of the variables, type constructors, + or classes that are free in the left hand side of the rule are declared in M. + + + + + 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. + + +You can identify an orphan module by looking in its interface file, M.hi. If there is a ``!'' on +the first line, GHC considers it an orphan module. + + +