X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FbasicTypes%2FUnique.lhs;h=41806040d26f36750a8fc9bc1a9ad53745ccd269;hp=40287867de80a7844df454c5d8b3dce52b2ac13e;hb=5289f5d85610f71625a439747a09384876655eb5;hpb=57c02891f82bcfd366945b8583399da963ad5478 diff --git a/compiler/basicTypes/Unique.lhs b/compiler/basicTypes/Unique.lhs index 4028786..4180604 100644 --- a/compiler/basicTypes/Unique.lhs +++ b/compiler/basicTypes/Unique.lhs @@ -16,12 +16,16 @@ Some of the other hair in this code is to be able to use a Haskell). \begin{code} +{-# LANGUAGE BangPatterns #-} module Unique ( - Unique, Uniquable(..), hasKey, + -- * Main data types + Unique, Uniquable(..), + + -- ** Constructors, desctructors and operations on 'Unique's + hasKey, pprUnique, - mkUnique, -- Used in UniqSupply mkUniqueGrimily, -- Used in UniqSupply only! getKey, getKeyFastInt, -- Used in Var, UniqFM, Name only! @@ -32,6 +36,8 @@ module Unique ( isTupleKey, + -- ** Making built-in uniques + -- now all the built-in Uniques (and functions to make them) -- [the Oh-So-Wonderful Haskell module system wins again...] mkAlphaTyVarUnique, @@ -41,6 +47,9 @@ module Unique ( mkPreludeTyConUnique, mkPreludeClassUnique, mkPArrDataConUnique, + mkVarOccUnique, mkDataOccUnique, mkTvOccUnique, mkTcOccUnique, + mkRegSingleUnique, mkRegPairUnique, mkRegClassUnique, mkRegSubUnique, + mkBuiltinUnique, mkPseudoUniqueC, mkPseudoUniqueD, @@ -54,9 +63,7 @@ import BasicTypes import FastTypes import FastString import Outputable -#ifdef DEBUG -import StaticFlags ( opt_SuppressUniques ) -#endif +-- import StaticFlags #if defined(__GLASGOW_HASKELL__) --just for implementing a fast [0,61) -> Char function @@ -78,6 +85,10 @@ Fast comparison is everything on @Uniques@: \begin{code} --why not newtype Int? + +-- | The type of unique identifiers that are used in many places in GHC +-- for fast ordering and equality tests. You should generate these with +-- the functions from the 'UniqSupply' module data Unique = MkUnique FastInt \end{code} @@ -85,7 +96,6 @@ Now come the functions which construct uniques from their pieces, and vice versa The stuff about unique *supplies* is handled further down this module. \begin{code} -mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces unpkUnique :: Unique -> (Char, Int) -- The reverse mkUniqueGrimily :: Int -> Unique -- A trap-door for UniqSupply @@ -123,11 +133,14 @@ newTagUnique u c = mkUnique c i where (_,i) = unpkUnique u -- and as long as the Char fits in 8 bits, which we assume anyway! +mkUnique :: Char -> Int -> Unique -- Builds a unique from pieces +-- NOT EXPORTED, so that we can see all the Chars that +-- are used in this one module mkUnique c i = MkUnique (tag `bitOrFastInt` bits) where - tag = fastOrd (cUnbox c) `shiftLFastInt` _ILIT(24) - bits = iUnbox i `bitAndFastInt` _ILIT(16777215){-``0x00ffffff''-} + !tag = fastOrd (cUnbox c) `shiftLFastInt` _ILIT(24) + !bits = iUnbox i `bitAndFastInt` _ILIT(16777215){-``0x00ffffff''-} unpkUnique (MkUnique u) = let @@ -148,6 +161,7 @@ unpkUnique (MkUnique u) %************************************************************************ \begin{code} +-- | Class of things that we can obtain a 'Unique' from class Uniquable a where getUnique :: a -> Unique @@ -202,11 +216,9 @@ We do sometimes make strings with @Uniques@ in them: \begin{code} pprUnique :: Unique -> SDoc pprUnique uniq -#ifdef DEBUG - | opt_SuppressUniques - = empty -- Used exclusively to suppress uniques so you - | otherwise -- can compare output easily -#endif +-- | opt_SuppressUniques +-- = empty -- Used exclusively to suppress uniques so you +-- | otherwise -- can compare output easily = case unpkUnique uniq of (tag, u) -> finish_ppr tag u (text (iToBase62 u)) @@ -259,7 +271,7 @@ iToBase62 n_ #if defined(__GLASGOW_HASKELL__) --then FastInt == Int# chooseChar62 n = C# (indexCharOffAddr# chars62 n) - chars62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"# + !chars62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"# #else --Haskell98 arrays are portable chooseChar62 n = (!) chars62 n @@ -280,13 +292,14 @@ Allocation of unique supply characters: X: uniques derived by deriveUnique _: unifiable tyvars (above) 0-9: prelude things below + (no numbers left any more..) + :: (prelude) parallel array data constructors other a-z: lower case chars for unique supplies. Used so far: d desugarer f AbsC flattener g SimplStg - l ndpFlatten n Native codegen r Hsc name cache s simplifier @@ -329,11 +342,10 @@ mkTupleDataConUnique Unboxed a = mkUnique '8' (2*a) isTupleKey u = case unpkUnique u of (tag,_) -> tag == '4' || tag == '5' || tag == '7' || tag == '8' -mkPrimOpIdUnique op = mkUnique '9' op -mkPreludeMiscIdUnique i = mkUnique '0' i +mkPrimOpIdUnique op = mkUnique '9' op +mkPreludeMiscIdUnique i = mkUnique '0' i --- No numbers left anymore, so I pick something different for the character --- tag +-- No numbers left anymore, so I pick something different for the character tag mkPArrDataConUnique a = mkUnique ':' (2*a) -- The "tyvar uniques" print specially nicely: a, b, c, etc. @@ -350,5 +362,18 @@ mkPseudoUniqueC i = mkUnique 'C' i -- used for getUnique on Regs mkPseudoUniqueD i = mkUnique 'D' i -- used in NCG for getUnique on RealRegs mkPseudoUniqueE i = mkUnique 'E' i -- used in NCG spiller to create spill VirtualRegs mkPseudoUniqueH i = mkUnique 'H' i -- used in NCG spiller to create spill VirtualRegs + +mkRegSingleUnique, mkRegPairUnique, mkRegSubUnique, mkRegClassUnique :: Int -> Unique +mkRegSingleUnique = mkUnique 'R' +mkRegSubUnique = mkUnique 'S' +mkRegPairUnique = mkUnique 'P' +mkRegClassUnique = mkUnique 'L' + +mkVarOccUnique, mkDataOccUnique, mkTvOccUnique, mkTcOccUnique :: FastString -> Unique +-- See Note [The Unique of an OccName] in OccName +mkVarOccUnique fs = mkUnique 'i' (iBox (uniqueOfFS fs)) +mkDataOccUnique fs = mkUnique 'd' (iBox (uniqueOfFS fs)) +mkTvOccUnique fs = mkUnique 'v' (iBox (uniqueOfFS fs)) +mkTcOccUnique fs = mkUnique 'c' (iBox (uniqueOfFS fs)) \end{code}