[project @ 2000-10-25 07:09:52 by simonpj]
[ghc-hetmet.git] / ghc / compiler / main / HscTypes.lhs
index ee3c9e2..99b07b8 100644 (file)
@@ -9,7 +9,8 @@ module HscTypes (
 
        ModDetails(..), ModIface(..), GlobalSymbolTable, 
        HomeSymbolTable, PackageSymbolTable,
-       HomeIfaceTable, PackageIfaceTable,
+       HomeIfaceTable, PackageIfaceTable, 
+       lookupTable, lookupTableByModName,
 
        IfaceDecls(..), 
 
@@ -19,8 +20,6 @@ module HscTypes (
 
        TypeEnv, extendTypeEnv, lookupTypeEnv, 
 
-       lookupFixityEnv,
-
        WhetherHasOrphans, ImportVersion, WhatsImported(..),
        PersistentRenamerState(..), IsBootInterface, Avails, DeclsMap,
        IfaceInsts, IfaceRules, GatedDecl,
@@ -31,6 +30,7 @@ module HscTypes (
        Deprecations(..), lookupDeprec,
 
        InstEnv, ClsInstEnv, DFunId,
+       PackageInstEnv, PackageRuleBase,
 
        GlobalRdrEnv, RdrAvailInfo,
 
@@ -50,7 +50,9 @@ import Name           ( Name, NameEnv, NamedThing,
 import NameSet         ( NameSet )
 import OccName         ( OccName )
 import Module          ( Module, ModuleName, ModuleEnv,
-                         lookupModuleEnv )
+                         lookupModuleEnv, lookupModuleEnvByName
+                       )
+import Rules           ( RuleBase )
 import VarSet          ( TyVarSet )
 import VarEnv          ( emptyVarEnv )
 import Id              ( Id )
@@ -60,18 +62,20 @@ import TyCon                ( TyCon )
 import BasicTypes      ( Version, initialVersion, Fixity )
 
 import HsSyn           ( DeprecTxt )
-import RdrHsSyn                ( RdrNameHsDecl )
-import RnHsSyn         ( RenamedTyClDecl, RenamedIfaceSig, RenamedRuleDecl, RenamedInstDecl )
+import RdrHsSyn                ( RdrNameHsDecl, RdrNameTyClDecl )
+import RnHsSyn         ( RenamedTyClDecl, RenamedRuleDecl, RenamedInstDecl )
 
 import CoreSyn         ( CoreRule )
 import Type            ( Type )
 
 import FiniteMap       ( FiniteMap, emptyFM, addToFM, lookupFM, foldFM )
 import Bag             ( Bag )
+import Maybes          ( seqMaybe )
 import UniqFM          ( UniqFM )
 import Outputable
 import SrcLoc          ( SrcLoc, isGoodSrcLoc )
 import Util            ( thenCmp )
+import UniqSupply      ( UniqSupply )
 \end{code}
 
 %************************************************************************
@@ -118,7 +122,10 @@ data ModIface
         mi_version  :: VersionInfo,            -- Module version number
         mi_orphan   :: WhetherHasOrphans,       -- Whether this module has orphans
 
-        mi_usages   :: [ImportVersion Name],   -- Usages; kept sorted
+        mi_usages   :: [ImportVersion Name],   -- Usages; kept sorted so that it's easy
+                                               -- to decide whether to write a new iface file
+                                               -- (changing usages doesn't affect the version of
+                                               --  this module)
 
         mi_exports  :: Avails,                 -- What it exports
                                                -- Kept sorted by (mod,occ),
@@ -133,7 +140,6 @@ data ModIface
      }
 
 data IfaceDecls = IfaceDecls { dcl_tycl  :: [RenamedTyClDecl], -- Sorted
-                              dcl_sigs  :: [RenamedIfaceSig],  -- Sorted
                               dcl_rules :: [RenamedRuleDecl],  -- Sorted
                               dcl_insts :: [RenamedInstDecl] } -- Unsorted
 
@@ -144,7 +150,7 @@ data ModDetails
        -- The next three fields are created by the typechecker
         md_types    :: TypeEnv,
         md_insts    :: [DFunId],       -- Dfun-ids for the instances in this module
-        md_rules    :: RuleEnv         -- Domain may include Ids from other modules
+        md_rules    :: [(Id,CoreRule)] -- Domain may include Ids from other modules
      }
 \end{code}
 
@@ -153,7 +159,7 @@ emptyModDetails :: ModDetails
 emptyModDetails
   = ModDetails { md_types = emptyTypeEnv,
                  md_insts = [],
-                 md_rules = emptyRuleEnv
+                 md_rules = []
     }
 
 emptyModIface :: Module -> ModIface
@@ -182,11 +188,17 @@ type GlobalSymbolTable  = SymbolTable     -- Domain = all modules
 Simple lookups in the symbol table.
 
 \begin{code}
-lookupFixityEnv :: IfaceTable -> Name -> Maybe Fixity
-lookupFixityEnv tbl name
-  = case lookupModuleEnv tbl (nameModule name) of
-       Nothing      -> Nothing
-       Just details -> lookupNameEnv (mi_fixities details) name
+lookupTable :: ModuleEnv a -> ModuleEnv a -> Name -> Maybe a
+-- We often have two Symbol- or IfaceTables, and want to do a lookup
+lookupTable ht pt name
+  = lookupModuleEnv ht mod `seqMaybe` lookupModuleEnv pt mod
+  where
+    mod = nameModule name
+
+lookupTableByModName :: ModuleEnv a -> ModuleEnv a -> ModuleName -> Maybe a
+-- We often have two Symbol- or IfaceTables, and want to do a lookup
+lookupTableByModName ht pt mod
+  = lookupModuleEnvByName ht mod `seqMaybe` lookupModuleEnvByName pt mod
 \end{code}
 
 
@@ -289,12 +301,9 @@ lookupDeprec iface name
        DeprecSome env -> lookupNameEnv env name
 
 type InstEnv    = UniqFM ClsInstEnv            -- Maps Class to instances for that class
+
 type ClsInstEnv = [(TyVarSet, [Type], DFunId)] -- The instances for a particular class
 type DFunId    = Id
-
-type RuleEnv    = NameEnv [CoreRule]
-
-emptyRuleEnv    = emptyVarEnv
 \end{code}
 
 
@@ -371,14 +380,18 @@ data PersistentCompilerState
    = PCS {
         pcs_PIT :: PackageIfaceTable,  -- Domain = non-home-package modules
                                        --   the mi_decls component is empty
+
         pcs_PST :: PackageSymbolTable, -- Domain = non-home-package modules
                                        --   except that the InstEnv components is empty
-       pcs_insts :: InstEnv,           -- The total InstEnv accumulated from all
+
+       pcs_insts :: PackageInstEnv,    -- The total InstEnv accumulated from all
                                        --   the non-home-package modules
-       pcs_rules :: RuleEnv,           -- Ditto RuleEnv
+
+       pcs_rules :: PackageRuleBase,   -- Ditto RuleEnv
 
         pcs_PRS :: PersistentRenamerState
      }
+
 \end{code}
 
 The @PersistentRenamerState@ persists across successive calls to the
@@ -401,11 +414,15 @@ It contains:
     interface files but not yet sucked in, renamed, and typechecked
 
 \begin{code}
+type PackageRuleBase = RuleBase
+type PackageInstEnv  = InstEnv
+
 data PersistentRenamerState
   = PRS { prsOrig  :: OrigNameEnv,
          prsDecls :: DeclsMap,
          prsInsts :: IfaceInsts,
-         prsRules :: IfaceRules
+         prsRules :: IfaceRules,
+         prsNS    :: UniqSupply
     }
 \end{code}
 
@@ -439,7 +456,7 @@ including the constructors of a type decl etc.  The Bool is True just
 for the 'main' Name.
 
 \begin{code}
-type DeclsMap = NameEnv (AvailInfo, Bool, (Module, RdrNameHsDecl))
+type DeclsMap = NameEnv (AvailInfo, Bool, (Module, RdrNameTyClDecl))
 
 type IfaceInsts = Bag GatedDecl
 type IfaceRules = Bag GatedDecl