Bug fixes in my refactored RnNames code.
[ghc-hetmet.git] / ghc / compiler / typecheck / TcRnDriver.lhs
index dcf1636..4ca79d9 100644 (file)
@@ -53,6 +53,7 @@ import TcSimplify     ( tcSimplifyTop )
 import TcTyClsDecls    ( tcTyAndClassDecls )
 import LoadIface       ( loadOrphanModules )
 import RnNames         ( importsFromLocalDecls, rnImports, rnExports,
+                          mkRdrEnvAndImports, mkExportNameSet,
                          reportUnusedNames, reportDeprecations )
 import RnEnv           ( lookupSrcOcc_maybe )
 import RnSource                ( rnSrcDecls, rnTyClDecls, checkModDeprec )
@@ -149,7 +150,7 @@ tcRnModule :: HscEnv
           -> Located (HsModule RdrName)
           -> IO (Messages, Maybe TcGblEnv)
 
-tcRnModule hsc_env hsc_src save_rn_decls
+tcRnModule hsc_env hsc_src save_rn_syntax
         (L loc (HsModule maybe_mod export_ies 
                          import_decls local_decls mod_deprec))
  = do { showPass (hsc_dflags hsc_env) "Renamer/typechecker" ;
@@ -161,8 +162,9 @@ tcRnModule hsc_env hsc_src save_rn_decls
    initTc hsc_env hsc_src this_mod $ 
    setSrcSpan loc $
    do {
-               -- Deal with imports; sets tcg_rdr_env, tcg_imports
-       (rdr_env, imports) <- rnImports import_decls ;
+               -- Deal with imports;
+       rn_imports <- rnImports import_decls ;
+        (rdr_env, imports) <- mkRdrEnvAndImports rn_imports ;
 
        let { dep_mods :: ModuleEnv (Module, IsBootInterface)
            ; dep_mods = imp_dep_mods imports
@@ -189,7 +191,11 @@ tcRnModule hsc_env hsc_src save_rn_decls
                gbl { tcg_rdr_env  = rdr_env,
                      tcg_inst_env = extendInstEnvList (tcg_inst_env gbl) home_insts,
                      tcg_imports  = tcg_imports gbl `plusImportAvails` imports,
-                     tcg_rn_decls = if save_rn_decls then
+                      tcg_rn_imports = if save_rn_syntax then
+                                         Just rn_imports
+                                       else
+                                         Nothing,
+                     tcg_rn_decls = if save_rn_syntax then
                                        Just emptyRnGroup
                                     else
                                        Nothing })
@@ -223,7 +229,9 @@ tcRnModule hsc_env hsc_src save_rn_decls
        reportDeprecations tcg_env ;
 
                -- Process the export list
-       exports <- rnExports (isJust maybe_mod) export_ies ;
+       rn_exports <- rnExports export_ies ;
+        let { liftM2' fn a b = do a' <- a; b' <- b; return (fn a' b') } ;
+        exports <- mkExportNameSet (isJust maybe_mod) (liftM2' (,) rn_exports export_ies) ;
 
                -- Check whether the entire module is deprecated
                -- This happens only once per module
@@ -231,6 +239,9 @@ tcRnModule hsc_env hsc_src save_rn_decls
 
                -- Add exports and deprecations to envt
        let { final_env  = tcg_env { tcg_exports = exports,
+                                     tcg_rn_exports = if save_rn_syntax then
+                                                         rn_exports
+                                                      else Nothing,
                                     tcg_dus = tcg_dus tcg_env `plusDU` usesOnly exports,
                                     tcg_deprecs = tcg_deprecs tcg_env `plusDeprecs` 
                                                   mod_deprecs }
@@ -730,7 +741,7 @@ tcTopSrcDecls boot_details
 checkMain :: TcM TcGblEnv
 -- If we are in module Main, check that 'main' is defined.
 checkMain 
-  = do { ghci_mode <- getGhciMode ;
+  = do { ghc_mode <- getGhcMode ;
         tcg_env   <- getGblEnv ;
         dflags    <- getDOpts ;
         let { main_mod = mainModIs dflags ;
@@ -738,11 +749,11 @@ checkMain
                                Just fn -> mkRdrUnqual (mkVarOccFS (mkFastString fn)) ;
                                Nothing -> main_RDR_Unqual } } ;
        
-        check_main ghci_mode tcg_env main_mod main_fn
+        check_main ghc_mode tcg_env main_mod main_fn
     }
 
 
-check_main ghci_mode tcg_env main_mod main_fn
+check_main ghc_mode tcg_env main_mod main_fn
  | mod /= main_mod
  = traceTc (text "checkMain not" <+> ppr main_mod <+> ppr mod) >>
    return tcg_env
@@ -793,7 +804,7 @@ check_main ghci_mode tcg_env main_mod main_fn
   where
     mod = tcg_mod tcg_env
  
-    complain_no_main | ghci_mode == Interactive = return ()
+    complain_no_main | ghc_mode == Interactive = return ()
                     | otherwise                = failWithTc noMainMsg
        -- In interactive mode, don't worry about the absence of 'main'
        -- In other modes, fail altogether, so that we don't go on