-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 = GenRnNameSupply RealWorld
+
+type GenRnNameSupply s
+ = ( UniqSupply
+ , FiniteMap FAST_STRING (SSTRef s Int)
+ , FiniteMap (Module,OccName) Name
+ )
+ -- Ensures that one (m,n) pair gets one unique
+ -- The finite map on FAST_STRINGS is used to give a per-class unique to each
+ -- instance declaration; it's really a separate name supply.
+
+data RnEnv = RnEnv GlobalNameEnv FixityEnv
+emptyRnEnv = RnEnv emptyNameEnv emptyFixityEnv
+
+type GlobalNameEnv = FiniteMap RdrName (Name, HowInScope)
+emptyGlobalNameEnv = emptyFM
+
+data HowInScope -- Used for error messages only
+ = FromLocalDefn SrcLoc
+ | FromImportDecl Module SrcLoc
+
+type NameEnv = FiniteMap RdrName Name
+emptyNameEnv = emptyFM
+
+type FixityEnv = FiniteMap RdrName (Fixity, HowInScope)
+emptyFixityEnv = emptyFM
+ -- It's possible to have a different fixity for B.op than for op:
+ --
+ -- module A( op ) where module B where
+ -- import qualified B( op ) infixr 2 op
+ -- infixl 9 `op` op = ...
+ -- op a b = a `B.op` b
+
+data ExportEnv = ExportEnv Avails Fixities
+type Avails = [AvailInfo]
+type Fixities = [(OccName, 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)
+
+ UniqFM AvailInfo) -- Used to figure out all other export specifiers.
+ -- Maps a Name to the AvailInfo that contains it
+ -- NB: Contain bindings for class ops but
+ -- not constructors (see defn of availEntityNames)
+
+
+data GenAvailInfo name = NotAvailable
+ | 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, IfaceFlavour, [RdrAvailInfo])
+type VersionInfo name = [ImportVersion name]
+
+type ImportVersion name = (Module, IfaceFlavour, 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
+ [(OccName,Fixity)] -- Fixities
+ [(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
+ Module -- Name of this module
+ (FiniteMap Module (IfaceFlavour, -- Exports
+ Version,
+ Avails,
+ [(OccName,Fixity)]))
+ DeclsMap
+
+ 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.
+
+ [(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.
+
+ (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.
+
+ (FiniteMap Name RdrNameTyDecl)
+ -- 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.
+
+ [Module] -- Set of modules with "special" instance declarations
+ -- Excludes this module
+
+
+type DeclsMap = FiniteMap Name (Version, AvailInfo, RdrNameHsDecl)
+type IfaceInst = ((Module, RdrNameInstDecl), -- Instance decl
+ [Name]) -- "Gate" names. Slurp this instance decl when this
+ -- list 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 loc names_var errs_var occs_var
+ g_down = GDown himap hibmap iface_var
+
+ -- do the business
+ res <- sstToIO (do_rn rn_down g_down)