[project @ 2002-11-21 15:51:43 by simonpj]
authorsimonpj <unknown>
Thu, 21 Nov 2002 15:51:44 +0000 (15:51 +0000)
committersimonpj <unknown>
Thu, 21 Nov 2002 15:51:44 +0000 (15:51 +0000)
-------------------------------
Pass the current-module type envt
to HscMain.compileExpr, and thence to the desugarer
-------------------------------

For Template Haskell it's important to have the type envt of
the current module available to hand the desugarer.

Should fix TH_spliceDecl3

ghc/compiler/deSugar/Desugar.lhs
ghc/compiler/main/HscMain.lhs

index 5880de0..f06cd26 100644 (file)
@@ -10,7 +10,7 @@ module Desugar ( deSugar, deSugarExpr ) where
 
 import CmdLineOpts     ( DynFlag(..), dopt, opt_SccProfilingOn )
 import HscTypes                ( ModGuts(..), ModGuts, HscEnv(..), ExternalPackageState(..), 
-                         PersistentCompilerState(..), Dependencies(..),
+                         PersistentCompilerState(..), Dependencies(..), TypeEnv, GlobalRdrEnv,
                          lookupType, unQualInScope )
 import HsSyn           ( MonoBinds, RuleDecl(..), RuleBndr(..), 
                          HsExpr(..), HsBinds(..), MonoBinds(..) )
@@ -38,6 +38,7 @@ import ErrUtils               ( doIfSet, dumpIfSet_dyn, pprBagOfWarnings, addShortWarnLocLine
 import Outputable
 import qualified Pretty
 import UniqSupply      ( mkSplitUniqSupply )
+import Maybes          ( orElse )
 import SrcLoc          ( SrcLoc )
 import FastString
 import DATA_IOREF      ( readIORef )
@@ -136,18 +137,16 @@ deSugar hsc_env pcs
 
 deSugarExpr :: HscEnv
            -> PersistentCompilerState
-           -> Module -> PrintUnqualified
+           -> Module -> GlobalRdrEnv -> TypeEnv 
            -> TypecheckedHsExpr
            -> IO CoreExpr
-deSugarExpr hsc_env pcs mod_name unqual tc_expr
+deSugarExpr hsc_env pcs mod_name rdr_env type_env tc_expr
   = do { showPass dflags "Desugar"
        ; us <- mkSplitUniqSupply 'd'
 
        -- Do desugaring
        ; let (core_expr, ds_warns) = initDs dflags us lookup mod_name (dsExpr tc_expr)    
              warn_doc = pprBagOfWarnings (mapBag mk_warn ds_warns)
-             mk_warn :: (SrcLoc,SDoc) -> (SrcLoc, Pretty.Doc)
-             mk_warn (loc,sdoc) = addShortWarnLocLine loc unqual sdoc
 
        -- Display any warnings
         ; doIfSet (not (isEmptyBag ds_warns))
@@ -162,9 +161,15 @@ deSugarExpr hsc_env pcs mod_name unqual tc_expr
     dflags   = hsc_dflags hsc_env
     hpt      = hsc_HPT hsc_env
     pte      = eps_PTE (pcs_EPS pcs)
-    lookup n = case lookupType hpt pte n of
-                Just v -> v 
-                other  -> pprPanic "Desugar: lookup:" (ppr n)
+    lookup n = lookupNameEnv type_env n        `orElse`        -- Look in the type env of the
+                                                       -- current module first
+              lookupType hpt pte n     `orElse`        -- Then other modules
+              pprPanic "Desugar: lookup:" (ppr n)
+
+    mk_warn :: (SrcLoc,SDoc) -> (SrcLoc, Pretty.Doc)
+    mk_warn (loc,sdoc) = addShortWarnLocLine loc print_unqual sdoc
+
+    print_unqual = unQualInScope rdr_env
 
 dsProgram all_binds rules fo_decls
   = dsMonoBinds auto_scc all_binds []  `thenDs` \ core_prs ->
index 49f4a2f..f5e239a 100644 (file)
@@ -514,7 +514,9 @@ hscStmt hsc_env pcs icontext stmt
 
                -- Then desugar, code gen, and link it
        ; hval <- compileExpr hsc_env pcs1 iNTERACTIVE 
-                             (icPrintUnqual new_ic) tc_expr
+                             (ic_rn_gbl_env new_ic) 
+                             (ic_type_env new_ic)
+                             tc_expr
 
        ; return (pcs1, Just (new_ic, bound_names, hval))
        }}}}}
@@ -632,15 +634,15 @@ myParseIdentifier dflags str
 #ifdef GHCI
 compileExpr :: HscEnv 
            -> PersistentCompilerState
-           -> Module -> PrintUnqualified
+           -> Module -> GlobalRdrEnv -> TypeEnv
            -> TypecheckedHsExpr
            -> IO HValue
 
-compileExpr hsc_env pcs this_mod print_unqual tc_expr
+compileExpr hsc_env pcs this_mod type_env rdr_env tc_expr
   = do { let dflags = hsc_dflags hsc_env
 
                -- Desugar it
-       ; ds_expr <- deSugarExpr hsc_env pcs this_mod print_unqual tc_expr
+       ; ds_expr <- deSugarExpr hsc_env pcs this_mod rdr_env type_env tc_expr
        
                -- Flatten it
        ; flat_expr <- flattenExpr hsc_env pcs ds_expr