summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-09-17 19:05:43 +0100
committerSimon Marlow <marlowsd@gmail.com>2011-09-21 09:53:10 +0100
commit94e7c6bf27fc18d9bbad5099b4c5cb4fd8a421e0 (patch)
tree362c8eff73a3f74388605d46c8ef5ec4946026c9
parent222589a9f270d90f4ac21bf22b0a82e8ae126718 (diff)
downloadhaskell-94e7c6bf27fc18d9bbad5099b4c5cb4fd8a421e0.tar.gz
move AvailInfo and related things into its own module
-rw-r--r--compiler/basicTypes/Avail.hs107
-rw-r--r--compiler/deSugar/Desugar.lhs1
-rw-r--r--compiler/ghc.cabal.in1
-rw-r--r--compiler/iface/BinIface.hs1
-rw-r--r--compiler/iface/IfaceEnv.lhs1
-rw-r--r--compiler/iface/LoadIface.lhs1
-rw-r--r--compiler/iface/MkIface.lhs1
-rw-r--r--compiler/main/GHC.hs4
-rw-r--r--compiler/main/HscTypes.lhs84
-rw-r--r--compiler/main/InteractiveEval.hs1
-rw-r--r--compiler/main/TidyPgm.lhs3
-rw-r--r--compiler/prelude/PrelInfo.lhs27
-rw-r--r--compiler/rename/RnBinds.lhs7
-rw-r--r--compiler/rename/RnEnv.lhs5
-rw-r--r--compiler/rename/RnNames.lhs1
-rw-r--r--compiler/rename/RnSource.lhs9
-rw-r--r--compiler/typecheck/TcRnDriver.lhs1
-rw-r--r--compiler/typecheck/TcRnTypes.lhs1
-rw-r--r--compiler/typecheck/TcTyDecls.lhs1
19 files changed, 149 insertions, 108 deletions
diff --git a/compiler/basicTypes/Avail.hs b/compiler/basicTypes/Avail.hs
new file mode 100644
index 0000000000..8bf622e13d
--- /dev/null
+++ b/compiler/basicTypes/Avail.hs
@@ -0,0 +1,107 @@
+--
+-- (c) The University of Glasgow
+--
+
+module Avail (
+ Avails,
+ AvailInfo(..),
+ availsToNameSet,
+ availsToNameEnv,
+ availName, availNames,
+ stableAvailCmp,
+ gresFromAvails,
+ gresFromAvail
+ ) where
+
+import Name
+import NameEnv
+import NameSet
+import RdrName
+
+import Outputable
+import Util
+
+-- -----------------------------------------------------------------------------
+-- The AvailInfo type
+
+-- | Records what things are "available", i.e. in scope
+data AvailInfo = Avail Name -- ^ An ordinary identifier in scope
+ | AvailTC Name
+ [Name] -- ^ A type or class in scope. Parameters:
+ --
+ -- 1) The name of the type or class
+ -- 2) The available pieces of type or class.
+ --
+ -- The AvailTC Invariant:
+ -- * If the type or class is itself
+ -- to be in scope, it must be
+ -- *first* in this list. Thus,
+ -- typically: @AvailTC Eq [Eq, ==, \/=]@
+ deriving( Eq )
+ -- Equality used when deciding if the
+ -- interface has changed
+
+-- | A collection of 'AvailInfo' - several things that are \"available\"
+type Avails = [AvailInfo]
+
+-- | Compare lexicographically
+stableAvailCmp :: AvailInfo -> AvailInfo -> Ordering
+stableAvailCmp (Avail n1) (Avail n2) = n1 `stableNameCmp` n2
+stableAvailCmp (Avail {}) (AvailTC {}) = LT
+stableAvailCmp (AvailTC n ns) (AvailTC m ms) = (n `stableNameCmp` m) `thenCmp`
+ (cmpList stableNameCmp ns ms)
+stableAvailCmp (AvailTC {}) (Avail {}) = GT
+
+
+-- -----------------------------------------------------------------------------
+-- Operations on AvailInfo
+
+availsToNameSet :: [AvailInfo] -> NameSet
+availsToNameSet avails = foldr add emptyNameSet avails
+ where add avail set = addListToNameSet set (availNames avail)
+
+availsToNameEnv :: [AvailInfo] -> NameEnv AvailInfo
+availsToNameEnv avails = foldr add emptyNameEnv avails
+ where add avail env = extendNameEnvList env
+ (zip (availNames avail) (repeat avail))
+
+-- | Just the main name made available, i.e. not the available pieces
+-- of type or class brought into scope by the 'GenAvailInfo'
+availName :: AvailInfo -> Name
+availName (Avail n) = n
+availName (AvailTC n _) = n
+
+-- | All names made available by the availability information
+availNames :: AvailInfo -> [Name]
+availNames (Avail n) = [n]
+availNames (AvailTC _ ns) = ns
+
+-- | make a 'GlobalRdrEnv' where all the elements point to the same
+-- Provenance (useful for "hiding" imports, or imports with
+-- no details).
+gresFromAvails :: Provenance -> [AvailInfo] -> [GlobalRdrElt]
+gresFromAvails prov avails
+ = concatMap (gresFromAvail (const prov)) avails
+
+gresFromAvail :: (Name -> Provenance) -> AvailInfo -> [GlobalRdrElt]
+gresFromAvail prov_fn avail
+ = [ GRE {gre_name = n,
+ gre_par = parent n avail,
+ gre_prov = prov_fn n}
+ | n <- availNames avail ]
+ where
+ parent _ (Avail _) = NoParent
+ parent n (AvailTC m _) | n == m = NoParent
+ | otherwise = ParentIs m
+
+-- -----------------------------------------------------------------------------
+-- Printing
+
+instance Outputable AvailInfo where
+ ppr = pprAvail
+
+pprAvail :: AvailInfo -> SDoc
+pprAvail (Avail n) = ppr n
+pprAvail (AvailTC n ns) = ppr n <> braces (hsep (punctuate comma (map ppr ns)))
+
+
diff --git a/compiler/deSugar/Desugar.lhs b/compiler/deSugar/Desugar.lhs
index 9001ec7cf5..d85ff0a8df 100644
--- a/compiler/deSugar/Desugar.lhs
+++ b/compiler/deSugar/Desugar.lhs
@@ -16,6 +16,7 @@ import TcRnTypes
import MkIface
import Id
import Name
+import Avail
import CoreSyn
import CoreSubst
import PprCore
diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in
index eea42bf981..01bbeb067d 100644
--- a/compiler/ghc.cabal.in
+++ b/compiler/ghc.cabal.in
@@ -146,6 +146,7 @@ Library
vectorise
Exposed-Modules:
+ Avail
BasicTypes
DataCon
Demand
diff --git a/compiler/iface/BinIface.hs b/compiler/iface/BinIface.hs
index 55ab378ea1..083e85c27b 100644
--- a/compiler/iface/BinIface.hs
+++ b/compiler/iface/BinIface.hs
@@ -21,6 +21,7 @@ import Annotations
import IfaceSyn
import Module
import Name
+import Avail
import VarEnv
import DynFlags
import UniqFM
diff --git a/compiler/iface/IfaceEnv.lhs b/compiler/iface/IfaceEnv.lhs
index 798164c448..98c21fd286 100644
--- a/compiler/iface/IfaceEnv.lhs
+++ b/compiler/iface/IfaceEnv.lhs
@@ -27,6 +27,7 @@ import Type
import DataCon
import Var
import Name
+import Avail
import PrelNames
import Module
import UniqFM
diff --git a/compiler/iface/LoadIface.lhs b/compiler/iface/LoadIface.lhs
index b9e72a6c1f..bbee0424ff 100644
--- a/compiler/iface/LoadIface.lhs
+++ b/compiler/iface/LoadIface.lhs
@@ -43,6 +43,7 @@ import InstEnv
import FamInstEnv
import Name
import NameEnv
+import Avail
import Module
import Maybes
import ErrUtils
diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs
index c56e9854e0..1688d2314d 100644
--- a/compiler/iface/MkIface.lhs
+++ b/compiler/iface/MkIface.lhs
@@ -75,6 +75,7 @@ import VarEnv
import VarSet
import Var
import Name
+import Avail
import RdrName
import NameEnv
import NameSet
diff --git a/compiler/main/GHC.hs b/compiler/main/GHC.hs
index d803ea85fb..928f21e8ff 100644
--- a/compiler/main/GHC.hs
+++ b/compiler/main/GHC.hs
@@ -265,6 +265,7 @@ import TyCon
import Class
import DataCon
import Name hiding ( varName )
+import Avail
import InstEnv
import FamInstEnv
import SrcLoc
@@ -276,8 +277,7 @@ import HscTypes
import DynFlags
import StaticFlagParser
import qualified StaticFlags
-import SysTools ( initSysTools, cleanTempFiles,
- cleanTempDirs )
+import SysTools
import Annotations
import Module
import UniqFM
diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs
index 0b90fd9668..79c5c13c42 100644
--- a/compiler/main/HscTypes.lhs
+++ b/compiler/main/HscTypes.lhs
@@ -74,9 +74,7 @@ module HscTypes (
WhetherHasOrphans, IsBootInterface, Usage(..),
Dependencies(..), noDependencies,
NameCache(..), OrigNameCache, OrigIParamCache,
- Avails, availsToNameSet, availsToNameEnv, availName, availNames,
- AvailInfo(..), gresFromAvails, gresFromAvail,
- IfaceExport, stableAvailCmp,
+ IfaceExport,
-- * Warnings
Warnings(..), WarningTxt(..), plusWarns,
@@ -116,6 +114,7 @@ import {-# SOURCE #-} InteractiveEval ( Resume )
import HsSyn
import RdrName
import Name
+import Avail
import NameEnv
import NameSet
import Module
@@ -695,6 +694,9 @@ data ModIface
-- See Note [RnNames . Trust Own Package]
}
+-- | The original names declared of a certain module that are exported
+type IfaceExport = AvailInfo
+
-- | The 'ModDetails' is essentially a cache for information in the 'ModIface'
-- for home modules only. Information relating to packages will be loaded into
-- global environments in 'ExternalPackageState'.
@@ -1473,82 +1475,6 @@ plusWarns _ (WarnAll t) = WarnAll t
plusWarns (WarnAll t) _ = WarnAll t
plusWarns (WarnSome v1) (WarnSome v2) = WarnSome (v1 ++ v2)
\end{code}
-\begin{code}
--- | A collection of 'AvailInfo' - several things that are \"available\"
-type Avails = [AvailInfo]
-
--- | Records what things are "available", i.e. in scope
-data AvailInfo = Avail Name -- ^ An ordinary identifier in scope
- | AvailTC Name
- [Name] -- ^ A type or class in scope. Parameters:
- --
- -- 1) The name of the type or class
- -- 2) The available pieces of type or class.
- --
- -- The AvailTC Invariant:
- -- * If the type or class is itself
- -- to be in scope, it must be *first* in this list.
- -- Thus, typically: @AvailTC Eq [Eq, ==, \/=]@
- deriving( Eq )
- -- Equality used when deciding if the interface has changed
-
--- | The original names declared of a certain module that are exported
-type IfaceExport = AvailInfo
-
-availsToNameSet :: [AvailInfo] -> NameSet
-availsToNameSet avails = foldr add emptyNameSet avails
- where add avail set = addListToNameSet set (availNames avail)
-
-availsToNameEnv :: [AvailInfo] -> NameEnv AvailInfo
-availsToNameEnv avails = foldr add emptyNameEnv avails
- where add avail env = extendNameEnvList env
- (zip (availNames avail) (repeat avail))
-
--- | Just the main name made available, i.e. not the available pieces
--- of type or class brought into scope by the 'GenAvailInfo'
-availName :: AvailInfo -> Name
-availName (Avail n) = n
-availName (AvailTC n _) = n
-
--- | All names made available by the availability information
-availNames :: AvailInfo -> [Name]
-availNames (Avail n) = [n]
-availNames (AvailTC _ ns) = ns
-
--- | make a 'GlobalRdrEnv' where all the elements point to the same
--- import declaration (useful for "hiding" imports, or imports with
--- no details).
-gresFromAvails :: Provenance -> [AvailInfo] -> [GlobalRdrElt]
-gresFromAvails prov avails
- = concatMap (gresFromAvail (const prov)) avails
-
-gresFromAvail :: (Name -> Provenance) -> AvailInfo -> [GlobalRdrElt]
-gresFromAvail prov_fn avail
- = [ GRE {gre_name = n,
- gre_par = parent n avail,
- gre_prov = prov_fn n}
- | n <- availNames avail ]
- where
- parent _ (Avail _) = NoParent
- parent n (AvailTC m _) | n == m = NoParent
- | otherwise = ParentIs m
-
-
-instance Outputable AvailInfo where
- ppr = pprAvail
-
-pprAvail :: AvailInfo -> SDoc
-pprAvail (Avail n) = ppr n
-pprAvail (AvailTC n ns) = ppr n <> braces (hsep (punctuate comma (map ppr ns)))
-
-stableAvailCmp :: AvailInfo -> AvailInfo -> Ordering
--- Compare lexicographically
-stableAvailCmp (Avail n1) (Avail n2) = n1 `stableNameCmp` n2
-stableAvailCmp (Avail {}) (AvailTC {}) = LT
-stableAvailCmp (AvailTC n ns) (AvailTC m ms) = (n `stableNameCmp` m) `thenCmp`
- (cmpList stableNameCmp ns ms)
-stableAvailCmp (AvailTC {}) (Avail {}) = GT
-\end{code}
\begin{code}
-- | Creates cached lookup for the 'mi_fix_fn' field of 'ModIface'
diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs
index 3e763d55eb..47beb275e3 100644
--- a/compiler/main/InteractiveEval.hs
+++ b/compiler/main/InteractiveEval.hs
@@ -49,6 +49,7 @@ import Var
import Id
import Name hiding ( varName )
import NameSet
+import Avail
import RdrName
import PrelNames (pRELUDE)
import VarSet
diff --git a/compiler/main/TidyPgm.lhs b/compiler/main/TidyPgm.lhs
index 050931c813..2d90c2c334 100644
--- a/compiler/main/TidyPgm.lhs
+++ b/compiler/main/TidyPgm.lhs
@@ -31,8 +31,9 @@ import Demand
import BasicTypes
import Name hiding (varName)
import NameSet
-import IfaceEnv
import NameEnv
+import Avail
+import IfaceEnv
import TcType
import DataCon
import TyCon
diff --git a/compiler/prelude/PrelInfo.lhs b/compiler/prelude/PrelInfo.lhs
index f99f9ca292..5c02313965 100644
--- a/compiler/prelude/PrelInfo.lhs
+++ b/compiler/prelude/PrelInfo.lhs
@@ -22,21 +22,20 @@ module PrelInfo (
#include "HsVersions.h"
-import PrelNames ( basicKnownKeyNames,
- hasKey, charDataConKey, intDataConKey,
- numericClassKeys, standardClassKeys )
+import PrelNames
import PrelRules
-import PrimOp ( PrimOp, allThePrimOps, primOpTag, maxPrimOpTag )
-import DataCon ( DataCon )
-import Id ( Id, idName )
-import MkId -- All of it, for re-export
-import TysPrim ( primTyCons )
-import TysWiredIn ( wiredInTyCons )
-import HscTypes ( TyThing(..), implicitTyThings, AvailInfo(..), IfaceExport )
-import Class ( Class, classKey )
-import Type ( funTyCon )
-import TyCon ( tyConName )
-import Util ( isIn )
+import Avail
+import PrimOp
+import DataCon
+import Id
+import MkId
+import TysPrim
+import TysWiredIn
+import HscTypes
+import Class
+import Type
+import TyCon
+import Util
import Data.Array
\end{code}
diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.lhs
index 5fd0f1cc0c..ad46cb038b 100644
--- a/compiler/rename/RnBinds.lhs
+++ b/compiler/rename/RnBinds.lhs
@@ -29,16 +29,13 @@ import HsSyn
import RnHsSyn
import TcRnMonad
import RnTypes ( rnIPName, rnHsSigType, rnLHsType, checkPrecMatch )
-import RnPat (rnPats, rnBindPat,
- NameMaker, localRecNameMaker, topRecNameMaker, applyNameMaker
- )
-
+import RnPat
import RnEnv
import DynFlags
import Name
import NameEnv
import NameSet
-import RdrName ( RdrName, rdrNameOcc )
+import RdrName ( RdrName, rdrNameOcc )
import SrcLoc
import ListSetOps ( findDupsEq )
import BasicTypes ( RecFlag(..) )
diff --git a/compiler/rename/RnEnv.lhs b/compiler/rename/RnEnv.lhs
index cfdeab29c9..9771ab16a8 100644
--- a/compiler/rename/RnEnv.lhs
+++ b/compiler/rename/RnEnv.lhs
@@ -36,17 +36,18 @@ module RnEnv (
#include "HsVersions.h"
import LoadIface ( loadInterfaceForName, loadSrcInterface )
-import IfaceEnv ( lookupOrig, newGlobalBinder, updNameCache, extendNameCache )
+import IfaceEnv
import HsSyn
import RdrHsSyn ( extractHsTyRdrTyVars )
import RdrName
-import HscTypes ( NameCache(..), availNames, ModIface(..), FixItem(..), lookupFixity)
+import HscTypes
import TcEnv ( tcLookupDataCon, tcLookupField, isBrackStage )
import TcRnMonad
import Id ( isRecordSelector )
import Name
import NameSet
import NameEnv
+import Avail
import Module ( ModuleName, moduleName )
import UniqFM
import DataCon ( dataConFieldLabels )
diff --git a/compiler/rename/RnNames.lhs b/compiler/rename/RnNames.lhs
index 574550f1ff..ce14ad258f 100644
--- a/compiler/rename/RnNames.lhs
+++ b/compiler/rename/RnNames.lhs
@@ -25,6 +25,7 @@ import Module
import Name
import NameEnv
import NameSet
+import Avail
import HscTypes
import RdrName
import Outputable
diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs
index 0a3d3ffc25..1d7e956dae 100644
--- a/compiler/rename/RnSource.lhs
+++ b/compiler/rename/RnSource.lhs
@@ -20,11 +20,9 @@ import RdrName
import RdrHsSyn ( extractHsRhoRdrTyVars )
import RnHsSyn
import RnTypes
-import RnBinds ( rnTopBindsLHS, rnTopBindsRHS, rnMethodBinds,
- renameSigs, mkSigTvFn, makeMiniFixityEnv )
+import RnBinds
import RnEnv
-import RnNames ( getLocalNonValBinders, extendGlobalRdrEnvRn, lookupTcdName )
-import HscTypes ( AvailInfo(..) )
+import RnNames
import RnHsDoc ( rnHsDoc, rnMbLHsDoc )
import TcRnMonad
import Kind ( liftedTypeKind )
@@ -33,9 +31,10 @@ import ForeignCall ( CCallTarget(..) )
import Module
import HscTypes ( Warnings(..), plusWarns )
import Class ( FunDep )
-import Name ( Name, nameOccName )
+import Name
import NameSet
import NameEnv
+import Avail
import Outputable
import Bag
import FastString
diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
index 21b71b2c6a..ed05220d64 100644
--- a/compiler/typecheck/TcRnDriver.lhs
+++ b/compiler/typecheck/TcRnDriver.lhs
@@ -66,6 +66,7 @@ import UniqFM
import Name
import NameEnv
import NameSet
+import Avail
import TyCon
import SrcLoc
import HscTypes
diff --git a/compiler/typecheck/TcRnTypes.lhs b/compiler/typecheck/TcRnTypes.lhs
index 58c3aa6a43..937cbac53b 100644
--- a/compiler/typecheck/TcRnTypes.lhs
+++ b/compiler/typecheck/TcRnTypes.lhs
@@ -76,6 +76,7 @@ import RdrName
import Name
import NameEnv
import NameSet
+import Avail
import Var
import VarEnv
import Module
diff --git a/compiler/typecheck/TcTyDecls.lhs b/compiler/typecheck/TcTyDecls.lhs
index 02ac0b824b..4314fb5d9f 100644
--- a/compiler/typecheck/TcTyDecls.lhs
+++ b/compiler/typecheck/TcTyDecls.lhs
@@ -26,6 +26,7 @@ import DataCon
import Name
import NameEnv
import NameSet
+import Avail
import Digraph
import BasicTypes
import SrcLoc