X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FbasicTypes%2FBasicTypes.lhs;h=35c57f36f34a1eb6ba014c89dea65c968fe58eec;hb=e68a891932d615590d9b1ab5752ada8142db5053;hp=6b662bd6a64c18c590d9dc541187fe88e13d1c79;hpb=0065d5ab628975892cea1ec7303f968c3338cbe1;p=ghc-hetmet.git diff --git a/compiler/basicTypes/BasicTypes.lhs b/compiler/basicTypes/BasicTypes.lhs index 6b662bd..35c57f3 100644 --- a/compiler/basicTypes/BasicTypes.lhs +++ b/compiler/basicTypes/BasicTypes.lhs @@ -1,4 +1,5 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1997-1998 % \section[BasicTypes]{Miscellanous types} @@ -31,12 +32,14 @@ module BasicTypes( TopLevelFlag(..), isTopLevel, isNotTopLevel, + OverlapFlag(..), + Boxity(..), isBoxed, TupCon(..), tupleParens, OccInfo(..), seqOccInfo, isFragileOcc, isOneOcc, - isDeadOcc, isLoopBreaker, isNoOcc, + isDeadOcc, isLoopBreaker, isNonRuleLoopBreaker, isNoOcc, InsideLam, insideLam, notInsideLam, OneBranch, oneBranch, notOneBranch, @@ -107,24 +110,18 @@ The @IPName@ type is here because it is used in TypeRep (i.e. very early in the hierarchy), but also in HsSyn. \begin{code} -data IPName name - = Dupable name -- ?x: you can freely duplicate this implicit parameter - | Linear name -- %x: you must use the splitting function to duplicate it +newtype IPName name = IPName name -- ?x deriving( Eq, Ord ) -- Ord is used in the IP name cache finite map -- (used in HscTypes.OrigIParamCache) - ipNameName :: IPName name -> name -ipNameName (Dupable n) = n -ipNameName (Linear n) = n +ipNameName (IPName n) = n mapIPName :: (a->b) -> IPName a -> IPName b -mapIPName f (Dupable n) = Dupable (f n) -mapIPName f (Linear n) = Linear (f n) +mapIPName f (IPName n) = IPName (f n) instance Outputable name => Outputable (IPName name) where - ppr (Dupable n) = char '?' <> ppr n -- Ordinary implicit parameters - ppr (Linear n) = char '%' <> ppr n -- Splittable implicit parameters + ppr (IPName n) = char '?' <> ppr n -- Ordinary implicit parameters \end{code} @@ -217,7 +214,7 @@ instance Outputable TopLevelFlag where %************************************************************************ %* * -\subsection[Top-level/local]{Top-level/not-top level flag} + Top-level/not-top level flag %* * %************************************************************************ @@ -235,11 +232,11 @@ isBoxed Unboxed = False %************************************************************************ %* * -\subsection[Recursive/Non-Recursive]{Recursive/Non-Recursive flag} + Recursive/Non-Recursive flag %* * %************************************************************************ -\begin{code} +\begin{code} data RecFlag = Recursive | NonRecursive deriving( Eq ) @@ -263,6 +260,47 @@ instance Outputable RecFlag where %************************************************************************ %* * + Instance overlap flag +%* * +%************************************************************************ + +\begin{code} +data OverlapFlag + = NoOverlap -- This instance must not overlap another + + | OverlapOk -- Silently ignore this instance if you find a + -- more specific one that matches the constraint + -- you are trying to resolve + -- + -- Example: constraint (Foo [Int]) + -- instances (Foo [Int]) + -- (Foo [a]) OverlapOk + -- Since the second instance has the OverlapOk flag, + -- the first instance will be chosen (otherwise + -- its ambiguous which to choose) + + | Incoherent -- Like OverlapOk, but also ignore this instance + -- if it doesn't match the constraint you are + -- trying to resolve, but could match if the type variables + -- in the constraint were instantiated + -- + -- Example: constraint (Foo [b]) + -- instances (Foo [Int]) Incoherent + -- (Foo [a]) + -- Without the Incoherent flag, we'd complain that + -- instantiating 'b' would change which instance + -- was chosen + deriving( Eq ) + +instance Outputable OverlapFlag where + ppr NoOverlap = empty + ppr OverlapOk = ptext SLIT("[overlap ok]") + ppr Incoherent = ptext SLIT("[incoherent]") + +\end{code} + +%************************************************************************ +%* * Tuples %* * %************************************************************************ @@ -328,18 +366,28 @@ defn of OccInfo here, safely at the bottom \begin{code} data OccInfo - = NoOccInfo + = NoOccInfo -- Many occurrences, or unknown | IAmDead -- Marks unused variables. Sometimes useful for -- lambda and case-bound variables. - | OneOcc !InsideLam - !OneBranch - !InterestingCxt + | OneOcc -- Occurs exactly once, not inside a rule + !InsideLam + !OneBranch + !InterestingCxt | IAmALoopBreaker -- Used by the occurrence analyser to mark loop-breakers -- in a group of recursive definitions + !RulesOnly -- True <=> This loop breaker mentions the other binders + -- in its recursive group only in its RULES, not + -- in its rhs + -- See OccurAnal Note [RulesOnly] +type RulesOnly = Bool +\end{code} + + +\begin{code} isNoOcc :: OccInfo -> Bool isNoOcc NoOccInfo = True isNoOcc other = False @@ -366,8 +414,12 @@ oneBranch = True notOneBranch = False isLoopBreaker :: OccInfo -> Bool -isLoopBreaker IAmALoopBreaker = True -isLoopBreaker other = False +isLoopBreaker (IAmALoopBreaker _) = True +isLoopBreaker other = False + +isNonRuleLoopBreaker :: OccInfo -> Bool +isNonRuleLoopBreaker (IAmALoopBreaker False) = True -- Loop-breaker that breaks a non-rule cycle +isNonRuleLoopBreaker other = False isDeadOcc :: OccInfo -> Bool isDeadOcc IAmDead = True @@ -384,9 +436,9 @@ isFragileOcc other = False \begin{code} instance Outputable OccInfo where -- only used for debugging; never parsed. KSW 1999-07 - ppr NoOccInfo = empty - ppr IAmALoopBreaker = ptext SLIT("LoopBreaker") - ppr IAmDead = ptext SLIT("Dead") + ppr NoOccInfo = empty + ppr (IAmALoopBreaker ro) = ptext SLIT("LoopBreaker") <> if ro then char '!' else empty + ppr IAmDead = ptext SLIT("Dead") ppr (OneOcc inside_lam one_branch int_cxt) = ptext SLIT("Once") <> pp_lam <> pp_br <> pp_args where