X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fmain%2FHscTypes.lhs;h=63f80de3fa8a63db4119eb36c6f556a3831b7887;hb=1b91b7e5adb10bb9d9c6bfe6112f3ef03ab47e31;hp=9ebbbeefdc6477ea9f5b7e6e62c2d2b8913e157a;hpb=90fecc3bb3600fc28662d090cb2218032689ed21;p=ghc-hetmet.git diff --git a/ghc/compiler/main/HscTypes.lhs b/ghc/compiler/main/HscTypes.lhs index 9ebbbee..63f80de 100644 --- a/ghc/compiler/main/HscTypes.lhs +++ b/ghc/compiler/main/HscTypes.lhs @@ -8,18 +8,25 @@ module HscTypes ( ModDetails(..), GlobalSymbolTable, HomeSymbolTable, PackageSymbolTable, - TyThing(..), lookupTypeEnv, + TyThing(..), groupTyThings, - WhetherHasOrphans, ImportVersion, ExportItem, + TypeEnv, extendTypeEnv, lookupTypeEnv, + + lookupFixityEnv, + + WhetherHasOrphans, ImportVersion, ExportItem, WhatsImported(..), PersistentRenamerState(..), IsBootInterface, Avails, DeclsMap, - IfaceInsts, IfaceRules, DeprecationEnv, OrigNameEnv, + IfaceInsts, IfaceRules, DeprecationEnv, + OrigNameEnv(..), OrigNameNameEnv, OrigNameIParamEnv, AvailEnv, AvailInfo, GenAvailInfo(..), PersistentCompilerState(..), - InstEnv, + InstEnv, ClsInstEnv, DFunId, GlobalRdrEnv, RdrAvailInfo, + CompResult(..), HscResult(..), + -- Provenance Provenance(..), ImportReason(..), PrintUnqualified, pprNameProvenance, hasBetterProv @@ -49,6 +56,7 @@ import ErrUtils ( ErrMsg, WarnMsg ) import CmLink ( Linkable ) import RdrHsSyn ( RdrNameInstDecl, RdrNameRuleDecl, RdrNameHsDecl, RdrNameDeprecation, RdrNameFixitySig ) +import InterpSyn ( UnlinkedIBind ) import UniqSupply ( UniqSupply ) import HsDecls ( DeprecTxt ) import CoreSyn ( CoreRule ) @@ -58,6 +66,7 @@ import VarSet ( TyVarSet ) import Panic ( panic ) import Outputable import SrcLoc ( SrcLoc, isGoodSrcLoc ) +import Util ( thenCmp ) \end{code} %************************************************************************ @@ -66,27 +75,54 @@ import SrcLoc ( SrcLoc, isGoodSrcLoc ) %* * %************************************************************************ -A @ModDetails@ summarises everything we know about a compiled module. +A @ModIface@ plus a @ModDetails@ summarises everything we know +about a compiled module. The @ModIface@ is the stuff *before* linking, +and can be written out to an interface file. The @ModDetails@ is after +linking; it is the "linked" form of the mi_decls field. \begin{code} data ModDetails = ModDetails { - md_id :: Module, - md_exports :: Avails, -- What it exports - md_version :: VersionInfo, - md_globals :: GlobalRdrEnv, -- Its top level environment + md_module :: Module, -- Complete with package info + md_version :: VersionInfo, -- Module version number + md_orphan :: WhetherHasOrphans, -- Whether this module has orphans + md_usages :: [ImportVersion Name], -- Usages - md_fixities :: NameEnv Fixity, - md_deprecs :: NameEnv DeprecTxt, - md_types :: TypeEnv, + md_exports :: Avails, -- What it exports + md_globals :: GlobalRdrEnv, -- Its top level environment + md_fixities :: NameEnv Fixity, -- Fixities + md_deprecs :: NameEnv DeprecTxt, -- Deprecations + + -- The next three fields are created by the typechecker + md_types :: TypeEnv, md_insts :: [DFunId], -- Dfun-ids for the instances in this module - md_rules :: RuleEnv -- Domain may include Id from other modules + md_rules :: RuleEnv -- Domain may include Ids from other modules } +-- ModIFace is nearly the same as RnMonad.ParsedIface. +-- Right now it's identical :) +data ModIFace + = ModIFace { + mi_mod :: Module, -- Complete with package info + mi_vers :: Version, -- Module version number + mi_orphan :: WhetherHasOrphans, -- Whether this module has orphans + mi_usages :: [ImportVersion OccName], -- Usages + mi_exports :: [ExportItem], -- Exports + mi_insts :: [RdrNameInstDecl], -- Local instance declarations + mi_decls :: [(Version, RdrNameHsDecl)], -- Local definitions + mi_fixity :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, + -- with their version + mi_rules :: (Version, [RdrNameRuleDecl]), -- Rules, with their version + mi_deprecs :: [RdrNameDeprecation] -- Deprecations + } + +\end{code} + +\begin{code} emptyModDetails :: Module -> ModDetails emptyModDetails mod - = ModDetails { md_id = mod, + = ModDetails { md_module = mod, md_exports = [], md_globals = emptyRdrEnv, md_fixities = emptyNameEnv, @@ -187,8 +223,8 @@ but they are mostly elaborated elsewhere \begin{code} data VersionInfo = VersionInfo { - modVers :: Version, - fixVers :: Version, + modVers :: Version, + fixVers :: Version, ruleVers :: Version, declVers :: NameEnv Version } @@ -230,23 +266,6 @@ type AvailEnv = NameEnv AvailInfo -- Maps a Name to the AvailInfo that contain %************************************************************************ \begin{code} --- ModIFace is nearly the same as RnMonad.ParsedIface. --- Right now it's identical :) -data ModIFace - = ModIFace { - mi_mod :: Module, -- Complete with package info - mi_vers :: Version, -- Module version number - mi_orphan :: WhetherHasOrphans, -- Whether this module has orphans - mi_usages :: [ImportVersion OccName], -- Usages - mi_exports :: [ExportItem], -- Exports - mi_insts :: [RdrNameInstDecl], -- Local instance declarations - mi_decls :: [(Version, RdrNameHsDecl)], -- Local definitions - mi_fixity :: (Version, [RdrNameFixitySig]), -- Local fixity declarations, - -- with their version - mi_rules :: (Version, [RdrNameRuleDecl]), -- Rules, with their version - mi_deprecs :: [RdrNameDeprecation] -- Deprecations - } - type ExportItem = (ModuleName, [RdrAvailInfo]) type ImportVersion name = (ModuleName, WhetherHasOrphans, IsBootInterface, WhatsImported name) @@ -347,9 +366,14 @@ we just store junk. Then when we find the binding site, we fix it up. \begin{code} data OrigNameEnv - = Orig { origNames :: FiniteMap (ModuleName,OccName) Name, -- Ensures that one original name gets one unique - origIParam :: FiniteMap OccName Name -- Ensures that one implicit parameter name gets one unique + = Orig { origNames :: OrigNameNameEnv, + -- Ensures that one original name gets one unique + origIParam :: OrigNameIParamEnv + -- Ensures that one implicit parameter name gets one unique } + +type OrigNameNameEnv = FiniteMap (ModuleName,OccName) Name +type OrigNameIParamEnv = FiniteMap OccName Name \end{code} @@ -398,14 +422,14 @@ data HscResult (Maybe ModIFace) -- new iface (if any compilation was done) (Maybe String) -- generated stub_h filename (in /tmp) (Maybe String) -- generated stub_c filename (in /tmp) + (Maybe [UnlinkedIBind]) -- interpreted code, if any PersistentCompilerState -- updated PCS - [SDoc] -- warnings + (Bag WarnMsg) -- warnings | HscErrs PersistentCompilerState -- updated PCS - [SDoc] -- errors - [SDoc] -- warnings + (Bag ErrMsg) -- errors + (Bag WarnMsg) -- warnings - -- These two are only here to avoid recursion between CmCompile and -- CompManager. They really ought to be in the latter. type ModuleEnv a = UniqFM a -- Domain is Module @@ -440,6 +464,29 @@ data Provenance ImportReason PrintUnqualified +-- Just used for grouping error messages (in RnEnv.warnUnusedBinds) +instance Eq Provenance where + p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False + +instance Eq ImportReason where + p1 == p2 = case p1 `compare` p2 of EQ -> True; _ -> False + +instance Ord Provenance where + compare LocalDef LocalDef = EQ + compare LocalDef (NonLocalDef _ _) = LT + compare (NonLocalDef _ _) LocalDef = GT + + compare (NonLocalDef reason1 _) (NonLocalDef reason2 _) + = compare reason1 reason2 + +instance Ord ImportReason where + compare ImplicitImport ImplicitImport = EQ + compare ImplicitImport (UserImport _ _ _) = LT + compare (UserImport _ _ _) ImplicitImport = GT + compare (UserImport m1 loc1 _) (UserImport m2 loc2 _) + = (m1 `compare` m2) `thenCmp` (loc1 `compare` loc2) + + {- Moved here from Name. pp_prov (LocalDef _ Exported) = char 'x'