-type RnM s r = RnMonad () s r
-type RnM_Fixes s r = RnMonad (UniqFM RenamedFixityDecl) s r
-
-type RnMonad x s r = RnDown x s -> SST s r
-
-data RnDown x s
- = RnDown
- x
- Module -- Module name
- SrcLoc -- Source location
- (RnMode s) -- Source or Iface
- RnEnv -- Renaming environment
- (MutableVar s UniqSupply) -- Unique supply
- (MutableVar s (Bag Warning, -- Warnings and Errors
- Bag Error))
-
-data RnMode s
- = RnSource (MutableVar s (Bag (RnName, RdrName)))
- -- Renaming source; returning occurences
-
- | RnIface BuiltinNames BuiltinKeys
- (MutableVar s ImplicitEnv)
- -- Renaming interface; creating and returning implicit names
- -- ImplicitEnv: one map for Values and one for TyCons/Classes.
-
-type ImplicitEnv = (FiniteMap RdrName RnName, FiniteMap RdrName RnName)
-emptyImplicitEnv :: ImplicitEnv
-emptyImplicitEnv = (emptyFM, emptyFM)
-
--- With a builtin polymorphic type for _runSST the type for
--- initTc should use RnM s r instead of RnM _RealWorld r
-
-initRn :: Bool -- True => Source; False => Iface
- -> Module
- -> RnEnv
- -> UniqSupply
- -> RnM _RealWorld r
- -> (r, Bag Error, Bag Warning)
-
-initRn source mod env us do_rn
- = _runSST (
- newMutVarSST emptyBag `thenSST` \ occ_var ->
- newMutVarSST emptyImplicitEnv `thenSST` \ imp_var ->
- newMutVarSST us `thenSST` \ us_var ->
- newMutVarSST (emptyBag,emptyBag) `thenSST` \ errs_var ->
- let
- mode = if source then
- RnSource occ_var
- else
- case builtinNameInfo of { (wiredin_fm, key_fm, _) ->
- RnIface wiredin_fm key_fm imp_var }
-
- rn_down = RnDown () mod mkUnknownSrcLoc mode env us_var errs_var
- in
- -- do the buisness
- do_rn rn_down `thenSST` \ res ->
+--------------------------------
+type RnNameSupply
+ = ( UniqSupply
+
+ , FiniteMap (OccName, OccName) Int
+ -- This is used as a name supply for dictionary functions
+ -- From the inst decl we derive a (class, tycon) pair;
+ -- this map then gives a unique int for each inst decl with that
+ -- (class, tycon) pair. (In Haskell 98 there can only be one,
+ -- but not so in more extended versions.)
+ --
+ -- We could just use one Int for all the instance decls, but this
+ -- way the uniques change less when you add an instance decl,
+ -- hence less recompilation
+
+ , FiniteMap (Module,OccName) Name
+ -- Ensures that one (module,occname) pair gets one unique
+ )
+
+
+--------------------------------
+data ExportEnv = ExportEnv Avails Fixities
+type Avails = [AvailInfo]
+type Fixities = [(Name, Fixity)]
+
+type ExportAvails = (FiniteMap Module Avails, -- Used to figure out "module M" export specifiers
+ -- Includes avails only from *unqualified* imports
+ -- (see 1.4 Report Section 5.1.1)
+
+ NameEnv AvailInfo) -- Used to figure out all other export specifiers.
+ -- Maps a Name to the AvailInfo that contains it
+
+
+data GenAvailInfo name = Avail name -- An ordinary identifier
+ | AvailTC name -- The name of the type or class
+ [name] -- The available pieces of type/class. NB: If the type or
+ -- class is itself to be in scope, it must be in this list.
+ -- Thus, typically: AvailTC Eq [Eq, ==, /=]
+type AvailInfo = GenAvailInfo Name
+type RdrAvailInfo = GenAvailInfo OccName
+\end{code}
+
+===================================================
+ INTERFACE FILE STUFF
+===================================================
+
+\begin{code}
+type ExportItem = (Module, [RdrAvailInfo])
+type VersionInfo name = [ImportVersion name]
+
+type ImportVersion name = (Module, Version, WhatsImported name)
+data WhatsImported name = Everything
+ | Specifically [LocalVersion name] -- List guaranteed non-empty
+
+ -- ("M", hif, ver, Everything) means there was a "module M" in
+ -- this module's export list, so we just have to go by M's version, "ver",
+ -- not the list of LocalVersions.
+
+
+type LocalVersion name = (name, Version)
+
+data ParsedIface
+ = ParsedIface
+ Module -- Module name
+ Version -- Module version number
+ [ImportVersion OccName] -- Usages
+ [ExportItem] -- Exports
+ [Module] -- Special instance modules
+ [(Version, RdrNameHsDecl)] -- Local definitions
+ [RdrNameInstDecl] -- Local instance declarations
+
+type InterfaceDetails = (VersionInfo Name, -- Version information for what this module imports
+ ExportEnv, -- What this module exports
+ [Module]) -- Instance modules
+
+type RdrNamePragma = () -- Fudge for now
+-------------------
+
+data Ifaces = Ifaces {
+ iMod :: Module, -- Name of the module being compiled
+
+ iModMap :: FiniteMap Module (IfaceFlavour, -- Exports
+ Version,
+ Avails),
+
+ iDecls :: DeclsMap, -- A single, global map of Names to decls
+
+ iFixes :: FixityEnv, -- A single, global map of Names to fixities
+
+ iSlurp :: NameSet, -- All the names (whether "big" or "small", whether wired-in or not,
+ -- whether locally defined or not) that have been slurped in so far.
+
+ iVSlurp :: [(Name,Version)], -- All the (a) non-wired-in (b) "big" (c) non-locally-defined names that
+ -- have been slurped in so far, with their versions.
+ -- This is used to generate the "usage" information for this module.
+ -- Subset of the previous field.
+
+ iDefInsts :: (Bag IfaceInst, NameSet),
+ -- The as-yet un-slurped instance decls; this bag is depleted when we
+ -- slurp an instance decl so that we don't slurp the same one twice.
+ -- Together with them is the set of tycons/classes that may allow
+ -- the instance decls in.
+
+ iDefData :: NameEnv (Module, RdrNameTyClDecl),
+ -- Deferred data type declarations; each has the following properties
+ -- * it's a data type decl
+ -- * its TyCon is needed
+ -- * the decl may or may not have been slurped, depending on whether any
+ -- of the constrs are needed.
+
+ iInstMods :: [Module] -- Set of modules with "special" instance declarations
+ -- Excludes this module
+ }
+
+
+type DeclsMap = NameEnv (Version, AvailInfo, RdrNameHsDecl, Bool)
+ -- A DeclsMap contains a binding for each Name in the declaration
+ -- including the constructors of a type decl etc.
+ -- The Bool is True just for the 'main' Name.
+
+type IfaceInst = ((Module, RdrNameInstDecl), -- Instance decl
+ NameSet) -- "Gate" names. Slurp this instance decl when this
+ -- set becomes empty. It's depleted whenever we
+ -- slurp another type or class decl.
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Main monad code}
+%* *
+%************************************************************************
+
+\begin{code}
+initRn :: Module -> UniqSupply -> SearchPath -> SrcLoc
+ -> RnMG r
+ -> IO (r, Bag ErrMsg, Bag WarnMsg)
+
+initRn mod us dirs loc do_rn = do
+ names_var <- sstToIO (newMutVarSST (us, emptyFM, builtins))
+ errs_var <- sstToIO (newMutVarSST (emptyBag,emptyBag))
+ iface_var <- sstToIO (newMutVarSST (emptyIfaces mod))
+ occs_var <- sstToIO (newMutVarSST initOccs)
+ (himap, hibmap) <- mkModuleHiMaps dirs
+ let
+ rn_down = RnDown { rn_loc = loc, rn_omit = \n -> False, rn_ns = names_var,
+ rn_errs = errs_var, rn_occs = occs_var,
+ rn_mod = mod }
+ g_down = GDown { rn_hi_map = himap, rn_hiboot_map = hibmap, rn_ifaces = iface_var }
+
+ -- do the business
+ res <- sstToIO (do_rn rn_down g_down)