summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorIan Lynagh <ian@well-typed.com>2012-11-02 12:48:43 +0000
committerIan Lynagh <ian@well-typed.com>2012-11-02 15:26:07 +0000
commit7c4157a53e6dbdecdb859f287f6a31f4e32e0dad (patch)
tree2a9bf14667a5a649f426793428775f01313f405c /compiler
parent095b9bf4ed418c43216cfca2ae271c143e555f1d (diff)
downloadhaskell-7c4157a53e6dbdecdb859f287f6a31f4e32e0dad.tar.gz
Whitespace only in basicTypes/Name.lhs
Diffstat (limited to 'compiler')
-rw-r--r--compiler/basicTypes/Name.lhs265
1 files changed, 129 insertions, 136 deletions
diff --git a/compiler/basicTypes/Name.lhs b/compiler/basicTypes/Name.lhs
index 32813e8ac3..281ae938ed 100644
--- a/compiler/basicTypes/Name.lhs
+++ b/compiler/basicTypes/Name.lhs
@@ -5,13 +5,6 @@
\section[Name]{@Name@: to transmit name info from renamer to typechecker}
\begin{code}
-{-# OPTIONS -fno-warn-tabs #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and
--- detab the module (please do the detabbing in a separate patch). See
--- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
--- for details
-
-- |
-- #name_types#
-- GHC uses several kinds of name internally:
@@ -39,42 +32,42 @@
-- Names are system names, if they are names manufactured by the compiler
module Name (
- -- * The main types
- Name, -- Abstract
- BuiltInSyntax(..),
-
- -- ** Creating 'Name's
- mkSystemName, mkSystemNameAt,
- mkInternalName, mkClonedInternalName, mkDerivedInternalName,
- mkSystemVarName, mkSysTvName,
+ -- * The main types
+ Name, -- Abstract
+ BuiltInSyntax(..),
+
+ -- ** Creating 'Name's
+ mkSystemName, mkSystemNameAt,
+ mkInternalName, mkClonedInternalName, mkDerivedInternalName,
+ mkSystemVarName, mkSysTvName,
mkFCallName,
mkExternalName, mkWiredInName,
- -- ** Manipulating and deconstructing 'Name's
- nameUnique, setNameUnique,
- nameOccName, nameModule, nameModule_maybe,
- tidyNameOcc,
- hashName, localiseName,
+ -- ** Manipulating and deconstructing 'Name's
+ nameUnique, setNameUnique,
+ nameOccName, nameModule, nameModule_maybe,
+ tidyNameOcc,
+ hashName, localiseName,
mkLocalisedOccName,
- nameSrcLoc, nameSrcSpan, pprNameDefnLoc, pprDefinedAt,
+ nameSrcLoc, nameSrcSpan, pprNameDefnLoc, pprDefinedAt,
- -- ** Predicates on 'Name's
- isSystemName, isInternalName, isExternalName,
- isTyVarName, isTyConName, isDataConName,
- isValName, isVarName,
- isWiredInName, isBuiltInSyntax,
- wiredInNameTyThing_maybe,
- nameIsLocalOrFrom, stableNameCmp,
+ -- ** Predicates on 'Name's
+ isSystemName, isInternalName, isExternalName,
+ isTyVarName, isTyConName, isDataConName,
+ isValName, isVarName,
+ isWiredInName, isBuiltInSyntax,
+ wiredInNameTyThing_maybe,
+ nameIsLocalOrFrom, stableNameCmp,
- -- * Class 'NamedThing' and overloaded friends
- NamedThing(..),
- getSrcLoc, getSrcSpan, getOccString,
+ -- * Class 'NamedThing' and overloaded friends
+ NamedThing(..),
+ getSrcLoc, getSrcSpan, getOccString,
- pprInfixName, pprPrefixName, pprModulePrefix,
+ pprInfixName, pprPrefixName, pprModulePrefix,
- -- Re-export the OccName stuff
- module OccName
+ -- Re-export the OccName stuff
+ module OccName
) where
#include "Typeable.h"
@@ -97,21 +90,21 @@ import Data.Data
\end{code}
%************************************************************************
-%* *
+%* *
\subsection[Name-datatype]{The @Name@ datatype, and name construction}
-%* *
+%* *
%************************************************************************
-
+
\begin{code}
-- | A unique, unambigious name for something, containing information about where
-- that thing originated.
data Name = Name {
- n_sort :: NameSort, -- What sort of name it is
- n_occ :: !OccName, -- Its occurrence name
- n_uniq :: FastInt, -- UNPACK doesn't work, recursive type
+ n_sort :: NameSort, -- What sort of name it is
+ n_occ :: !OccName, -- Its occurrence name
+ n_uniq :: FastInt, -- UNPACK doesn't work, recursive type
--(note later when changing Int# -> FastInt: is that still true about UNPACK?)
- n_loc :: !SrcSpan -- Definition site
- }
+ n_loc :: !SrcSpan -- Definition site
+ }
deriving Typeable
-- NOTE: we make the n_loc field strict to eliminate some potential
@@ -120,17 +113,17 @@ data Name = Name {
data NameSort
= External Module
-
+
| WiredIn Module TyThing BuiltInSyntax
- -- A variant of External, for wired-in things
+ -- A variant of External, for wired-in things
- | Internal -- A user-defined Id or TyVar
- -- defined in the module being compiled
+ | Internal -- A user-defined Id or TyVar
+ -- defined in the module being compiled
- | System -- A system-defined Id or TyVar. Typically the
- -- OccName is very uninformative (like 's')
+ | System -- A system-defined Id or TyVar. Typically the
+ -- OccName is very uninformative (like 's')
--- | BuiltInSyntax is for things like @(:)@, @[]@ and tuples,
+-- | BuiltInSyntax is for things like @(:)@, @[]@ and tuples,
-- which have special syntactic forms. They aren't in scope
-- as such.
data BuiltInSyntax = BuiltInSyntax | UserSyntax
@@ -138,7 +131,7 @@ data BuiltInSyntax = BuiltInSyntax | UserSyntax
Notes about the NameSorts:
-1. Initially, top-level Ids (including locally-defined ones) get External names,
+1. Initially, top-level Ids (including locally-defined ones) get External names,
and all other local Ids get Internal names
2. Things with a External name are given C static labels, so they finally
@@ -150,8 +143,8 @@ Notes about the NameSorts:
is changed to Internal, and a Internal that is visible is changed to External
4. A System Name differs in the following ways:
- a) has unique attached when printing dumps
- b) unifier eliminates sys tyvars in favour of user provs where possible
+ a) has unique attached when printing dumps
+ b) unifier eliminates sys tyvars in favour of user provs where possible
Before anything gets printed in interface files or output code, it's
fed through a 'tidy' processor, which zaps the OccNames to have
@@ -161,9 +154,9 @@ Notes about the NameSorts:
Built-in syntax => It's a syntactic form, not "in scope" (e.g. [])
-Wired-in thing => The thing (Id, TyCon) is fully known to the compiler,
- not read from an interface file.
- E.g. Bool, True, Int, Float, and many others
+Wired-in thing => The thing (Id, TyCon) is fully known to the compiler,
+ not read from an interface file.
+ E.g. Bool, True, Int, Float, and many others
All built-in syntax is for wired-in things.
@@ -171,11 +164,11 @@ All built-in syntax is for wired-in things.
instance HasOccName Name where
occName = nameOccName
-nameUnique :: Name -> Unique
-nameOccName :: Name -> OccName
-nameModule :: Name -> Module
-nameSrcLoc :: Name -> SrcLoc
-nameSrcSpan :: Name -> SrcSpan
+nameUnique :: Name -> Unique
+nameOccName :: Name -> OccName
+nameModule :: Name -> Module
+nameSrcLoc :: Name -> SrcLoc
+nameSrcSpan :: Name -> SrcSpan
nameUnique name = mkUniqueGrimily (iBox (n_uniq name))
nameOccName name = n_occ name
@@ -184,17 +177,17 @@ nameSrcSpan name = n_loc name
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{Predicates on names}
-%* *
+%* *
%************************************************************************
\begin{code}
nameIsLocalOrFrom :: Module -> Name -> Bool
-isInternalName :: Name -> Bool
-isExternalName :: Name -> Bool
-isSystemName :: Name -> Bool
-isWiredInName :: Name -> Bool
+isInternalName :: Name -> Bool
+isExternalName :: Name -> Bool
+isSystemName :: Name -> Bool
+isWiredInName :: Name -> Bool
isWiredInName (Name {n_sort = WiredIn _ _ _}) = True
isWiredInName _ = False
@@ -221,7 +214,7 @@ nameModule_maybe _ = Nothing
nameIsLocalOrFrom from name
| isExternalName name = from == nameModule name
- | otherwise = True
+ | otherwise = True
isTyVarName :: Name -> Bool
isTyVarName name = isTvOcc (nameOccName name)
@@ -244,9 +237,9 @@ isSystemName _ = False
%************************************************************************
-%* *
+%* *
\subsection{Making names}
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -257,12 +250,12 @@ mkInternalName uniq occ loc = Name { n_uniq = getKeyFastInt uniq
, n_sort = Internal
, n_occ = occ
, n_loc = loc }
- -- NB: You might worry that after lots of huffing and
- -- puffing we might end up with two local names with distinct
- -- uniques, but the same OccName. Indeed we can, but that's ok
- -- * the insides of the compiler don't care: they use the Unique
- -- * when printing for -ddump-xxx you can switch on -dppr-debug to get the
- -- uniques if you get confused
+ -- NB: You might worry that after lots of huffing and
+ -- puffing we might end up with two local names with distinct
+ -- uniques, but the same OccName. Indeed we can, but that's ok
+ -- * the insides of the compiler don't care: they use the Unique
+ -- * when printing for -ddump-xxx you can switch on -dppr-debug to get the
+ -- uniques if you get confused
-- * for interface files we tidyCore first, which makes
-- the OccNames distinct when they need to be
@@ -278,7 +271,7 @@ mkDerivedInternalName derive_occ uniq (Name { n_occ = occ, n_loc = loc })
-- | Create a name which definitely originates in the given module
mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name
-mkExternalName uniq mod occ loc
+mkExternalName uniq mod occ loc
= Name { n_uniq = getKeyFastInt uniq, n_sort = External mod,
n_occ = occ, n_loc = loc }
@@ -286,16 +279,16 @@ mkExternalName uniq mod occ loc
mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
mkWiredInName mod occ uniq thing built_in
= Name { n_uniq = getKeyFastInt uniq,
- n_sort = WiredIn mod thing built_in,
- n_occ = occ, n_loc = wiredInSrcSpan }
+ n_sort = WiredIn mod thing built_in,
+ n_occ = occ, n_loc = wiredInSrcSpan }
-- | Create a name brought into being by the compiler
mkSystemName :: Unique -> OccName -> Name
mkSystemName uniq occ = mkSystemNameAt uniq occ noSrcSpan
mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
-mkSystemNameAt uniq occ loc = Name { n_uniq = getKeyFastInt uniq, n_sort = System
- , n_occ = occ, n_loc = loc }
+mkSystemNameAt uniq occ loc = Name { n_uniq = getKeyFastInt uniq, n_sort = System
+ , n_occ = occ, n_loc = loc }
mkSystemVarName :: Unique -> FastString -> Name
mkSystemVarName uniq fs = mkSystemName uniq (mkVarOccFS fs)
@@ -321,7 +314,7 @@ tidyNameOcc :: Name -> OccName -> Name
-- In doing so, we change System --> Internal, so that when we print
-- it we don't get the unique by default. It's tidy now!
tidyNameOcc name@(Name { n_sort = System }) occ = name { n_occ = occ, n_sort = Internal}
-tidyNameOcc name occ = name { n_occ = occ }
+tidyNameOcc name occ = name { n_occ = occ }
-- | Make the 'Name' into an internal name, regardless of what it was to begin with
localiseName :: Name -> Name
@@ -329,30 +322,30 @@ localiseName n = n { n_sort = Internal }
\end{code}
\begin{code}
--- |Create a localised variant of a name.
+-- |Create a localised variant of a name.
--
-- If the name is external, encode the original's module name to disambiguate.
--
mkLocalisedOccName :: Module -> (Maybe String -> OccName -> OccName) -> Name -> OccName
mkLocalisedOccName this_mod mk_occ name = mk_occ origin (nameOccName name)
where
- origin
+ origin
| nameIsLocalOrFrom this_mod name = Nothing
| otherwise = Just (moduleNameColons . moduleName . nameModule $ name)
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{Hashing and comparison}
-%* *
+%* *
%************************************************************************
\begin{code}
-hashName :: Name -> Int -- ToDo: should really be Word
+hashName :: Name -> Int -- ToDo: should really be Word
hashName name = getKey (nameUnique name) + 1
- -- The +1 avoids keys with lots of zeros in the ls bits, which
- -- interacts badly with the cheap and cheerful multiplication in
- -- hashExpr
+ -- The +1 avoids keys with lots of zeros in the ls bits, which
+ -- interacts badly with the cheap and cheerful multiplication in
+ -- hashExpr
cmpName :: Name -> Name -> Ordering
cmpName n1 n2 = iBox (n_uniq n1) `compare` iBox (n_uniq n2)
@@ -360,7 +353,7 @@ cmpName n1 n2 = iBox (n_uniq n1) `compare` iBox (n_uniq n2)
stableNameCmp :: Name -> Name -> Ordering
-- Compare lexicographically
stableNameCmp (Name { n_sort = s1, n_occ = occ1 })
- (Name { n_sort = s2, n_occ = occ2 })
+ (Name { n_sort = s2, n_occ = occ2 })
= (s1 `sort_cmp` s2) `thenCmp` (occ1 `compare` occ2)
-- The ordinary compare on OccNames is lexicogrpahic
where
@@ -379,9 +372,9 @@ stableNameCmp (Name { n_sort = s1, n_occ = occ1 })
\end{code}
%************************************************************************
-%* *
+%* *
\subsection[Name-instances]{Instance declarations}
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -391,9 +384,9 @@ instance Eq Name where
instance Ord Name where
a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
- a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
+ a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
- a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
+ a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
compare a b = cmpName a b
instance Uniquable Name where
@@ -410,15 +403,15 @@ instance Data Name where
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{Binary}
-%* *
+%* *
%************************************************************************
\begin{code}
instance Binary Name where
put_ bh name =
- case getUserData bh of
+ case getUserData bh of
UserData{ ud_put_name = put_name } -> put_name bh name
get bh =
@@ -427,9 +420,9 @@ instance Binary Name where
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{Pretty printing}
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -448,20 +441,20 @@ pprName n@(Name {n_sort = sort, n_uniq = u, n_occ = occ})
case sort of
WiredIn mod _ builtin -> pprExternal sty uniq mod occ n True builtin
External mod -> pprExternal sty uniq mod occ n False UserSyntax
- System -> pprSystem sty uniq occ
- Internal -> pprInternal sty uniq occ
+ System -> pprSystem sty uniq occ
+ Internal -> pprInternal sty uniq occ
where uniq = mkUniqueGrimily (iBox u)
pprExternal :: PprStyle -> Unique -> Module -> OccName -> Name -> Bool -> BuiltInSyntax -> SDoc
pprExternal sty uniq mod occ name is_wired is_builtin
| codeStyle sty = ppr mod <> char '_' <> ppr_z_occ_name occ
- -- In code style, always qualify
- -- ToDo: maybe we could print all wired-in things unqualified
- -- in code style, to reduce symbol table bloat?
+ -- In code style, always qualify
+ -- ToDo: maybe we could print all wired-in things unqualified
+ -- in code style, to reduce symbol table bloat?
| debugStyle sty = pp_mod <> ppr_occ_name occ
- <> braces (hsep [if is_wired then ptext (sLit "(w)") else empty,
- pprNameSpaceBrief (occNameSpace occ),
- pprUnique uniq])
+ <> braces (hsep [if is_wired then ptext (sLit "(w)") else empty,
+ pprNameSpaceBrief (occNameSpace occ),
+ pprUnique uniq])
| BuiltInSyntax <- is_builtin = ppr_occ_name occ -- Never qualify builtin syntax
| otherwise = pprModulePrefix sty mod name <> ppr_occ_name occ
where
@@ -473,23 +466,23 @@ pprExternal sty uniq mod occ name is_wired is_builtin
pprInternal :: PprStyle -> Unique -> OccName -> SDoc
pprInternal sty uniq occ
| codeStyle sty = pprUnique uniq
- | debugStyle sty = ppr_occ_name occ <> braces (hsep [pprNameSpaceBrief (occNameSpace occ),
- pprUnique uniq])
+ | debugStyle sty = ppr_occ_name occ <> braces (hsep [pprNameSpaceBrief (occNameSpace occ),
+ pprUnique uniq])
| dumpStyle sty = ppr_occ_name occ <> ppr_underscore_unique uniq
- -- For debug dumps, we're not necessarily dumping
- -- tidied code, so we need to print the uniques.
- | otherwise = ppr_occ_name occ -- User style
+ -- For debug dumps, we're not necessarily dumping
+ -- tidied code, so we need to print the uniques.
+ | otherwise = ppr_occ_name occ -- User style
-- Like Internal, except that we only omit the unique in Iface style
pprSystem :: PprStyle -> Unique -> OccName -> SDoc
pprSystem sty uniq occ
| codeStyle sty = pprUnique uniq
| debugStyle sty = ppr_occ_name occ <> ppr_underscore_unique uniq
- <> braces (pprNameSpaceBrief (occNameSpace occ))
- | otherwise = ppr_occ_name occ <> ppr_underscore_unique uniq
- -- If the tidy phase hasn't run, the OccName
- -- is unlikely to be informative (like 's'),
- -- so print the unique
+ <> braces (pprNameSpaceBrief (occNameSpace occ))
+ | otherwise = ppr_occ_name occ <> ppr_underscore_unique uniq
+ -- If the tidy phase hasn't run, the OccName
+ -- is unlikely to be informative (like 's'),
+ -- so print the unique
pprModulePrefix :: PprStyle -> Module -> Name -> SDoc
@@ -500,7 +493,7 @@ pprModulePrefix sty mod name = sdocWithDynFlags $ \dflags ->
then empty
else
case qualName sty name of -- See Outputable.QualifyName:
- NameQual modname -> ppr modname <> dot -- Name is in scope
+ NameQual modname -> ppr modname <> dot -- Name is in scope
NameNotInScope1 -> ppr mod <> dot -- Not in scope
NameNotInScope2 -> ppr (modulePackageId mod) <> colon -- Module not in
<> ppr (moduleName mod) <> dot -- scope eithber
@@ -517,39 +510,39 @@ ppr_underscore_unique uniq
ppr_occ_name :: OccName -> SDoc
ppr_occ_name occ = ftext (occNameFS occ)
- -- Don't use pprOccName; instead, just print the string of the OccName;
- -- we print the namespace in the debug stuff above
+ -- Don't use pprOccName; instead, just print the string of the OccName;
+ -- we print the namespace in the debug stuff above
-- In code style, we Z-encode the strings. The results of Z-encoding each FastString are
-- cached behind the scenes in the FastString implementation.
ppr_z_occ_name :: OccName -> SDoc
ppr_z_occ_name occ = ztext (zEncodeFS (occNameFS occ))
--- Prints (if mod information is available) "Defined at <loc>" or
+-- Prints (if mod information is available) "Defined at <loc>" or
-- "Defined in <mod>" information for a Name.
pprDefinedAt :: Name -> SDoc
pprDefinedAt name = ptext (sLit "Defined") <+> pprNameDefnLoc name
pprNameDefnLoc :: Name -> SDoc
--- Prints "at <loc>" or
+-- Prints "at <loc>" or
-- or "in <mod>" depending on what info is available
-pprNameDefnLoc name
+pprNameDefnLoc name
= case nameSrcLoc name of
-- nameSrcLoc rather than nameSrcSpan
- -- It seems less cluttered to show a location
- -- rather than a span for the definition point
+ -- It seems less cluttered to show a location
+ -- rather than a span for the definition point
RealSrcLoc s -> ptext (sLit "at") <+> ppr s
UnhelpfulLoc s
| isInternalName name || isSystemName name
-> ptext (sLit "at") <+> ftext s
- | otherwise
+ | otherwise
-> ptext (sLit "in") <+> quotes (ppr (nameModule name))
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{Overloaded functions related to Names}
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -558,20 +551,20 @@ class NamedThing a where
getOccName :: a -> OccName
getName :: a -> Name
- getOccName n = nameOccName (getName n) -- Default method
+ getOccName n = nameOccName (getName n) -- Default method
\end{code}
\begin{code}
-getSrcLoc :: NamedThing a => a -> SrcLoc
-getSrcSpan :: NamedThing a => a -> SrcSpan
-getOccString :: NamedThing a => a -> String
+getSrcLoc :: NamedThing a => a -> SrcLoc
+getSrcSpan :: NamedThing a => a -> SrcSpan
+getOccString :: NamedThing a => a -> String
-getSrcLoc = nameSrcLoc . getName
-getSrcSpan = nameSrcSpan . getName
-getOccString = occNameString . getOccName
+getSrcLoc = nameSrcLoc . getName
+getSrcSpan = nameSrcSpan . getName
+getOccString = occNameString . getOccName
pprInfixName, pprPrefixName :: (Outputable a, NamedThing a) => a -> SDoc
--- See Outputable.pprPrefixVar, pprInfixVar;
+-- See Outputable.pprPrefixVar, pprInfixVar;
-- add parens or back-quotes as appropriate
pprInfixName n = pprInfixVar (isSymOcc (getOccName n)) (ppr n)
pprPrefixName n = pprPrefixVar (isSymOcc (getOccName n)) (ppr n)