Remove unused imports
[ghc-hetmet.git] / compiler / iface / IfaceEnv.lhs
index bf8d09b..05c6289 100644 (file)
@@ -1,20 +1,13 @@
 (c) The University of Glasgow 2002-2006
 
 \begin{code}
-{-# OPTIONS_GHC -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
--- for details
-
 module IfaceEnv (
        newGlobalBinder, newIPName, newImplicitBinder, 
        lookupIfaceTop,
        lookupOrig, lookupOrigNameCache, extendNameCache,
        newIfaceName, newIfaceNames,
        extendIfaceIdEnv, extendIfaceTyVarEnv, 
-       tcIfaceLclId,     tcIfaceTyVar, 
+       tcIfaceLclId, tcIfaceTyVar, lookupIfaceTyVar,
        tcIfaceTick,
 
        ifaceExportNames,
@@ -33,10 +26,9 @@ import TyCon
 import DataCon
 import Var
 import Name
-import OccName
 import PrelNames
 import Module
-import UniqFM
+import LazyUniqFM
 import FastString
 import UniqSupply
 import FiniteMap
@@ -121,9 +113,16 @@ newImplicitBinder :: Name                  -- Base name
 -- For source type/class decls, this is the first occurrence
 -- For iface ones, the LoadIface has alrady allocated a suitable name in the cache
 newImplicitBinder base_name mk_sys_occ
-  = newGlobalBinder (nameModule base_name)
-                   (mk_sys_occ (nameOccName base_name))
-                   (nameSrcSpan base_name)    
+  | Just mod <- nameModule_maybe base_name
+  = newGlobalBinder mod occ loc
+  | otherwise          -- When typechecking a [d| decl bracket |], 
+                       -- TH generates types, classes etc with Internal names,
+                       -- so we follow suit for the implicit binders
+  = do { uniq <- newUnique
+       ; return (mkInternalName uniq occ loc) }
+  where
+    occ = mk_sys_occ (nameOccName base_name)
+    loc = nameSrcSpan base_name
 
 ifaceExportNames :: [IfaceExport] -> TcRnIf gbl lcl [AvailInfo]
 ifaceExportNames exports = do
@@ -139,7 +138,7 @@ lookupAvail mod (AvailTC p_occ occs) = do
   p_name <- lookupOrig mod p_occ
   let lookup_sub occ | occ == p_occ = return p_name
                      | otherwise    = lookupOrig mod occ
-  subs <- mappM lookup_sub occs
+  subs <- mapM lookup_sub occs
   return (AvailTC p_name subs)
        -- Remember that 'occs' is all the exported things, including
        -- the parent.  It's possible to export just class ops without
@@ -159,7 +158,7 @@ lookupOrig mod occ
     
        ; name_cache <- getNameCache
        ; case lookupOrigNameCache (nsNames name_cache) mod occ of {
-             Just name -> returnM name;
+             Just name -> return name;
              Nothing   ->
               let
                 us        = nsUniqs name_cache
@@ -173,15 +172,14 @@ lookupOrig mod occ
     }}}
 
 newIPName :: IPName OccName -> TcRnIf m n (IPName Name)
-newIPName occ_name_ip
-  = getNameCache               `thenM` \ name_supply ->
+newIPName occ_name_ip = do
+    name_supply <- getNameCache
     let
        ipcache = nsIPs name_supply
-    in
     case lookupFM ipcache key of
-       Just name_ip -> returnM name_ip
-       Nothing      -> setNameCache new_ns     `thenM_`
-                       returnM name_ip
+       Just name_ip -> return name_ip
+       Nothing      -> do setNameCache new_ns
+                          return name_ip
                  where
                     (us', us1)  = splitUniqSupply (nsUniqs name_supply)
                     uniq        = uniqFromSupply us1
@@ -192,12 +190,17 @@ newIPName occ_name_ip
        key = occ_name_ip       -- Ensures that ?x and %x get distinct Names
 \end{code}
 
-       Local helper functions (not exported)
+%************************************************************************
+%*                                                                     *
+               Name cache access
+%*                                                                     *
+%************************************************************************
 
 \begin{code}
 lookupOrigNameCache :: OrigNameCache -> Module -> OccName -> Maybe Name
-lookupOrigNameCache nc mod occ
-  | mod == dATA_TUP || mod == gHC_PRIM,                -- Boxed tuples from one, 
+lookupOrigNameCache _ mod occ
+  -- XXX Why is gHC_UNIT not mentioned here?
+  | mod == gHC_TUPLE || mod == gHC_PRIM,               -- Boxed tuples from one, 
     Just tup_info <- isTupleOcc_maybe occ      -- unboxed from the other
   =    -- Special case for tuples; there are too many
        -- of them to pre-populate the original-name cache
@@ -215,7 +218,8 @@ lookupOrigNameCache nc mod occ      -- The normal case
 
 extendOrigNameCache :: OrigNameCache -> Name -> OrigNameCache
 extendOrigNameCache nc name 
-  = extendNameCache nc (nameModule name) (nameOccName name) name
+  = ASSERT2( isExternalName name, ppr name ) 
+    extendNameCache nc (nameModule name) (nameOccName name) name
 
 extendNameCache :: OrigNameCache -> Module -> OccName -> Name -> OrigNameCache
 extendNameCache nc mod occ name
@@ -277,6 +281,11 @@ tcIfaceTyVar occ
             Nothing     -> failIfM (text "Iface type variable out of scope: " <+> ppr occ)
         }
 
+lookupIfaceTyVar :: FastString -> IfL (Maybe TyVar)
+lookupIfaceTyVar occ
+  = do { lcl <- getLclEnv
+       ; return (lookupUFM (if_tv_env lcl) occ) }
+
 extendIfaceTyVarEnv :: [TyVar] -> IfL a -> IfL a
 extendIfaceTyVarEnv tyvars thing_inside
   = do { env <- getLclEnv