[project @ 2001-12-03 11:36:26 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcModule.lhs
index 4a34cba..eea3a21 100644 (file)
@@ -15,7 +15,7 @@ module TcModule (
 import CmdLineOpts     ( DynFlag(..), DynFlags, dopt )
 import HsSyn           ( HsBinds(..), MonoBinds(..), HsDecl(..), HsExpr(..),
                          Stmt(..), InPat(..), HsMatchContext(..), HsDoContext(..), RuleDecl(..),
-                         isIfaceRuleDecl, nullBinds, andMonoBindList, mkSimpleMatch, placeHolderType
+                         isIfaceRuleDecl, nullBinds, mkSimpleMatch, placeHolderType
                        )
 import PrelNames       ( mAIN_Name, mainName, ioTyConName, printName,
                          returnIOName, bindIOName, failIOName, 
@@ -33,7 +33,7 @@ import TcHsSyn                ( TypecheckedMonoBinds, TypecheckedHsExpr,
 import MkIface         ( pprModDetails )
 import TcExpr          ( tcMonoExpr )
 import TcMonad
-import TcMType         ( unifyTauTy, newTyVarTy, zonkTcType, tcInstType )
+import TcMType         ( newTyVarTy, zonkTcType, tcInstType )
 import TcType          ( Type, liftedTypeKind, openTypeKind,
                          tyVarsOfType, tidyType, tcFunResultTy,
                          mkForAllTys, mkFunTys, mkTyConApp, tcSplitForAllTys
@@ -52,9 +52,10 @@ import TcRules               ( tcIfaceRules, tcSourceRules )
 import TcForeign       ( tcForeignImports, tcForeignExports )
 import TcIfaceSig      ( tcInterfaceSigs )
 import TcInstDcls      ( tcInstDecls1, tcInstDecls2 )
+import TcUnify         ( unifyTauTy )
 import TcSimplify      ( tcSimplifyTop, tcSimplifyInfer )
 import TcTyClsDecls    ( tcTyAndClassDecls )
-import CoreUnfold      ( unfoldingTemplate, hasUnfolding )
+import CoreUnfold      ( unfoldingTemplate )
 import TysWiredIn      ( mkListTy, unitTy )
 import ErrUtils                ( printErrorsAndWarnings, errorsFound, 
                          dumpIfSet_dyn, dumpIfSet_dyn_or, showPass )
@@ -71,7 +72,6 @@ import HscTypes               ( PersistentCompilerState(..), HomeSymbolTable,
                          PackageTypeEnv, ModIface(..),
                          ModDetails(..), DFunId,
                          TypeEnv, extendTypeEnvList, typeEnvTyCons, typeEnvElts,
-                         TyThing(..), 
                          mkTypeEnv
                        )
 \end{code}
@@ -553,24 +553,25 @@ tcImports unf_env pcs hst get_fixity this_mod decls
     tcTyAndClassDecls unf_env this_mod tycl_decls      `thenTc` \ env ->
     tcSetEnv env                                       $
     
+       -- 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 "Tc2")                       `thenNF_Tc_`
+    tcInterfaceSigs unf_env this_mod tycl_decls        `thenTc` \ sig_ids ->
+    tcExtendGlobalValEnv sig_ids               $
+    
        -- Typecheck the instance decls, includes deriving
-    traceTc (text "Tc2")       `thenNF_Tc_`
+       -- Note that imported dictionary functions are already
+       -- in scope from the preceding tcInterfaceSigs
+    traceTc (text "Tc3")       `thenNF_Tc_`
     tcInstDecls1 (pcs_insts pcs) (pcs_PRS pcs) 
             hst unf_env get_fixity this_mod 
             decls                      `thenTc` \ (new_pcs_insts, inst_env, local_insts, deriv_binds) ->
     tcSetInstEnv inst_env                      $
     
-    -- 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 "Tc3")                       `thenNF_Tc_`
-    tcInterfaceSigs unf_env this_mod tycl_decls        `thenTc` \ sig_ids ->
-    tcExtendGlobalValEnv sig_ids               $
-    
-    
     tcIfaceRules unf_env (pcs_rules pcs) this_mod iface_rules  `thenNF_Tc` \ (new_pcs_rules, local_rules) ->
        -- When relinking this module from its interface-file decls
        -- we'll have IfaceRules that are in fact local to this module