- let { all_binds = tc_val_binds `AndMonoBinds`
- inst_binds `AndMonoBinds`
- cls_dm_binds `AndMonoBinds`
- foe_binds } ;
-
- return (tcg_env, all_binds, src_rules, foe_decls)
- }}}}}}}}}
-\end{code}
-
-\begin{code}
-tcTyClDecls :: RecTcGblEnv
- -> [RenamedTyClDecl]
- -> TcM TcGblEnv
-
--- tcTyClDecls deals with
--- type and class decls (some source, some imported)
--- interface signatures (checked lazily)
---
--- It returns the TcGblEnv for this module, and side-effects the
--- persistent compiler state to reflect the things imported from
--- other modules
-
-tcTyClDecls unf_env tycl_decls
- -- (unf_env :: RecTcGblEnv) is used for type-checking interface pragmas
- -- which is done lazily [ie failure just drops the pragma
- -- without having any global-failure effect].
-
- = checkNoErrs $
- -- tcTyAndClassDecls recovers internally, but if anything gave rise to
- -- an error we'd better stop now, to avoid a cascade
-
- traceTc (text "TyCl1") `thenM_`
- tcTyAndClassDecls tycl_decls `thenM` \ tycl_things ->
- tcExtendGlobalEnv tycl_things $
-
- -- Interface type signatures
- -- We tie a knot so that the Ids read out of interfaces are in scope
- -- when we read their pragmas.
- -- What we rely on is that pragmas are typechecked lazily; if
- -- any type errors are found (ie there's an inconsistency)
- -- we silently discard the pragma
- traceTc (text "TyCl2") `thenM_`
- tcInterfaceSigs unf_env tycl_decls `thenM` \ sig_ids ->
- tcExtendGlobalValEnv sig_ids $
-
- getGblEnv -- Return the TcLocals environment
-\end{code}
-
-
-
-%************************************************************************
-%* *
- Load the old interface file for this module (unless
- we have it aleady), and check whether it is up to date
-
-%* *
-%************************************************************************
-
-\begin{code}
-checkOldIface :: HscEnv
- -> PersistentCompilerState
- -> Module
- -> FilePath -- Where the interface file is
- -> Bool -- Source unchanged
- -> Maybe ModIface -- Old interface from compilation manager, if any
- -> IO (PersistentCompilerState, Maybe (RecompileRequired, Maybe ModIface))
- -- Nothing <=> errors happened
-
-checkOldIface hsc_env pcs mod iface_path source_unchanged maybe_iface
- = do { showPass (hsc_dflags hsc_env)
- ("Checking old interface for " ++ moduleUserString mod) ;
-
- initTc hsc_env pcs mod
- (check_old_iface iface_path source_unchanged maybe_iface)
- }
-
-check_old_iface iface_path source_unchanged maybe_iface
- = -- CHECK WHETHER THE SOURCE HAS CHANGED
- ifM (not source_unchanged)
- (traceHiDiffs (nest 4 (text "Source file changed or recompilation check turned off")))
- `thenM_`
-
- -- If the source has changed and we're in interactive mode, avoid reading
- -- an interface; just return the one we might have been supplied with.
- getGhciMode `thenM` \ ghci_mode ->
- if (ghci_mode == Interactive) && not source_unchanged then
- returnM (outOfDate, maybe_iface)
- else
-
- case maybe_iface of
- Just old_iface -> -- Use the one we already have
- checkVersions source_unchanged old_iface `thenM` \ recomp ->
- returnM (recomp, Just old_iface)
-
- Nothing -- Try and read it from a file
- -> getModule `thenM` \ this_mod ->
- readIface this_mod iface_path False `thenM` \ read_result ->
- case read_result of
- Left err -> -- Old interface file not found, or garbled; give up
- traceHiDiffs (
- text "Cannot read old interface file:"
- $$ nest 4 (text (showException err))) `thenM_`
- returnM (outOfDate, Nothing)
-
- Right parsed_iface ->
- initRn (InterfaceMode this_mod)
- (loadOldIface parsed_iface) `thenM` \ m_iface ->
- checkVersions source_unchanged m_iface `thenM` \ recomp ->
- returnM (recomp, Just m_iface)
-\end{code}
-
-
-%************************************************************************
-%* *
- Type-check and rename supporting declarations
- This is used to deal with the free vars of a splice,
- or derived code: slurp in the necessary declarations,
- typecheck them, and add them to the EPS
-%* *
-%************************************************************************
-
-\begin{code}
-importSupportingDecls :: FreeVars -> TcM TcGblEnv
--- Completely deal with the supporting imports needed
--- by the specified free-var set
-importSupportingDecls fvs
- = do { traceRn (text "Import supporting decls for" <+> ppr (nameSetToList fvs)) ;
- decls <- slurpImpDecls fvs ;
- traceRn (text "...namely:" <+> vcat (map ppr decls)) ;
- typecheckIfaceDecls (mkGroup decls) }
-
-typecheckIfaceDecls :: HsGroup Name -> TcM TcGblEnv
- -- The decls are all interface-file declarations
- -- Usually they are all from other modules, but when we are reading
- -- this module's interface from a file, it's possible that some of
- -- them are for the module being compiled.
- -- That is why the tcExtendX functions need to do partitioning.
- --
- -- If all the decls are from other modules, the returned TcGblEnv
- -- will have an empty tc_genv, but its tc_inst_env and tc_ist
- -- caches may have been augmented.
-typecheckIfaceDecls (HsGroup { hs_tyclds = tycl_decls,
- hs_instds = inst_decls,
- hs_ruleds = rule_decls })
- = do { -- Typecheck the type, class, and interface-sig decls
- tcg_env <- fixM (\ unf_env -> tcTyClDecls unf_env tycl_decls) ;
- setGblEnv tcg_env $ do {
-
- -- Typecheck the instance decls, and rules
- -- Note that imported dictionary functions are already
- -- in scope from the preceding tcTyClDecls
- tcIfaceInstDecls inst_decls `thenM` \ dfuns ->
- tcExtendInstEnv dfuns $
- tcRules rule_decls `thenM` \ rules ->
- tcExtendRules rules $
-
- getGblEnv -- Return the environment
- }}