\begin{code}
module BasicTypes(
- Version, Arity,
+ Version,
+
+ Arity,
+
Unused, unused,
- Module, moduleString, pprModule,
- Fixity(..), FixityDirection(..), StrictnessMark(..),
- NewOrData(..), IfaceFlavour(..), 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"
Used as a placeholder in types.
\begin{code}
-type Unused = Void
+type Unused = ()
unused :: Unused
unused = error "Unused is used!"
%************************************************************************
%* *
-\subsection[Module]{The name of a module}
-%* *
-%************************************************************************
-
-\begin{code}
-type Module = FAST_STRING
-
-moduleString :: Module -> String
-moduleString mod = _UNPK_ mod
-
-pprModule :: Module -> SDoc
-pprModule m = ptext m
-\end{code}
-
-%************************************************************************
-%* *
-\subsection[IfaceFlavour]{IfaceFlavour}
-%* *
-%************************************************************************
-
-The IfaceFlavour type is used mainly in an imported Name's Provenance
-to say whether the name comes from a regular .hi file, or whether it comes
-from a hand-written .hi-boot file. This is important, because it has to be
-propagated. Suppose
-
- C.hs imports B
- B.hs imports A
- A.hs imports C {-# SOURCE -#} ( f )
-
-Then in A.hi we may mention C.f, in an inlining. When compiling B we *must not*
-read C.f's details from C.hi, even if the latter happens to exist from an earlier
-compilation run. So we use the name "C!f" in A.hi, and when looking for an interface
-file with details of C!f we look in C.hi-boot. The "!" stuff is recorded in the
-IfaceFlavour in the Name of C.f in A.
-
-Not particularly beautiful, but it works.
-
-\begin{code}
-data IfaceFlavour = HiFile -- The interface was read from a standard interface file
- | HiBootFile -- ... or from a handwritten "hi-boot" interface file
-
-instance Text IfaceFlavour where -- Just used in debug prints of lex tokens
- showsPrec n HiFile s = s
- showsPrec n HiBootFile s = "!" ++ s
-\end{code}
-
-
-%************************************************************************
-%* *
\subsection[Fixity]{Fixity info}
%* *
%************************************************************************
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}
data NewOrData
= NewType -- "newtype Blah ..."
| DataType -- "data Blah ..."
- | EnumType -- Enumeration; all constructors are nullary
deriving( Eq ) -- Needed because Demand derives Eq
\end{code}
-The @RecFlag@ tells whether the thing is part of a recursive group or not.
-
-
%************************************************************************
%* *
\subsection[Top-level/local]{Top-level/not-top level flag}
data TopLevelFlag
= TopLevel
| NotTopLevel
-\end{code}
+isTopLevel, isNotTopLevel :: TopLevelFlag -> Bool
+
+isNotTopLevel NotTopLevel = True
+isNotTopLevel TopLevel = False
+
+isTopLevel TopLevel = True
+isTopLevel NotTopLevel = False
+\end{code}
%************************************************************************
%* *
-\subsection[Top-level/local]{Top-level/not-top level flag}
+\subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag}
%* *
%************************************************************************
\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 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}
-data StrictnessMark = MarkedStrict
- | NotMarkedStrict
+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}
+