-\begin{code}
-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 ->
-
- -- grab errors and return
- readMutVarSST errs_var `thenSST` \ (warns,errs) ->
- returnSST (res, errs, warns)
- )
-
-{-# INLINE thenRn #-}
-{-# INLINE thenRn_ #-}
-{-# INLINE returnRn #-}
-{-# INLINE andRn #-}
-
-returnRn :: a -> RnMonad x s a
-thenRn :: RnMonad x s a -> (a -> RnMonad x s b) -> RnMonad x s b
-thenRn_ :: RnMonad x s a -> RnMonad x s b -> RnMonad x s b
-andRn :: (a -> a -> a) -> RnMonad x s a -> RnMonad x s a -> RnMonad x s a
-mapRn :: (a -> RnMonad x s b) -> [a] -> RnMonad x s [b]
-mapAndUnzipRn :: (a -> RnMonad x s (b,c)) -> [a] -> RnMonad x s ([b],[c])
-
-returnRn v down = returnSST v
-thenRn m k down = m down `thenSST` \ r -> k r down
-thenRn_ m k down = m down `thenSST_` k down
-
-andRn combiner m1 m2 down
- = m1 down `thenSST` \ res1 ->
- m2 down `thenSST` \ res2 ->
- returnSST (combiner res1 res2)
-
-mapRn f [] = returnRn []
-mapRn f (x:xs)
- = f x `thenRn` \ r ->
- mapRn f xs `thenRn` \ rs ->
- returnRn (r:rs)