- -- Default declarations
- tcDefaults default_decls `thenTc` \ defaulting_tys ->
- tcSetDefaultTys defaulting_tys ( -- for the iface sigs...
-
- -- 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
- tcInterfaceSigs sigs `thenTc` \ sig_ids ->
-
- returnTc (env, inst_info, deriv_binds, ddump_deriv, defaulting_tys, sig_ids)
-
- )))) `thenTc` \ (env, inst_info, deriv_binds, ddump_deriv, defaulting_tys, _) ->
-
- tcSetEnv env ( -- to the end...
- tcSetDefaultTys defaulting_tys ( -- ditto
+-- Convenient type synonyms first:
+data TcResults
+ = TcResults {
+ -- All these fields have info *just for this module*
+ tc_env :: TypeEnv, -- The top level TypeEnv
+ tc_binds :: TypecheckedMonoBinds, -- Bindings
+ tc_fords :: [TypecheckedForeignDecl], -- Foreign import & exports.
+ tc_rules :: [TypecheckedRuleDecl] -- Transformation rules
+ }
+
+---------------
+typecheckModule
+ :: DynFlags
+ -> PersistentCompilerState
+ -> HomeSymbolTable
+ -> ModIface -- Iface for this module
+ -> PrintUnqualified -- For error printing
+ -> [RenamedHsDecl]
+ -> IO (Maybe (PersistentCompilerState, TcResults))
+ -- The new PCS is Augmented with imported information,
+ -- (but not stuff from this module)
+
+
+typecheckModule dflags pcs hst mod_iface unqual decls
+ = do { maybe_tc_result <- typecheck dflags pcs hst unqual $
+ tcModule pcs hst get_fixity this_mod decls
+ ; printTcDump dflags maybe_tc_result
+ ; return maybe_tc_result }
+ where
+ this_mod = mi_module mod_iface
+ fixity_env = mi_fixities mod_iface
+
+ get_fixity :: Name -> Maybe Fixity
+ get_fixity nm = lookupNameEnv fixity_env nm
+
+---------------
+typecheckExpr :: DynFlags
+ -> PersistentCompilerState
+ -> HomeSymbolTable
+ -> PrintUnqualified -- For error printing
+ -> Module
+ -> (RenamedHsExpr, -- The expression itself
+ [RenamedHsDecl]) -- Plus extra decls it sucked in from interface files
+ -> IO (Maybe (PersistentCompilerState, TypecheckedHsExpr, TcType))
+
+typecheckExpr dflags pcs hst unqual this_mod (expr, decls)
+ = typecheck dflags pcs hst unqual $
+
+ -- use the default default settings, i.e. [Integer, Double]
+ tcSetDefaultTys defaultDefaultTys $
+ tcImports pcs hst get_fixity this_mod decls `thenTc` \ (env, new_pcs, local_inst_info, deriv_binds, local_rules) ->
+ ASSERT( null local_inst_info && nullBinds deriv_binds && null local_rules )
+
+ tcSetEnv env $
+ newTyVarTy openTypeKind `thenTc` \ ty ->
+ tcMonoExpr expr ty `thenTc` \ (expr', lie) ->
+ tcSimplifyTop lie `thenTc` \ binds ->
+ let all_expr = mkHsLet binds expr' in
+ zonkExpr all_expr `thenNF_Tc` \ zonked_expr ->
+ zonkTcType ty `thenNF_Tc` \ zonked_ty ->
+ returnTc (new_pcs, zonked_expr, zonked_ty)
+ where
+ get_fixity :: Name -> Maybe Fixity
+ get_fixity n = pprPanic "typecheckExpr" (ppr n)
+
+---------------
+typecheck :: DynFlags
+ -> PersistentCompilerState
+ -> HomeSymbolTable
+ -> PrintUnqualified -- For error printing
+ -> TcM r
+ -> IO (Maybe r)
+
+typecheck dflags pcs hst unqual thing_inside
+ = do { showPass dflags "Typechecker";
+ ; env <- initTcEnv hst (pcs_PTE pcs)
+
+ ; (maybe_tc_result, errs) <- initTc dflags env thing_inside
+
+ ; printErrorsAndWarnings unqual errs
+
+ ; if errorsFound errs then
+ return Nothing
+ else
+ return maybe_tc_result
+ }
+\end{code}