[project @ 2002-10-15 11:52:31 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcRnDriver.lhs
index 04b0ca3..e3858d0 100644 (file)
@@ -22,7 +22,7 @@ import {-# SOURCE #-} TcSplice( tcSpliceDecls )
 import CmdLineOpts     ( DynFlag(..), opt_PprStyle_Debug, dopt )
 import HsSyn           ( HsModule(..), HsBinds(..), MonoBinds(..), HsDecl(..), HsExpr(..),
                          Stmt(..), Pat(VarPat), HsStmtContext(..), RuleDecl(..),
-                         HsGroup(..),
+                         HsGroup(..), SpliceDecl(..),
                          mkSimpleMatch, placeHolderType, toHsType, andMonoBinds,
                          isSrcRule, collectStmtsBinders
                        )
@@ -73,7 +73,7 @@ import TcTyClsDecls   ( tcTyAndClassDecls )
 import RnNames         ( rnImports, exportsFromAvail, reportUnusedNames )
 import RnIfaces                ( slurpImpDecls, checkVersions, RecompileRequired, outOfDate )
 import RnHiFiles       ( readIface, loadOldIface )
-import RnEnv           ( lookupSrcName, lookupOccRn,
+import RnEnv           ( lookupSrcName, lookupOccRn, plusGlobalRdrEnv,
                          ubiquitousNames, implicitModuleFVs, implicitStmtFVs, dataTcOccs )
 import RnExpr          ( rnStmts, rnExpr )
 import RnNames         ( importsFromLocalDecls )
@@ -112,7 +112,7 @@ import HscTypes             ( PersistentCompilerState(..), InteractiveContext(..),
 #ifdef GHCI
 import RdrName         ( rdrEnvElts )
 import RnHiFiles       ( loadInterface )
-import RnEnv           ( mkGlobalRdrEnv, plusGlobalRdrEnv )
+import RnEnv           ( mkGlobalRdrEnv )
 import HscTypes                ( GlobalRdrElt(..), GlobalRdrEnv, ImportReason(..), Provenance(..), 
                          isLocalGRE )
 #endif
@@ -145,7 +145,7 @@ tcRnModule hsc_env pcs
    do {        -- Deal with imports; sets tcg_rdr_env, tcg_imports
        (rdr_env, imports) <- rnImports import_decls ;
        updGblEnv ( \ gbl -> gbl { tcg_rdr_env = rdr_env,
-                                  tcg_imports = imports }) 
+                                  tcg_imports = tcg_imports gbl `plusImportAvails` imports }) 
                     $ do {
        traceRn (text "rn1") ;
                -- Fail if there are any errors so far
@@ -172,7 +172,7 @@ tcRnModule hsc_env pcs
        updGblEnv (\gbl -> gbl { tcg_deprecs = tcg_deprecs gbl `plusDeprecs` mod_deprecs })
                  $ do {
 
-       traceRn (text "rn4") ;
+       traceRn (text "Rn4:" <+> ppr (imp_unqual (tcg_imports tcg_env))) ;
                -- Process the export list
        export_avails <- exportsFromAvail exports ;
        updGblEnv (\gbl -> gbl { tcg_exports = export_avails })
@@ -597,12 +597,17 @@ tcRnSrcDecls ds
        -- If there is no splice, we're done
        case group_tail of
           Nothing -> return (tcg_env, src_fvs1)
-          Just (splice_expr, rest_ds) -> do {
+          Just (SpliceDecl splice_expr splice_loc, rest_ds) -> do {
 
        setGblEnv tcg_env $ do {
-               
+
+#ifndef GHCI
+       failWithTc (text "Can't do a top-level splice; need a bootstrapped compiler")
+#else
        -- Rename the splice expression, and get its supporting decls
-       (rn_splice_expr, fvs) <- initRn SourceMode (rnExpr splice_expr) ;
+       (rn_splice_expr, fvs) <- initRn SourceMode $
+                                addSrcLoc splice_loc $
+                                rnExpr splice_expr ;
        tcg_env <- importSupportingDecls fvs ;
        setGblEnv tcg_env $ do {
 
@@ -613,7 +618,9 @@ tcRnSrcDecls ds
        (tcg_env, src_fvs2) <- tcRnSrcDecls (spliced_decls ++ rest_ds) ;
 
        return (tcg_env, src_fvs1 `plusFV` src_fvs2)
-    }}}}
+    }
+#endif /* GHCI */
+    }}}
 \end{code}
 
 
@@ -658,6 +665,8 @@ rnTopSrcDecls group
                                                  tcg_imports gbl }) 
                     $ do {
 
+       failIfErrsM ;   -- No point in continuing if (say) we have duplicate declarations
+
                -- Rename the source decls
        (tcg_env, rn_src_decls, src_fvs) <- initRn SourceMode (rnSrcDecls group) ;
        setGblEnv tcg_env $ do {