X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FBasicTypes.lhs;h=b0100e659e06ea98439738f6e6047b8ca4a45514;hb=1bba522f5ec82c43abd2ba4e84127b9c915dd020;hp=ded171f06b9e21c3253d5683474f3a676a5a9951;hpb=123e3135b5f7c666f716a503e754aaf738e78ba6;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/BasicTypes.lhs b/ghc/compiler/basicTypes/BasicTypes.lhs index ded171f..b0100e6 100644 --- a/ghc/compiler/basicTypes/BasicTypes.lhs +++ b/ghc/compiler/basicTypes/BasicTypes.lhs @@ -14,13 +14,28 @@ types that \begin{code} module BasicTypes( - Version, Arity, + Version, bumpVersion, initialVersion, bogusVersion, + + Arity, + Unused, unused, + Fixity(..), FixityDirection(..), defaultFixity, maxPrecedence, negateFixity, negatePrecedence, + NewOrData(..), + RecFlag(..), isRec, isNonRec, - TopLevelFlag(..), isTopLevel, isNotTopLevel + + TopLevelFlag(..), isTopLevel, isNotTopLevel, + + Boxity(..), isBoxed, tupleParens, + + OccInfo(..), seqOccInfo, isFragileOcc, isDeadOcc, isLoopBreaker, + + InsideLam, insideLam, notInsideLam, + OneBranch, oneBranch, notOneBranch + ) where #include "HsVersions.h" @@ -63,6 +78,15 @@ type Arity = Int \begin{code} type Version = Int + +bogusVersion :: Version -- Shouldn't look at these +bogusVersion = error "bogusVersion" + +bumpVersion :: Version -> Version +bumpVersion v = v+1 + +initialVersion :: Version +initialVersion = 1 \end{code} @@ -109,7 +133,6 @@ negatePrecedence = 6 data NewOrData = NewType -- "newtype Blah ..." | DataType -- "data Blah ..." - | EnumType -- Enumeration; all constructors are nullary deriving( Eq ) -- Needed because Demand derives Eq \end{code} @@ -135,6 +158,28 @@ isTopLevel NotTopLevel = False %************************************************************************ %* * +\subsection[Top-level/local]{Top-level/not-top level flag} +%* * +%************************************************************************ + +\begin{code} +data Boxity + = Boxed + | Unboxed + deriving( Eq ) + +isBoxed :: Boxity -> Bool +isBoxed Boxed = True +isBoxed Unboxed = False + +tupleParens :: Boxity -> SDoc -> SDoc +tupleParens Boxed p = parens p +tupleParens Unboxed p = ptext SLIT("(#") <+> p <+> ptext SLIT("#)") +\end{code} + + +%************************************************************************ +%* * \subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag} %* * %************************************************************************ @@ -151,3 +196,72 @@ isNonRec :: RecFlag -> Bool isNonRec Recursive = False isNonRec NonRecursive = True \end{code} + + +%************************************************************************ +%* * +\subsection{Occurrence information} +%* * +%************************************************************************ + +This data type is used exclusively by the simplifier, but it appears in a +SubstResult, which is currently defined in VarEnv, which is pretty near +the base of the module hierarchy. So it seemed simpler to put the +defn of OccInfo here, safely at the bottom + +\begin{code} +data OccInfo + = NoOccInfo + + | IAmDead -- Marks unused variables. Sometimes useful for + -- lambda and case-bound variables. + + | OneOcc InsideLam + + OneBranch + + | IAmALoopBreaker -- Used by the occurrence analyser to mark loop-breakers + -- in a group of recursive definitions + +seqOccInfo :: OccInfo -> () +seqOccInfo (OneOcc in_lam once) = in_lam `seq` once `seq` () +seqOccInfo occ = () + +type InsideLam = Bool -- True <=> Occurs inside a non-linear lambda + -- Substituting a redex for this occurrence is + -- dangerous because it might duplicate work. +insideLam = True +notInsideLam = False + +type OneBranch = Bool -- True <=> Occurs in only one case branch + -- so no code-duplication issue to worry about +oneBranch = True +notOneBranch = False + +isLoopBreaker :: OccInfo -> Bool +isLoopBreaker IAmALoopBreaker = True +isLoopBreaker other = False + +isDeadOcc :: OccInfo -> Bool +isDeadOcc IAmDead = True +isDeadOcc other = False + +isFragileOcc :: OccInfo -> Bool +isFragileOcc (OneOcc _ _) = True +isFragileOcc other = False +\end{code} + +\begin{code} +instance Outputable OccInfo where + -- only used for debugging; never parsed. KSW 1999-07 + ppr NoOccInfo = empty + ppr IAmALoopBreaker = ptext SLIT("_Kx") + ppr IAmDead = ptext SLIT("_Kd") + ppr (OneOcc inside_lam one_branch) | inside_lam = ptext SLIT("_Kl") + | one_branch = ptext SLIT("_Ks") + | otherwise = ptext SLIT("_Ks*") + +instance Show OccInfo where + showsPrec p occ = showsPrecSDoc p (ppr occ) +\end{code} +