#include "HsVersions.h"
import CmdLineOpts ( DynFlag(..), DynFlags, opt_PprStyle_Debug )
-import HsSyn ( HsModule(..), HsBinds(..), MonoBinds(..), HsDecl(..) )
+import HsSyn ( HsBinds(..), MonoBinds(..), HsDecl(..) )
import HsTypes ( toHsType )
-import RnHsSyn ( RenamedHsModule, RenamedHsDecl )
+import RnHsSyn ( RenamedHsDecl )
import TcHsSyn ( TypecheckedMonoBinds,
TypecheckedForeignDecl, TypecheckedRuleDecl,
zonkTopBinds, zonkForeignExports, zonkRules
)
import TcMonad
-import Inst ( emptyLIE, plusLIE )
+import Inst ( plusLIE )
import TcBinds ( tcTopBinds )
import TcClassDcl ( tcClassDecls2, mkImplicitClassBinds )
import TcDefaults ( tcDefaults )
import TcForeign ( tcForeignImports, tcForeignExports )
import TcIfaceSig ( tcInterfaceSigs )
import TcInstDcls ( tcInstDecls1, tcInstDecls2 )
-import TcInstUtil ( InstInfo(..) )
+import InstEnv ( InstInfo(..) )
import TcSimplify ( tcSimplifyTop )
import TcTyClsDecls ( tcTyAndClassDecls )
import TcTyDecls ( mkImplicitDataBinds )
import ErrUtils ( printErrorsAndWarnings, dumpIfSet_dyn )
import Id ( idType, idName, idUnfolding )
import Module ( Module, moduleName, plusModuleEnv )
-import Name ( nameOccName, isLocallyDefined, isGlobalName,
- toRdrName, nameEnvElts, emptyNameEnv
+import Name ( Name, nameOccName, isLocallyDefined, isGlobalName,
+ toRdrName, nameEnvElts, emptyNameEnv, lookupNameEnv
)
-import TyCon ( TyCon, isDataTyCon, tyConName, tyConGenInfo )
+import TyCon ( tyConGenInfo, isClassTyCon )
import OccName ( isSysOcc )
-import TyCon ( TyCon, isClassTyCon )
-import Class ( Class )
import PrelNames ( mAIN_Name, mainName )
-import UniqSupply ( UniqSupply )
-import Maybes ( maybeToBool )
+import Maybes ( thenMaybe )
import Util
-import BasicTypes ( EP(..) )
-import Bag ( Bag, isEmptyBag )
+import BasicTypes ( EP(..), Fixity )
+import Bag ( isEmptyBag )
import Outputable
-import HscTypes ( PersistentCompilerState(..), HomeSymbolTable,
- PackageSymbolTable, DFunId,
- TypeEnv, extendTypeEnv,
+import HscTypes ( PersistentCompilerState(..), HomeSymbolTable, HomeIfaceTable,
+ PackageSymbolTable, PackageIfaceTable, DFunId, ModIface(..),
+ TypeEnv, extendTypeEnv, lookupTable,
TyThing(..), groupTyThings )
import FiniteMap ( FiniteMap, delFromFM, lookupWithDefaultFM )
\end{code}
= TcResults {
tc_pcs :: PersistentCompilerState, -- Augmented with imported information,
-- (but not stuff from this module)
- tc_env :: TypeEnv, -- The TypeEnv just for the stuff from this module
- tc_insts :: [DFunId], -- Instances, just for this module
- tc_binds :: TypecheckedMonoBinds,
+
+ -- All these fields have info *just for this module*
+ tc_env :: TypeEnv, -- The top level TypeEnv
+ tc_insts :: [DFunId], -- Instances
+ tc_binds :: TypecheckedMonoBinds, -- Bindings
tc_fords :: [TypecheckedForeignDecl], -- Foreign import & exports.
tc_rules :: [TypecheckedRuleDecl] -- Transformation rules
}
:: DynFlags
-> Module
-> PersistentCompilerState
- -> HomeSymbolTable
- -> RenamedHsModule
- -> IO (Maybe (TcEnv, TcResults))
-
-typecheckModule dflags this_mod pcs hst (HsModule mod_name _ _ _ decls _ src_loc)
- = do env <- initTcEnv global_symbol_table
- (maybe_result, (errs,warns)) <- initTc dflags env src_loc tc_module
- printErrorsAndWarnings (errs,warns)
- printTcDump dflags maybe_result
- if isEmptyBag errs then
- return Nothing
- else
- return maybe_result
+ -> HomeSymbolTable -> HomeIfaceTable
+ -> [RenamedHsDecl]
+ -> IO (Maybe TcResults)
+
+typecheckModule dflags this_mod pcs hst hit decls
+ = do env <- initTcEnv global_symbol_table
+
+ (maybe_result, (errs,warns)) <- initTc dflags env tc_module
+
+ let { maybe_tc_result :: Maybe TcResults ;
+ maybe_tc_result = case maybe_result of
+ Nothing -> Nothing
+ Just (_,r) -> Just r }
+
+ printErrorsAndWarnings (errs,warns)
+ printTcDump dflags maybe_tc_result
+
+ if isEmptyBag errs then
+ return Nothing
+ else
+ return maybe_tc_result
where
global_symbol_table = pcs_PST pcs `plusModuleEnv` hst
- tc_module = fixTc (\ ~(unf_env ,_) -> tcModule pcs hst this_mod decls unf_env)
+ tc_module :: TcM (TcEnv, TcResults)
+ tc_module = fixTc (\ ~(unf_env ,_) -> tcModule pcs hst get_fixity this_mod decls unf_env)
+
+ pit = pcs_PIT pcs
+
+ get_fixity :: Name -> Maybe Fixity
+ get_fixity nm = lookupTable hit pit nm `thenMaybe` \ iface ->
+ lookupNameEnv (mi_fixities iface) nm
\end{code}
The internal monster:
\begin{code}
tcModule :: PersistentCompilerState
-> HomeSymbolTable
+ -> (Name -> Maybe Fixity)
-> Module
-> [RenamedHsDecl]
-> TcEnv -- The knot-tied environment
-- unf_env is also used to get the pragama info
-- for imported dfuns and default methods
-tcModule pcs hst this_mod decls unf_env
+tcModule pcs hst get_fixity this_mod decls unf_env
= -- Type-check the type and class decls
tcTyAndClassDecls unf_env decls `thenTc` \ env ->
tcSetEnv env $
let
classes = tcEnvClasses env
tycons = tcEnvTyCons env -- INCLUDES tycons derived from classes
- local_classes = filter isLocallyDefined classes
local_tycons = [ tc | tc <- tycons,
isLocallyDefined tc,
not (isClassTyCon tc)
in
-- Typecheck the instance decls, includes deriving
- tcInstDecls1 pcs hst unf_env this_mod
- local_tycons decls `thenTc` \ (pcs_with_insts, inst_env, inst_info, deriv_binds) ->
+ tcInstDecls1 (pcs_insts pcs) (pcs_PRS pcs)
+ hst unf_env get_fixity this_mod
+ local_tycons decls `thenTc` \ (new_pcs_insts, inst_env, local_inst_info, deriv_binds) ->
tcSetInstEnv inst_env $
-- Default declarations
-- Second pass over class and instance declarations,
-- to compile the bindings themselves.
- tcInstDecls2 inst_info `thenNF_Tc` \ (lie_instdecls, inst_binds) ->
+ tcInstDecls2 local_inst_info `thenNF_Tc` \ (lie_instdecls, inst_binds) ->
tcClassDecls2 decls `thenNF_Tc` \ (lie_clasdecls, cls_dm_binds) ->
- tcRules decls `thenNF_Tc` \ (lie_rules, rules) ->
+ tcRules (pcs_rules pcs) decls `thenNF_Tc` \ (new_pcs_rules, lie_rules, local_rules) ->
-- Deal with constant or ambiguous InstIds. How could
-- there be ambiguous ones? They can only arise if a
tcSetEnv final_env $
-- zonkTopBinds puts all the top-level Ids into the tcGEnv
zonkForeignExports foe_decls `thenNF_Tc` \ foe_decls' ->
- zonkRules rules `thenNF_Tc` \ rules' ->
+ zonkRules local_rules `thenNF_Tc` \ local_rules' ->
let groups :: FiniteMap Module TypeEnv
new_pst = extendTypeEnv (pcs_PST pcs) (delFromFM groups this_mod)
final_pcs :: PersistentCompilerState
- final_pcs = pcs_with_insts {pcs_PST = new_pst}
+ final_pcs = pcs { pcs_PST = new_pst,
+ pcs_insts = new_pcs_insts,
+ pcs_rules = new_pcs_rules
+ }
in
- returnTc (final_env, -- WAS: really_final_env,
+ returnTc (final_env,
TcResults { tc_pcs = final_pcs,
tc_env = local_type_env,
tc_binds = all_binds',
- tc_insts = map iDFunId inst_info,
+ tc_insts = map iDFunId local_inst_info,
tc_fords = foi_decls ++ foe_decls',
tc_rules = rules'
})
\begin{code}
printTcDump dflags Nothing = return ()
-printTcDump dflags (Just (_,results))
+printTcDump dflags (Just results)
= do dumpIfSet_dyn dflags Opt_D_dump_types
"Type signatures" (dump_sigs results)
dumpIfSet_dyn dflags Opt_D_dump_tc
dump_tc results
= vcat [ppr (tc_binds results),
- pp_rules (tc_rules results) --,
--- ppr_gen_tycons (tc_tycons results)
+ pp_rules (tc_rules results),
+ ppr_gen_tycons [tc | ATyCon tc <- nameEnvElts (tc_env results)]
]
dump_sigs results -- Print type signatures