[project @ 2000-04-03 09:52:28 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / BasicTypes.lhs
index 5625103..9641a04 100644 (file)
@@ -14,16 +14,29 @@ types that
 
 \begin{code}
 module BasicTypes(
-       Version, Arity, 
+       Version,
+
+       Arity, 
+
        Unused, unused,
-       Fixity(..), FixityDirection(..), StrictnessMark(..),
-       NewOrData(..), TopLevelFlag(..), RecFlag(..)
+
+       Fixity(..), FixityDirection(..),
+       defaultFixity, maxPrecedence, negateFixity, negatePrecedence,
+
+       NewOrData(..), 
+
+       RecFlag(..), isRec, isNonRec,
+
+       TopLevelFlag(..), isTopLevel, isNotTopLevel,
+
+       OccInfo(..), seqOccInfo, isFragileOccInfo,
+       InsideLam, insideLam, notInsideLam,
+       OneBranch, oneBranch, notOneBranch
+
    ) where
 
 #include "HsVersions.h"
 
-import {-# SOURCE #-} DataCon ( DataCon )
-import {-# SOURCE #-} Type    ( Type )
 import Outputable
 \end{code}
 
@@ -86,6 +99,15 @@ instance Outputable FixityDirection where
 
 instance Eq Fixity where               -- Used to determine if two fixities conflict
   (Fixity p1 dir1) == (Fixity p2 dir2) = p1==p2 && dir1 == dir2
+
+maxPrecedence = (9::Int)
+defaultFixity = Fixity maxPrecedence InfixL
+
+negateFixity :: Fixity
+negateFixity     = Fixity negatePrecedence InfixL      -- Precedence of unary negate is wired in as infixl 6!
+
+negatePrecedence :: Int
+negatePrecedence = 6
 \end{code}
 
 
@@ -99,7 +121,6 @@ instance Eq Fixity where             -- Used to determine if two fixities conflict
 data NewOrData
   = NewType    -- "newtype Blah ..."
   | DataType   -- "data Blah ..."
-  | EnumType   -- Enumeration; all constructors are nullary
   deriving( Eq )       -- Needed because Demand derives Eq
 \end{code}
 
@@ -113,6 +134,14 @@ data NewOrData
 data TopLevelFlag
   = TopLevel
   | NotTopLevel
+
+isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
+
+isNotTopLevel NotTopLevel = True
+isNotTopLevel TopLevel    = False
+
+isTopLevel TopLevel    = True
+isTopLevel NotTopLevel  = False
 \end{code}
 
 %************************************************************************
@@ -124,16 +153,73 @@ data TopLevelFlag
 \begin{code} 
 data RecFlag = Recursive 
             | NonRecursive
+
+isRec :: RecFlag -> Bool
+isRec Recursive    = True
+isRec NonRecursive = False
+
+isNonRec :: RecFlag -> Bool
+isNonRec Recursive    = False
+isNonRec NonRecursive = True
 \end{code}
 
+
 %************************************************************************
 %*                                                                     *
-\subsection{Strictness indication}
+\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 StrictnessMark = MarkedStrict
-                   | MarkedUnboxed DataCon [Type]
-                   | NotMarkedStrict
+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
+
+isFragileOccInfo :: OccInfo -> Bool
+isFragileOccInfo (OneOcc _ _) = True
+isFragileOccInfo 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}
+