[project @ 2000-10-20 15:38:42 by sewardj]
[ghc-hetmet.git] / ghc / compiler / rename / RnMonad.lhs
index 5ef1a72..8f5270d 100644 (file)
@@ -51,7 +51,7 @@ import Name           ( Name, OccName, NamedThing(..), getSrcLoc,
                        )
 import Module          ( Module, ModuleName, WhereFrom, moduleName )
 import NameSet         
-import CmdLineOpts     ( DynFlags, dopt_D_dump_rn_trace )
+import CmdLineOpts     ( DynFlags, DynFlag(..), dopt )
 import SrcLoc          ( SrcLoc, generatedSrcLoc )
 import Unique          ( Unique )
 import FiniteMap       ( FiniteMap, emptyFM, listToFM, plusFM )
@@ -60,12 +60,14 @@ import UniqSupply
 import Outputable
 import Finder          ( Finder )
 import PrelNames       ( mkUnboundName )
-import HscTypes                ( GlobalSymbolTable, OrigNameEnv, AvailEnv, 
+import HscTypes                ( GlobalSymbolTable, AvailEnv, 
+                         OrigNameEnv(..), OrigNameNameEnv, OrigNameIParamEnv,
                          WhetherHasOrphans, ImportVersion, ExportItem,
                          PersistentRenamerState(..), IsBootInterface, Avails,
                          DeclsMap, IfaceInsts, IfaceRules, DeprecationEnv,
                          HomeSymbolTable, PackageSymbolTable,
-                         PersistentCompilerState(..), GlobalRdrEnv )
+                         PersistentCompilerState(..), GlobalRdrEnv,
+                         HomeIfaceTable, PackageIfaceTable )
 
 infixr 9 `thenRn`, `thenRn_`
 \end{code}
@@ -85,7 +87,7 @@ ioToRnM io rn_down g_down = (io >>= \ ok -> return (Right ok))
            
 traceRn :: SDoc -> RnM d ()
 traceRn msg
-   = doptsRn dopt_D_dump_rn_trace `thenRn` \b ->
+   = doptRn Opt_D_dump_rn_trace `thenRn` \b ->
      if b then putDocRn msg else returnRn ()
 
 putDocRn :: SDoc -> RnM d ()
@@ -117,10 +119,13 @@ data RnDown
 
        rn_finder  :: Finder,
        rn_dflags  :: DynFlags,
-       rn_hst     :: HomeSymbolTable,
+       rn_hit     :: HomeIfaceTable,
+       rn_done    :: Name -> Bool,   -- available before compiling this module?
 
        rn_errs    :: IORef (Bag WarnMsg, Bag ErrMsg),
-       rn_ns      :: IORef (UniqSupply, OrigNameEnv),
+
+       -- The second and third components are a flattened-out OrigNameEnv
+       rn_ns      :: IORef (UniqSupply, OrigNameNameEnv, OrigNameIParamEnv),
        rn_ifaces  :: IORef Ifaces
     }
 
@@ -191,7 +196,8 @@ data ParsedIface
       pi_exports   :: [ExportItem],                    -- Exports
       pi_insts    :: [RdrNameInstDecl],                -- Local instance declarations
       pi_decls    :: [(Version, RdrNameHsDecl)],       -- Local definitions
-      pi_fixity           :: (Version, [RdrNameFixitySig]),    -- Local fixity declarations, with their version
+      pi_fixity           :: (Version, [RdrNameFixitySig]),    -- Local fixity declarations,
+                                                       --   with their version
       pi_rules    :: (Version, [RdrNameRuleDecl]),     -- Rules, with their version
       pi_deprecs   :: [RdrNameDeprecation]             -- Deprecations
     }
@@ -206,18 +212,18 @@ data ParsedIface
 \begin{code}
 data Ifaces = Ifaces {
     -- PERSISTENT FIELDS
-       iPST :: PackageSymbolTable,     
-               -- The ModuleDetails for modules in other packages
+       iPIT :: PackageIfaceTable,
+               -- The ModuleIFaces for modules in other packages
                -- whose interfaces we have opened
-               -- The contents of those interface files may be mostly
-               -- in the iDecls, iInsts, iRules (below), but what *will*
-               -- be in the PackageSymbolTable is:
+               -- The declarations in these interface files are held in
+               -- iDecls, iInsts, iRules (below), not in the mi_decls fields
+               -- of the iPIT.  What _is_ in the iPIT is:
                --      * The Module 
                --      * Version info
                --      * Its exports
                --      * Fixities
                --      * Deprecations
-               -- This field is initialised from the compiler's persistent
+               -- The iPIT field is initialised from the compiler's persistent
                -- package symbol table, and the renamer incrementally adds
                -- to it.
 
@@ -265,17 +271,21 @@ type IsLoaded = Bool
 %************************************************************************
 
 \begin{code}
-initRn :: DynFlags -> Finder -> HomeSymbolTable
+initRn :: DynFlags 
+       -> Finder 
+       -> HomeIfaceTable
        -> PersistentCompilerState
-       -> Module -> SrcLoc
+       -> Module 
+       -> SrcLoc
        -> RnMG t
        -> IO (t, PersistentCompilerState, (Bag WarnMsg, Bag ErrMsg))
 
-initRn dflags finder hst pcs mod loc do_rn
+initRn dflags finder hit pcs mod loc do_rn
   = do 
        let prs = pcs_PRS pcs
        uniqs     <- mkSplitUniqSupply 'r'
-       names_var <- newIORef (uniqs, prsOrig prs)
+       names_var <- newIORef (uniqs, origNames (prsOrig prs), 
+                                     origIParam (prsOrig prs))
        errs_var  <- newIORef (emptyBag,emptyBag)
        iface_var <- newIORef (initIfaces pcs)
        let rn_down = RnDown { rn_mod = mod,
@@ -283,7 +293,7 @@ initRn dflags finder hst pcs mod loc do_rn
        
                               rn_finder = finder,
                               rn_dflags = dflags,
-                              rn_hst    = hst,
+                              rn_hit    = hit,
                                             
                               rn_ns     = names_var, 
                               rn_errs   = errs_var, 
@@ -294,11 +304,11 @@ initRn dflags finder hst pcs mod loc do_rn
        res <- do_rn rn_down ()
        
        -- Grab state and record it
-       (warns, errs) <- readIORef errs_var
-       new_ifaces    <- readIORef iface_var
-       (_, new_orig) <- readIORef names_var
-
-       let new_prs = prs { prsOrig = new_orig, 
+       (warns, errs)              <- readIORef errs_var
+       new_ifaces                 <- readIORef iface_var
+       (_, new_origN, new_origIP) <- readIORef names_var
+       let new_orig = Orig { origNames = new_origN, origIParam = new_origIP }
+       let new_prs = prs { prsOrig = new_orig,
                            prsDecls = iDecls new_ifaces,
                            prsInsts = iInsts new_ifaces,
                            prsRules = iRules new_ifaces }
@@ -360,9 +370,10 @@ renameSourceCode dflags mod prs m
        -- only do any I/O if we need to read in a fixity declaration;
        -- and that doesn't happen in pragmas etc
 
-        mkSplitUniqSupply 'r'                  >>= \ new_us ->
-       newIORef (new_us, prsOrig prs)          >>= \ names_var ->
-       newIORef (emptyBag,emptyBag)            >>= \ errs_var ->
+        mkSplitUniqSupply 'r'                          >>= \ new_us ->
+       newIORef (new_us, origNames (prsOrig prs), 
+                         origIParam (prsOrig prs))     >>= \ names_var ->
+       newIORef (emptyBag,emptyBag)                    >>= \ errs_var ->
        let
            rn_down = RnDown { rn_dflags = dflags,
                               rn_loc = generatedSrcLoc, rn_ns = names_var,
@@ -514,14 +525,18 @@ checkErrsRn (RnDown {rn_errs = errs_var}) l_down
   = readIORef  errs_var                                        >>=  \ (warns,errs) ->
     return (isEmptyBag errs)
 
-doptsRn :: (DynFlags -> Bool) -> RnM d Bool
-doptsRn dopt (RnDown { rn_dflags = dflags}) l_down
-   = return (dopt dflags)
+doptRn :: DynFlag -> RnM d Bool
+doptRn dflag (RnDown { rn_dflags = dflags}) l_down
+   = return (dopt dflag dflags)
+
+getDOptsRn :: RnM d DynFlags
+getDOptsRn (RnDown { rn_dflags = dflags}) l_down
+   = return dflags
 \end{code}
 
 
 %================
-\subsubsection{  Source location}
+\subsubsection{Source location}
 %=====================
 
 \begin{code}
@@ -542,8 +557,8 @@ getSrcLocRn down l_down
 getFinderRn :: RnM d Finder
 getFinderRn down l_down = return (rn_finder down)
 
-getHomeSymbolTableRn :: RnM d HomeSymbolTable
-getHomeSymbolTableRn down l_down = return (rn_hst down)
+getHomeIfaceTableRn :: RnM d HomeIfaceTable
+getHomeIfaceTableRn down l_down = return (rn_hit down)
 \end{code}
 
 %================
@@ -551,21 +566,21 @@ getHomeSymbolTableRn down l_down = return (rn_hst down)
 %=====================
 
 \begin{code}
-getNameSupplyRn :: RnM d (UniqSupply, OrigNameEnv)
+getNameSupplyRn :: RnM d (UniqSupply, OrigNameNameEnv, OrigNameIParamEnv)
 getNameSupplyRn rn_down l_down
   = readIORef (rn_ns rn_down)
 
-setNameSupplyRn :: (UniqSupply, OrigNameEnv) -> RnM d ()
+setNameSupplyRn :: (UniqSupply, OrigNameNameEnv, OrigNameIParamEnv) -> RnM d ()
 setNameSupplyRn names' (RnDown {rn_ns = names_var}) l_down
   = writeIORef names_var names'
 
 getUniqRn :: RnM d Unique
 getUniqRn (RnDown {rn_ns = names_var}) l_down
- = readIORef names_var >>= \ (us, {-cache,-} ipcache) ->
+ = readIORef names_var >>= \ (us, cache, ipcache) ->
    let
      (us1,us') = splitUniqSupply us
    in
-   writeIORef names_var (us', {-cache,-} ipcache)  >>
+   writeIORef names_var (us', cache, ipcache)  >>
    return (uniqFromSupply us1)
 \end{code}