[project @ 2000-10-19 15:00:16 by sewardj]
[ghc-hetmet.git] / ghc / compiler / rename / RnMonad.lhs
index 10adbac..ddff54f 100644 (file)
@@ -51,19 +51,22 @@ import Name         ( Name, OccName, NamedThing(..), getSrcLoc,
                        )
 import Module          ( Module, ModuleName, WhereFrom, moduleName )
 import NameSet         
-import CmdLineOpts     ( DynFlags, dopt_D_dump_rn_trace )
-import SrcLoc          ( SrcLoc, mkGeneratedSrcLoc )
+import CmdLineOpts     ( DynFlags, DynFlag(..), dopt )
+import SrcLoc          ( SrcLoc, generatedSrcLoc )
 import Unique          ( Unique )
 import FiniteMap       ( FiniteMap, emptyFM, listToFM, plusFM )
 import Bag             ( Bag, mapBag, emptyBag, isEmptyBag, snocBag )
 import UniqSupply
 import Outputable
-import CmFind          ( Finder )
+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 )
+                         DeclsMap, IfaceInsts, IfaceRules, DeprecationEnv,
+                         HomeSymbolTable, PackageSymbolTable,
+                         PersistentCompilerState(..), GlobalRdrEnv )
 
 infixr 9 `thenRn`, `thenRn_`
 \end{code}
@@ -83,7 +86,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 ()
@@ -110,15 +113,17 @@ type RnMG r  = RnM ()    r                -- Getting global names etc
        -- Common part
 data RnDown
   = RnDown {
-       rn_mod     :: Module,                   -- This module
-       rn_loc     :: SrcLoc,                   -- Current locn
+       rn_mod     :: Module,           -- This module
+       rn_loc     :: SrcLoc,           -- Current locn
 
        rn_finder  :: Finder,
        rn_dflags  :: DynFlags,
        rn_hst     :: HomeSymbolTable,
 
        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
     }
 
@@ -158,7 +163,7 @@ type LocalFixityEnv = NameEnv RenamedFixitySig
        -- can report line-number info when there is a duplicate
        -- fixity declaration
 
-lookupLocalFixity :: FixityEnv -> Name -> Fixity
+lookupLocalFixity :: LocalFixityEnv -> Name -> Fixity
 lookupLocalFixity env name
   = case lookupNameEnv env name of 
        Just (FixitySig _ fix _) -> fix
@@ -250,8 +255,9 @@ data Ifaces = Ifaces {
                -- Subset of the previous field.
     }
 
-type ImportedModuleInfo = FiniteMap ModuleName (WhetherHasOrphans, IsBootInterface, IsLoaded)
-type IsLoaded = True
+type ImportedModuleInfo = FiniteMap ModuleName 
+                                   (WhetherHasOrphans, IsBootInterface, IsLoaded)
+type IsLoaded = Bool
 \end{code}
 
 
@@ -270,9 +276,10 @@ initRn :: DynFlags -> Finder -> HomeSymbolTable
 
 initRn dflags finder hst pcs mod loc do_rn
   = do 
-       let prs = pcsPRS pcs
+       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,
@@ -291,22 +298,22 @@ 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 }
-       let new_pcs = pcs { pcsPST = iPST new_ifaces, 
-                           pcsPRS = new_prs }
+       let new_pcs = pcs { pcs_PST = iPST new_ifaces, 
+                           pcs_PRS = new_prs }
        
        return (res, new_pcs, (warns, errs))
 
 
 initIfaces :: PersistentCompilerState -> Ifaces
-initIfaces (PCS { pcsPST = pst, psrPRS = prs })
+initIfaces (PCS { pcs_PST = pst, pcs_PRS = prs })
   = Ifaces { iPST   = pst,
             iDecls = prsDecls prs,
             iInsts = prsInsts prs,
@@ -321,7 +328,7 @@ initIfaces (PCS { pcsPST = pst, psrPRS = prs })
       }
 
 
-initRnMS :: GlobalRdrEnv -> FixityEnv -> RnMode -> RnMS r -> RnM d r
+initRnMS :: GlobalRdrEnv -> LocalFixityEnv -> RnMode -> RnMS r -> RnM d r
 initRnMS rn_env fixity_env mode thing_inside rn_down g_down
   = let
        s_down = SDown { rn_genv = rn_env, rn_lenv = emptyRdrEnv, 
@@ -357,12 +364,13 @@ 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 = mkGeneratedSrcLoc, rn_ns = names_var,
+                              rn_loc = generatedSrcLoc, rn_ns = names_var,
                               rn_errs = errs_var, 
                               rn_mod = mod, 
                               rn_ifaces = panic "rnameSourceCode: rn_ifaces"  -- Not required
@@ -511,9 +519,13 @@ 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}
 
 
@@ -548,21 +560,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}