7 #include "HsVersions.h"
9 import HsSyn ( MonoBinds(..) )
10 import HscTypes ( HscEnv(..), PersistentCompilerState(..),
11 emptyFixityEnv, emptyGlobalRdrEnv, TyThing,
12 ExternalPackageState(..), HomePackageTable,
13 ModDetails(..), HomeModInfo(..), Deprecations(..),
14 GlobalRdrEnv, LocalRdrEnv, NameCache, FixityEnv,
15 GhciMode, lookupType, unQualInScope )
17 import Module ( Module, moduleName, unitModuleEnv, foldModuleEnv )
18 import Name ( Name, isInternalName )
20 import NameEnv ( extendNameEnvList )
21 import InstEnv ( InstEnv, extendInstEnv )
22 import TysWiredIn ( integerTy, doubleTy )
24 import VarSet ( emptyVarSet )
25 import VarEnv ( TidyEnv, emptyTidyEnv )
26 import RdrName ( emptyRdrEnv )
27 import ErrUtils ( Message, Messages, emptyMessages, errorsFound,
28 addShortErrLocLine, addShortWarnLocLine, printErrorsAndWarnings )
29 import SrcLoc ( SrcLoc, noSrcLoc )
30 import NameEnv ( emptyNameEnv )
31 import Bag ( emptyBag )
33 import UniqSupply ( UniqSupply, mkSplitUniqSupply, uniqFromSupply, splitUniqSupply )
34 import Unique ( Unique )
35 import CmdLineOpts ( DynFlags, DynFlag(..), dopt, opt_PprStyle_Debug )
36 import BasicTypes ( FixitySig )
37 import Bag ( snocBag, unionBags )
38 import Panic ( showException )
40 import Maybe ( isJust )
42 import DATA_IOREF ( newIORef, readIORef )
43 import EXCEPTION ( Exception )
46 %************************************************************************
48 Standard combinators, but specialised for this monad
51 6%************************************************************************
54 mappM :: (a -> TcRn m b) -> [a] -> TcRn m [b]
55 mappM_ :: (a -> TcRn m b) -> [a] -> TcRn m ()
56 -- Funny names to avoid clash with Prelude
57 sequenceM :: [TcRn m a] -> TcRn m [a]
58 foldlM :: (a -> b -> TcRn m a) -> a -> [b] -> TcRn m a
59 mapAndUnzipM :: (a -> TcRn m (b,c)) -> [a] -> TcRn m ([b],[c])
60 mapAndUnzip3M :: (a -> TcRn m (b,c,d)) -> [a] -> TcRn m ([b],[c],[d])
61 checkM :: Bool -> TcRn m () -> TcRn m () -- Perform arg if bool is False
62 ifM :: Bool -> TcRn m () -> TcRn m () -- Perform arg if bool is True
64 mappM f [] = return []
65 mappM f (x:xs) = do { r <- f x; rs <- mappM f xs; return (r:rs) }
67 mappM_ f [] = return ()
68 mappM_ f (x:xs) = f x >> mappM_ f xs
70 sequenceM [] = return []
71 sequenceM (x:xs) = do { r <- x; rs <- sequenceM xs; return (r:rs) }
73 foldlM k z [] = return z
74 foldlM k z (x:xs) = do { r <- k z x; foldlM k r xs }
76 mapAndUnzipM f [] = return ([],[])
77 mapAndUnzipM f (x:xs) = do { (r,s) <- f x;
78 (rs,ss) <- mapAndUnzipM f xs;
81 mapAndUnzip3M f [] = return ([],[], [])
82 mapAndUnzip3M f (x:xs) = do { (r,s,t) <- f x;
83 (rs,ss,ts) <- mapAndUnzip3M f xs;
84 return (r:rs, s:ss, t:ts) }
86 checkM True err = return ()
87 checkM False err = err
89 ifM True do_it = do_it
90 ifM False do_it = return ()
94 %************************************************************************
98 %************************************************************************
101 initTc :: HscEnv -> PersistentCompilerState
104 -> IO (PersistentCompilerState, Maybe r)
105 -- Nothing => error thrown by the thing inside
106 -- (error messages should have been printed already)
108 initTc (HscEnv { hsc_mode = ghci_mode,
110 hsc_dflags = dflags })
112 = do { us <- mkSplitUniqSupply 'a' ;
113 us_var <- newIORef us ;
114 errs_var <- newIORef (emptyBag, emptyBag) ;
115 tvs_var <- newIORef emptyVarSet ;
116 usg_var <- newIORef emptyUsages ;
117 nc_var <- newIORef (pcs_nc pcs) ;
118 eps_var <- newIORef eps ;
121 env = Env { env_top = top_env,
124 env_loc = noSrcLoc } ;
127 top_mode = ghci_mode,
133 top_errs = errs_var } ;
137 tcg_usages = usg_var,
138 tcg_rdr_env = emptyGlobalRdrEnv,
139 tcg_fix_env = emptyFixityEnv,
140 tcg_default = defaultDefaultTys,
141 tcg_type_env = emptyNameEnv,
142 tcg_ist = mkImpTypeEnv eps hpt,
143 tcg_inst_env = mkImpInstEnv dflags eps hpt,
145 tcg_imports = init_imports,
146 tcg_binds = EmptyMonoBinds,
147 tcg_deprecs = NoDeprecs,
154 tcl_level = topStage,
155 tcl_env = emptyNameEnv,
156 tcl_tyvars = tvs_var,
157 tcl_lie = panic "initTc:LIE" } ;
158 -- LIE only valid inside a getLIE
161 -- OK, here's the business end!
162 maybe_res <- catch (do { res <- runTcRn env do_this ;
164 (\_ -> return Nothing) ;
166 -- Print any error messages
167 msgs <- readIORef errs_var ;
168 printErrorsAndWarnings msgs ;
170 -- Get final PCS and return
171 eps' <- readIORef eps_var ;
172 nc' <- readIORef nc_var ;
173 let { pcs' = PCS { pcs_EPS = eps', pcs_nc = nc' } ;
174 final_res | errorsFound dflags msgs = Nothing
175 | otherwise = maybe_res } ;
177 return (pcs', final_res)
182 init_imports = emptyImportAvails { imp_qual = unitModuleEnv mod emptyAvailEnv }
183 -- Initialise tcg_imports with an empty set of bindings for
184 -- this module, so that if we see 'module M' in the export
185 -- list, and there are no bindings in M, we don't bleat
186 -- "unknown module M".
188 defaultDefaultTys :: [Type]
189 defaultDefaultTys = [integerTy, doubleTy]
191 mkImpInstEnv :: DynFlags -> ExternalPackageState -> HomePackageTable -> InstEnv
192 mkImpInstEnv dflags eps hpt
193 = foldModuleEnv (add . md_insts . hm_details)
197 -- We shouldn't get instance conflict errors from
198 -- the package and home type envs
199 add dfuns inst_env = WARN( not (null errs), vcat (map snd errs) ) inst_env'
201 (inst_env', errs) = extendInstEnv dflags inst_env dfuns
203 -- mkImpTypeEnv makes the imported symbol table
204 mkImpTypeEnv :: ExternalPackageState -> HomePackageTable
205 -> Name -> Maybe TyThing
206 mkImpTypeEnv pcs hpt = lookup
209 lookup name | isInternalName name = Nothing
210 | otherwise = lookupType hpt pte name
214 %************************************************************************
218 %************************************************************************
221 getTopEnv :: TcRn m TopEnv
222 getTopEnv = do { env <- getEnv; return (env_top env) }
224 getGblEnv :: TcRn m TcGblEnv
225 getGblEnv = do { env <- getEnv; return (env_gbl env) }
227 updGblEnv :: (TcGblEnv -> TcGblEnv) -> TcRn m a -> TcRn m a
228 updGblEnv upd = updEnv (\ env@(Env { env_gbl = gbl }) ->
229 env { env_gbl = upd gbl })
231 setGblEnv :: TcGblEnv -> TcRn m a -> TcRn m a
232 setGblEnv gbl_env = updEnv (\ env -> env { env_gbl = gbl_env })
234 getLclEnv :: TcRn m m
235 getLclEnv = do { env <- getEnv; return (env_lcl env) }
237 updLclEnv :: (m -> m) -> TcRn m a -> TcRn m a
238 updLclEnv upd = updEnv (\ env@(Env { env_lcl = lcl }) ->
239 env { env_lcl = upd lcl })
241 setLclEnv :: m -> TcRn m a -> TcRn n a
242 setLclEnv lcl_env = updEnv (\ env -> env { env_lcl = lcl_env })
248 getDOpts :: TcRn m DynFlags
249 getDOpts = do { env <- getTopEnv; return (top_dflags env) }
251 doptM :: DynFlag -> TcRn m Bool
252 doptM flag = do { dflags <- getDOpts; return (dopt flag dflags) }
254 ifOptM :: DynFlag -> TcRn m () -> TcRn m () -- Do it flag is true
255 ifOptM flag thing_inside = do { b <- doptM flag;
256 if b then thing_inside else return () }
258 getGhciMode :: TcRn m GhciMode
259 getGhciMode = do { env <- getTopEnv; return (top_mode env) }
263 getSrcLocM :: TcRn m SrcLoc
264 -- Avoid clash with Name.getSrcLoc
265 getSrcLocM = do { env <- getEnv; return (env_loc env) }
267 addSrcLoc :: SrcLoc -> TcRn m a -> TcRn m a
268 addSrcLoc loc = updEnv (\env -> env { env_loc = loc })
272 getEps :: TcRn m ExternalPackageState
273 getEps = do { env <- getTopEnv; readMutVar (top_eps env) }
275 setEps :: ExternalPackageState -> TcRn m ()
276 setEps eps = do { env <- getTopEnv; writeMutVar (top_eps env) eps }
278 getHpt :: TcRn m HomePackageTable
279 getHpt = do { env <- getTopEnv; return (top_hpt env) }
281 getModule :: TcRn m Module
282 getModule = do { env <- getGblEnv; return (tcg_mod env) }
284 getGlobalRdrEnv :: TcRn m GlobalRdrEnv
285 getGlobalRdrEnv = do { env <- getGblEnv; return (tcg_rdr_env env) }
287 getImports :: TcRn m ImportAvails
288 getImports = do { env <- getGblEnv; return (tcg_imports env) }
290 getFixityEnv :: TcRn m FixityEnv
291 getFixityEnv = do { env <- getGblEnv; return (tcg_fix_env env) }
293 extendFixityEnv :: [(Name,FixitySig Name)] -> RnM a -> RnM a
294 extendFixityEnv new_bit
295 = updGblEnv (\env@(TcGblEnv { tcg_fix_env = old_fix_env }) ->
296 env {tcg_fix_env = extendNameEnvList old_fix_env new_bit})
298 getDefaultTys :: TcRn m [Type]
299 getDefaultTys = do { env <- getGblEnv; return (tcg_default env) }
303 getUsageVar :: TcRn m (TcRef EntityUsage)
304 getUsageVar = do { env <- getGblEnv; return (tcg_usages env) }
306 getUsages :: TcRn m EntityUsage
307 getUsages = do { usg_var <- getUsageVar; readMutVar usg_var }
309 updUsages :: (EntityUsage -> EntityUsage) -> TcRn m ()
310 updUsages upd = do { usg_var <- getUsageVar ;
311 usg <- readMutVar usg_var ;
312 writeMutVar usg_var (upd usg) }
316 %************************************************************************
320 %************************************************************************
323 getErrsVar :: TcRn m (TcRef Messages)
324 getErrsVar = do { env <- getTopEnv; return (top_errs env) }
326 setErrsVar :: TcRef Messages -> TcRn m a -> TcRn m a
327 setErrsVar v = updEnv (\ env@(Env { env_top = top_env }) ->
328 env { env_top = top_env { top_errs = v }})
330 addErr :: Message -> TcRn m ()
331 addErr msg = do { loc <- getSrcLocM ; addErrAt loc msg }
333 addErrAt :: SrcLoc -> Message -> TcRn m ()
335 = do { errs_var <- getErrsVar ;
336 rdr_env <- getGlobalRdrEnv ;
337 let { err = addShortErrLocLine loc (unQualInScope rdr_env) msg } ;
338 (warns, errs) <- readMutVar errs_var ;
339 writeMutVar errs_var (warns, errs `snocBag` err) }
341 addErrs :: [(SrcLoc,Message)] -> TcRn m ()
342 addErrs msgs = mappM_ add msgs
344 add (loc,msg) = addErrAt loc msg
346 addWarn :: Message -> TcRn m ()
348 = do { errs_var <- getErrsVar ;
350 rdr_env <- getGlobalRdrEnv ;
351 let { warn = addShortWarnLocLine loc (unQualInScope rdr_env) msg } ;
352 (warns, errs) <- readMutVar errs_var ;
353 writeMutVar errs_var (warns `snocBag` warn, errs) }
355 checkErr :: Bool -> Message -> TcRn m ()
356 -- Add the error if the bool is False
357 checkErr ok msg = checkM ok (addErr msg)
359 warnIf :: Bool -> Message -> TcRn m ()
360 warnIf True msg = addWarn msg
361 warnIf False msg = return ()
363 addMessages :: Messages -> TcRn m ()
364 addMessages (m_warns, m_errs)
365 = do { errs_var <- getErrsVar ;
366 (warns, errs) <- readMutVar errs_var ;
367 writeMutVar errs_var (warns `unionBags` m_warns,
368 errs `unionBags` m_errs) }
373 recoverM :: TcRn m r -- Recovery action; do this if the main one fails
374 -> TcRn m r -- Main action: do this first
376 recoverM recover thing
377 = do { mb_res <- try_m thing ;
380 Right res -> returnM res }
382 tryTc :: TcRn m a -> TcRn m (Messages, Maybe a)
383 -- (tryTc m) executes m, and returns
384 -- Just r, if m succeeds (returning r) and caused no errors
385 -- Nothing, if m fails, or caused errors
386 -- It also returns all the errors accumulated by m
387 -- (even in the Just case, there might be warnings)
389 -- It always succeeds (never raises an exception)
391 = do { errs_var <- newMutVar emptyMessages ;
393 mb_r <- try_m (setErrsVar errs_var m) ;
395 new_errs <- readMutVar errs_var ;
402 Right r | errorsFound dflags new_errs -> Nothing
403 | otherwise -> Just r)
406 try_m :: TcRn m r -> TcRn m (Either Exception r)
407 -- Does try_m, with a debug-trace on failure
409 = do { mb_r <- tryM thing ;
411 Left exn -> do { traceTc (exn_msg exn); return mb_r }
412 Right r -> return mb_r }
414 exn_msg exn = text "recoverM recovering from" <+> text (showException exn)
416 tryTcLIE :: TcM a -> TcM (Messages, Maybe a)
417 -- Just like tryTc, except that it ensures that the LIE
418 -- for the thing is propagated only if there are no errors
419 -- Hence it's restricted to the type-check monad
420 tryTcLIE thing_inside
421 = do { ((errs, mb_r), lie) <- getLIE (tryTc thing_inside) ;
422 ifM (isJust mb_r) (extendLIEs lie) ;
423 return (errs, mb_r) }
425 tryTcLIE_ :: TcM r -> TcM r -> TcM r
426 -- (tryTcLIE_ r m) tries m; if it succeeds it returns it,
427 -- otherwise it returns r. Any error messages added by m are discarded,
428 -- whether or not m succeeds.
429 tryTcLIE_ recover main
430 = do { (_msgs, mb_res) <- tryTcLIE main ;
432 Just res -> return res
435 checkNoErrs :: TcM r -> TcM r
436 -- (checkNoErrs m) succeeds iff m succeeds and generates no errors
437 -- If m fails then (checkNoErrsTc m) fails.
438 -- If m succeeds, it checks whether m generated any errors messages
439 -- (it might have recovered internally)
440 -- If so, it fails too.
441 -- Regardless, any errors generated by m are propagated to the enclosing context.
443 = do { (msgs, mb_res) <- tryTcLIE main ;
450 ifErrsM :: TcRn m r -> TcRn m r -> TcRn m r
451 -- ifErrsM bale_out main
452 -- does 'bale_out' if there are errors in errors collection
453 -- otherwise does 'main'
454 ifErrsM bale_out normal
455 = do { errs_var <- getErrsVar ;
456 msgs <- readMutVar errs_var ;
458 if errorsFound dflags msgs then
463 failIfErrsM :: TcRn m ()
464 -- Useful to avoid error cascades
465 failIfErrsM = ifErrsM failM (return ())
469 forkM :: SDoc -> TcM a -> TcM (Maybe a)
470 -- Run thing_inside in an interleaved thread. It gets a separate
473 -- but everything else is shared, so this is DANGEROUS.
475 -- It returns Nothing if the computation fails
477 -- It's used for lazily type-checking interface
478 -- signatures, which is pretty benign
480 forkM doc thing_inside
481 = do { us <- newUniqueSupply ;
483 do { us_var <- newMutVar us ;
484 (msgs, mb_res) <- tryTcLIE (setUsVar us_var thing_inside) ;
486 Just r -> return (Just r)
489 -- Bleat about errors in the forked thread, if -ddump-tc-trace is on
490 -- Otherwise we silently discard errors. Errors can legitimately
491 -- happen when compiling interface signatures (see tcInterfaceSigs)
492 ifOptM Opt_D_dump_tc_trace
493 (ioToTcRn (do { printErrs (hdr_doc defaultErrStyle) ;
494 printErrorsAndWarnings msgs })) ;
499 hdr_doc = text "forkM failed:" <+> doc
503 %************************************************************************
507 %************************************************************************
510 getUsVar :: TcRn m (TcRef UniqSupply)
511 getUsVar = do { env <- getTopEnv; return (top_us env) }
513 setUsVar :: TcRef UniqSupply -> TcRn m a -> TcRn m a
514 setUsVar v = updEnv (\ env@(Env { env_top = top_env }) ->
515 env { env_top = top_env { top_us = v }})
517 newUnique :: TcRn m Unique
518 newUnique = do { us <- newUniqueSupply ;
519 return (uniqFromSupply us) }
521 newUniqueSupply :: TcRn m UniqSupply
523 = do { u_var <- getUsVar ;
524 us <- readMutVar u_var ;
525 let { (us1, us2) = splitUniqSupply us } ;
526 writeMutVar u_var us1 ;
532 getNameCache :: TcRn m NameCache
533 getNameCache = do { TopEnv { top_nc = nc_var } <- getTopEnv;
536 setNameCache :: NameCache -> TcRn m ()
537 setNameCache nc = do { TopEnv { top_nc = nc_var } <- getTopEnv;
538 writeMutVar nc_var nc }
542 %************************************************************************
546 %************************************************************************
549 traceTc, traceRn :: SDoc -> TcRn a ()
550 traceRn = dumpOptTcRn Opt_D_dump_rn_trace
551 traceTc = dumpOptTcRn Opt_D_dump_tc_trace
552 traceSplice = dumpOptTcRn Opt_D_dump_splices
553 traceHiDiffs = dumpOptTcRn Opt_D_dump_hi_diffs
555 dumpOptTcRn :: DynFlag -> SDoc -> TcRn a ()
556 dumpOptTcRn flag doc = ifOptM flag (dumpTcRn doc)
558 dumpTcRn :: SDoc -> TcRn a ()
559 dumpTcRn doc = do { rdr_env <- getGlobalRdrEnv ;
560 ioToTcRn (printForUser stderr (unQualInScope rdr_env) doc) }
564 %************************************************************************
566 Context management and error message generation
569 %************************************************************************
572 setErrCtxtM, addErrCtxtM :: (TidyEnv -> TcM (TidyEnv, Message)) -> TcM a -> TcM a
573 setErrCtxtM msg = updCtxt (\ msgs -> [msg])
574 addErrCtxtM msg = updCtxt (\ msgs -> msg : msgs)
576 setErrCtxt, addErrCtxt :: Message -> TcM a -> TcM a
577 setErrCtxt msg = setErrCtxtM (\env -> returnM (env, msg))
578 addErrCtxt msg = addErrCtxtM (\env -> returnM (env, msg))
580 popErrCtxt :: TcM a -> TcM a
581 popErrCtxt = updCtxt (\ msgs -> case msgs of { [] -> []; (m:ms) -> ms })
583 getErrCtxt :: TcM ErrCtxt
584 getErrCtxt = do { env <- getLclEnv ; return (tcl_ctxt env) }
586 -- Helper function for the above
587 updCtxt :: (ErrCtxt -> ErrCtxt) -> TcM a -> TcM a
588 updCtxt upd = updLclEnv (\ env@(TcLclEnv { tcl_ctxt = ctxt }) ->
589 env { tcl_ctxt = upd ctxt })
591 getInstLoc :: InstOrigin -> TcM InstLoc
593 = do { loc <- getSrcLocM ; env <- getLclEnv ;
594 return (InstLoc origin loc (tcl_ctxt env)) }
596 addInstCtxt :: InstLoc -> TcM a -> TcM a
597 -- Add the SrcLoc and context from the first Inst in the list
598 -- (they all have similar locations)
599 addInstCtxt (InstLoc _ src_loc ctxt) thing_inside
600 = addSrcLoc src_loc (updCtxt (\ old_ctxt -> ctxt) thing_inside)
603 The addErrTc functions add an error message, but do not cause failure.
604 The 'M' variants pass a TidyEnv that has already been used to
605 tidy up the message; we then use it to tidy the context messages
608 addErrTc :: Message -> TcM ()
609 addErrTc err_msg = addErrTcM (emptyTidyEnv, err_msg)
611 addErrsTc :: [Message] -> TcM ()
612 addErrsTc err_msgs = mappM_ addErrTc err_msgs
614 addErrTcM :: (TidyEnv, Message) -> TcM ()
615 addErrTcM (tidy_env, err_msg)
616 = do { ctxt <- getErrCtxt ;
618 add_err_tcm tidy_env err_msg loc ctxt }
621 The failWith functions add an error message and cause failure
624 failWithTc :: Message -> TcM a -- Add an error message and fail
626 = addErrTc err_msg >> failM
628 failWithTcM :: (TidyEnv, Message) -> TcM a -- Add an error message and fail
629 failWithTcM local_and_msg
630 = addErrTcM local_and_msg >> failM
632 checkTc :: Bool -> Message -> TcM () -- Check that the boolean is true
633 checkTc True err = returnM ()
634 checkTc False err = failWithTc err
637 Warnings have no 'M' variant, nor failure
640 addWarnTc :: Message -> TcM ()
642 = do { ctxt <- getErrCtxt ;
643 ctxt_msgs <- do_ctxt emptyTidyEnv ctxt ;
644 addWarn (vcat (msg : ctxt_to_use ctxt_msgs)) }
646 warnTc :: Bool -> Message -> TcM ()
647 warnTc warn_if_true warn_msg
648 | warn_if_true = addWarnTc warn_msg
649 | otherwise = return ()
655 add_err_tcm tidy_env err_msg loc ctxt
656 = do { ctxt_msgs <- do_ctxt tidy_env ctxt ;
657 addErrAt loc (vcat (err_msg : ctxt_to_use ctxt_msgs)) }
661 do_ctxt tidy_env (c:cs)
662 = do { (tidy_env', m) <- c tidy_env ;
663 ms <- do_ctxt tidy_env' cs ;
666 ctxt_to_use ctxt | opt_PprStyle_Debug = ctxt
667 | otherwise = take 3 ctxt
670 %************************************************************************
672 Other stuff specific to type checker
674 %************************************************************************
677 getLIEVar :: TcM (TcRef LIE)
678 getLIEVar = do { env <- getLclEnv; return (tcl_lie env) }
680 setLIEVar :: TcRef LIE -> TcM a -> TcM a
681 setLIEVar lie_var = updLclEnv (\ env -> env { tcl_lie = lie_var })
683 getLIE :: TcM a -> TcM (a, [Inst])
684 -- (getLIE m) runs m, and returns the type constraints it generates
686 = do { lie_var <- newMutVar emptyLIE ;
687 res <- updLclEnv (\ env -> env { tcl_lie = lie_var })
689 lie <- readMutVar lie_var ;
690 return (res, lieToList lie) }
692 extendLIE :: Inst -> TcM ()
694 = do { lie_var <- getLIEVar ;
695 lie <- readMutVar lie_var ;
696 writeMutVar lie_var (inst `consLIE` lie) }
698 extendLIEs :: [Inst] -> TcM ()
702 = do { lie_var <- getLIEVar ;
703 lie <- readMutVar lie_var ;
704 writeMutVar lie_var (mkLIE insts `plusLIE` lie) }
709 getStage :: TcM Stage
710 getStage = do { env <- getLclEnv; return (tcl_level env) }
712 setStage :: Stage -> TcM a -> TcM a
713 setStage s = updLclEnv (\ env -> env { tcl_level = s })
715 setLclTypeEnv :: TcLclEnv -> TcM a -> TcM a
716 -- Set the local type envt, but do *not* disturb other fields,
717 -- notably the lie_var
718 setLclTypeEnv lcl_env thing_inside
719 = updLclEnv upd thing_inside
721 upd env = env { tcl_env = tcl_env lcl_env,
722 tcl_tyvars = tcl_tyvars lcl_env }
726 %************************************************************************
728 Stuff for the renamer's local env
730 %************************************************************************
733 initRn :: RnMode -> RnM a -> TcRn m a
734 initRn mode thing_inside
735 = do { env <- getGblEnv ;
736 let { lcl_env = RnLclEnv {
738 rn_lenv = emptyRdrEnv }} ;
739 setLclEnv lcl_env thing_inside }
743 getLocalRdrEnv :: RnM LocalRdrEnv
744 getLocalRdrEnv = do { env <- getLclEnv; return (rn_lenv env) }
746 setLocalRdrEnv :: LocalRdrEnv -> RnM a -> RnM a
747 setLocalRdrEnv rdr_env thing_inside
748 = updLclEnv (\env -> env {rn_lenv = rdr_env}) thing_inside
750 getModeRn :: RnM RnMode
751 getModeRn = do { env <- getLclEnv; return (rn_mode env) }