X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Futils%2FUniqFM.lhs;h=97f8fb45bc2501208c5d8cc12888fcbbb56fb97b;hb=8ffd91b6102f4ad3111cabdf6bdb1998f257887f;hp=57295d50ae95f37a1d79499ec8bc48de6bb06a01;hpb=68bc57c179fe4f1d739a435766bced7236b36261;p=ghc-hetmet.git diff --git a/compiler/utils/UniqFM.lhs b/compiler/utils/UniqFM.lhs index 57295d5..97f8fb4 100644 --- a/compiler/utils/UniqFM.lhs +++ b/compiler/utils/UniqFM.lhs @@ -15,14 +15,17 @@ Basically, the things need to be in class @Uniquable@, and we use the \begin{code} {-# OPTIONS -Wall -fno-warn-name-shadowing #-} module UniqFM ( + -- * Unique-keyed mappings UniqFM(..), -- abstract type -- (de-abstracted for MachRegs.trivColorable optimisation BL 2007/09) + -- ** Manipulating those mappings emptyUFM, unitUFM, unitDirectlyUFM, listToUFM, listToUFM_Directly, + listToUFM_C, addToUFM,addToUFM_C,addToUFM_Acc, addListToUFM,addListToUFM_C, addToUFM_Directly, @@ -74,6 +77,9 @@ unitDirectlyUFM -- got the Unique already listToUFM :: Uniquable key => [(key,elt)] -> UniqFM elt listToUFM_Directly :: [(Unique, elt)] -> UniqFM elt +listToUFM_C :: Uniquable key => (elt -> elt -> elt) + -> [(key, elt)] + -> UniqFM elt addToUFM :: Uniquable key => UniqFM elt -> key -> elt -> UniqFM elt addListToUFM :: Uniquable key => UniqFM elt -> [(key,elt)] -> UniqFM elt @@ -196,14 +202,14 @@ This code is explained in the paper: %* * %************************************************************************ -@UniqFM a@ is a mapping from Unique to a. - First, the DataType itself; which is either a Node, a Leaf, or an Empty. \begin{code} +-- | @UniqFM a@ is a mapping from Unique to @a@. DO NOT use these constructors +-- directly unless you live in this module! data UniqFM ele = EmptyUFM - | LeafUFM !FastInt !ele + | LeafUFM !FastInt ele | NodeUFM !FastInt -- the switching !FastInt -- the delta (UniqFM ele) @@ -243,6 +249,9 @@ listToUFM key_elt_pairs listToUFM_Directly uniq_elt_pairs = addListToUFM_directly_C use_snd EmptyUFM uniq_elt_pairs + +listToUFM_C combiner key_elt_pairs + = addListToUFM_C combiner EmptyUFM key_elt_pairs \end{code} Now ways of adding things to UniqFMs. @@ -634,7 +643,9 @@ functionality, but may do a few needless evaluations. \begin{code} mkLeafUFM :: FastInt -> a -> UniqFM a -mkLeafUFM i a = LeafUFM i a +mkLeafUFM i a = + ASSERT (iBox i >= 0) -- Note [Uniques must be positive] + LeafUFM i a -- The *ONLY* ways of building a NodeUFM. @@ -839,7 +850,21 @@ use_snd :: a -> b -> b use_snd _ b = b \end{code} -\begin{code} -_unused :: FS.FastString -_unused = undefined -\end{code} +{- Note [Uniques must be positive] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The getCommonNodeUFMData function assumes that the nodes use +positive uniques. Specifically, the inner `loop' shifts the +low bits out of two uniques until the shifted uniques are the same. +At the same time, it computes a new delta, by shifting +to the left. + +The failure case I (JPD) encountered: +If one of the uniques is negative, the shifting may continue +until all 64 bits have been shifted out, resulting in a new delta +of 0, which is wrong and can trigger later assertion failures. + +Where do the negative uniques come from? Both Simom M and +I have run into this problem when hashing a data structure. +In both cases, we have avoided the problem by ensuring that +the hashes remain positive. +-}