-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 OrigName RnName, FiniteMap OrigName 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 String Int
+ -- This is used as a name supply for dictionary functions
+ -- From the inst decl we derive a string, usually by glomming together
+ -- the class and tycon name -- but it doesn't matter exactly how;
+ -- this map then gives a unique int for each inst decl with that
+ -- string. (In Haskell 98 there can only be one,
+ -- but not so in more extended versions; also class CC type T
+ -- and class C type TT might both give the string CCT
+ --
+ -- 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 (ModuleName, OccName) Name
+ -- Ensures that one (module,occname) pair gets one unique
+ , FiniteMap OccName Name
+ -- Ensures that one implicit parameter name gets one unique
+ )
+
+
+--------------------------------
+data ExportEnv = ExportEnv Avails Fixities [ModuleName]
+ -- The list of modules is the modules exported
+ -- with 'module M' in the export list
+
+type Avails = [AvailInfo]
+type Fixities = [(Name, Fixity)]
+
+type ExportAvails = (FiniteMap ModuleName 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}
+
+%===================================================
+\subsubsection{ INTERFACE FILE STUFF}
+%===================================================
+
+\begin{code}
+type ExportItem = (ModuleName, [RdrAvailInfo])
+type VersionInfo name = [ImportVersion name]
+
+type ImportVersion name = (ModuleName, Version, WhetherHasOrphans, WhatsImported name)
+
+type WhetherHasOrphans = Bool
+ -- An "orphan" is
+ -- * an instance decl in a module other than the defn module for
+ -- one of the tycons or classes in the instance head
+ -- * a transformation rule in a module other than the one defining
+ -- the function in the head of the rule.
+
+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 {
+ pi_mod :: Version, -- Module version number
+ pi_orphan :: WhetherHasOrphans, -- Whether this module has orphans
+ pi_usages :: [ImportVersion OccName], -- Usages
+ pi_exports :: [ExportItem], -- Exports
+ pi_decls :: [(Version, RdrNameHsDecl)], -- Local definitions
+ pi_insts :: [RdrNameInstDecl], -- Local instance declarations
+ pi_rules :: [RdrNameRuleDecl], -- Rules
+ pi_deprecs :: [(Maybe FAST_STRING, FAST_STRING)] -- Deprecations, the type is currently only a hack
+ }
+
+data InterfaceDetails
+ = InterfaceDetails WhetherHasOrphans
+ (VersionInfo Name) -- Version information for what this module imports
+ ExportEnv -- What modules this one depends on
+ [Deprecation Name]
+
+
+-- needed by Main to fish out the fixities assoc list.
+getIfaceFixities :: InterfaceDetails -> Fixities
+getIfaceFixities (InterfaceDetails _ _ (ExportEnv _ fs _) _) = fs
+
+
+type RdrNamePragma = () -- Fudge for now
+-------------------
+
+data Ifaces = Ifaces {
+ iImpModInfo :: ImportedModuleInfo,
+ -- Modules this one depends on: that is, the union
+ -- of the modules its *direct* imports depend on.
+ -- NB: The direct imports have .hi files that enumerate *all* the
+ -- dependencies (direct or not) of the imported module.
+
+ iDecls :: DeclsMap, -- A single, global map of Names to decls
+
+ iFixes :: FixityEnv, -- A single, global map of Names to fixities
+ -- See comments with RnIfaces.lookupFixity
+
+ 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.
+
+ iInsts :: Bag GatedDecl,
+ -- 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.
+ -- Each is 'gated' by the names that must be available before
+ -- this instance decl is needed.
+
+ iRules :: Bag GatedDecl
+ -- Ditto transformation rules
+ }
+
+type GatedDecl = (NameSet, (Module, RdrNameHsDecl))
+
+type ImportedModuleInfo
+ = FiniteMap ModuleName (Version, Bool, Maybe (Module, Bool, Avails))
+ -- Suppose the domain element is module 'A'
+ --
+ -- The first Bool is True if A contains
+ -- 'orphan' rules or instance decls
+
+ -- The second Bool is true if the interface file actually
+ -- read was an .hi-boot file
+
+ -- Nothing => A's interface not yet read, but this module has
+ -- imported a module, B, that itself depends on A
+ --
+ -- Just xx => A's interface has been read. The Module in
+ -- the Just has the correct Dll flag
+
+ -- This set is used to decide whether to look for
+ -- A.hi or A.hi-boot when importing A.f.
+ -- Basically, we look for A.hi if A is in the map, and A.hi-boot
+ -- otherwise
+
+type DeclsMap = NameEnv (Version, AvailInfo, Bool, (Module, RdrNameHsDecl))
+ -- 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.
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Main monad code}
+%* *
+%************************************************************************
+
+\begin{code}
+initRn :: ModuleName -> UniqSupply -> SearchPath -> SrcLoc
+ -> RnMG r
+ -> IO (r, Bag ErrMsg, Bag WarnMsg)
+
+initRn mod us dirs loc do_rn = do
+ himaps <- mkModuleHiMaps dirs
+ names_var <- newIORef (us, emptyFM, builtins, emptyFM)
+ errs_var <- newIORef (emptyBag,emptyBag)
+ iface_var <- newIORef emptyIfaces
+ let
+ rn_down = RnDown { rn_loc = loc, rn_ns = names_var,
+ rn_errs = errs_var,
+ rn_hi_maps = himaps,
+ rn_ifaces = iface_var,
+ rn_mod = mod }
+
+ -- do the business
+ res <- do_rn rn_down ()