+ -> RnMG t
+ -> IO (PersistentCompilerState, Bool, t)
+ -- True <=> found errors
+
+initRn dflags finder hit hst pcs mod do_rn
+ = do
+ let prs = pcs_PRS pcs
+ let pst = pcs_PST pcs
+ let ifaces = Ifaces { iPIT = pcs_PIT pcs,
+ iDecls = prsDecls prs,
+ iInsts = prsInsts prs,
+ iRules = prsRules prs,
+
+ iImpModInfo = emptyFM,
+ iSlurp = unitNameSet (mkUnboundName dummyRdrVarName),
+ -- Pretend that the dummy unbound name has already been
+ -- slurped. This is what's returned for an out-of-scope name,
+ -- and we don't want thereby to try to suck it in!
+ iVSlurp = []
+ }
+ let uniqs = prsNS prs
+
+ names_var <- newIORef (uniqs, origNames (prsOrig prs),
+ origIParam (prsOrig prs))
+ errs_var <- newIORef (emptyBag,emptyBag)
+ iface_var <- newIORef ifaces
+ let rn_down = RnDown { rn_mod = mod,
+ rn_loc = noSrcLoc,
+
+ rn_finder = finder,
+ rn_dflags = dflags,
+ rn_hit = hit,
+ rn_done = is_done hst pst,
+
+ rn_ns = names_var,
+ rn_errs = errs_var,
+ rn_ifaces = iface_var,
+ }
+
+ -- do the business
+ res <- do_rn rn_down ()
+
+ -- Grab state and record it
+ (warns, errs) <- readIORef errs_var
+ new_ifaces <- readIORef iface_var
+ (new_NS, 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,
+ prsNS = new_NS }
+ let new_pcs = pcs { pcs_PIT = iPIT new_ifaces,
+ pcs_PRS = new_prs }
+
+ -- Check for warnings
+ printErrorsAndWarnings (warns, errs) ;
+
+ return (new_pcs, not (isEmptyBag errs), res)
+
+is_done :: HomeSymbolTable -> PackageSymbolTable -> Name -> Bool
+-- Returns True iff the name is in either symbol table
+is_done hst pst n = maybeToBool (lookupTypeEnv pst n `seqMaybe` lookupTypeEnv hst n)
+
+initRnMS rn_env fixity_env mode thing_inside rn_down g_down
+ = let
+ s_down = SDown { rn_genv = rn_env, rn_lenv = emptyRdrEnv,
+ rn_fixenv = fixity_env, rn_mode = mode }
+ in
+ thing_inside rn_down s_down
+
+initIfaceRnMS :: Module -> RnMS r -> RnM d r
+initIfaceRnMS mod thing_inside
+ = initRnMS emptyRdrEnv emptyNameEnv InterfaceMode $
+ setModuleRn mod thing_inside
+
+\end{code}
+
+@renameSourceCode@ is used to rename stuff ``out-of-line'';
+that is, not as part of the main renamer.
+Sole examples: derived definitions,
+which are only generated in the type checker.
+
+The @NameSupply@ includes a @UniqueSupply@, so if you call it more than
+once you must either split it, or install a fresh unique supply.
+
+\begin{code}
+renameSourceCode :: DynFlags
+ -> Module
+ -> PersistentRenamerState
+ -> RnMS r
+ -> r
+
+renameSourceCode dflags mod prs m
+ = unsafePerformIO (
+ -- It's not really unsafe! When renaming source code we
+ -- 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, origNames (prsOrig prs),
+ origIParam (prsOrig prs)) >>= \ names_var ->
+ newIORef (emptyBag,emptyBag) >>= \ errs_var ->
+ let
+ rn_down = RnDown { rn_dflags = dflags,
+ rn_loc = generatedSrcLoc, rn_ns = names_var,
+ rn_errs = errs_var,
+ rn_mod = mod,
+ rn_done = bogus "rn_done", rn_hit = bogus "rn_hit",
+ rn_ifaces = bogus "rn_ifaces", rn_finder = bogus "rn_finder"
+ }
+ s_down = SDown { rn_mode = InterfaceMode,
+ -- So that we can refer to PrelBase.True etc
+ rn_genv = emptyRdrEnv, rn_lenv = emptyRdrEnv,
+ rn_fixenv = emptyNameEnv }