[Git][ghc/ghc][wip/T22010] Remove Uniquable Word64 instance

Jaro Reinders (@Noughtmare) gitlab at gitlab.haskell.org
Wed Jun 28 16:08:02 UTC 2023



Jaro Reinders pushed to branch wip/T22010 at Glasgow Haskell Compiler / GHC


Commits:
48970668 by Jaro Reinders at 2023-06-28T18:07:54+02:00
Remove Uniquable Word64 instance

- - - - -


5 changed files:

- compiler/GHC/Cmm/Dataflow/Label.hs
- compiler/GHC/Data/Graph/UnVar.hs
- compiler/GHC/Types/Unique.hs
- compiler/GHC/Types/Unique/DFM.hs
- compiler/GHC/Types/Unique/FM.hs


Changes:

=====================================
compiler/GHC/Cmm/Dataflow/Label.hs
=====================================
@@ -20,7 +20,7 @@ import GHC.Utils.Outputable
 -- TODO: This should really just use GHC's Unique and Uniq{Set,FM}
 import GHC.Cmm.Dataflow.Collections
 
-import GHC.Types.Unique (Uniquable(..))
+import GHC.Types.Unique (Uniquable(..), mkUniqueGrimily)
 import GHC.Data.TrieMap
 import Data.Word (Word64)
 
@@ -39,7 +39,7 @@ instance Show Label where
   show (Label n) = "L" ++ show n
 
 instance Uniquable Label where
-  getUnique label = getUnique (lblToUnique label)
+  getUnique label = mkUniqueGrimily (lblToUnique label)
 
 instance Outputable Label where
   ppr label = ppr (getUnique label)


=====================================
compiler/GHC/Data/Graph/UnVar.hs
=====================================
@@ -93,7 +93,7 @@ unionUnVarSets = foldl' (flip unionUnVarSet) emptyUnVarSet
 
 instance Outputable UnVarSet where
     ppr (UnVarSet s) = braces $
-        hcat $ punctuate comma [ ppr (getUnique i) | i <- S.toList s]
+        hcat $ punctuate comma [ ppr (mkUniqueGrimily i) | i <- S.toList s]
 
 data UnVarGraph = CBPG  !UnVarSet !UnVarSet -- ^ complete bipartite graph
                 | CG    !UnVarSet           -- ^ complete graph


=====================================
compiler/GHC/Types/Unique.hs
=====================================
@@ -205,9 +205,6 @@ instance Uniquable FastString where
 instance Uniquable Int where
   getUnique i = mkUniqueIntGrimily i
 
-instance Uniquable Word64 where
- getUnique i = MkUnique i
-
 instance Uniquable ModuleName where
   getUnique (ModuleName nm) = getUnique nm
 


=====================================
compiler/GHC/Types/Unique/DFM.hs
=====================================
@@ -71,7 +71,7 @@ module GHC.Types.Unique.DFM (
 
 import GHC.Prelude
 
-import GHC.Types.Unique ( Uniquable(..), Unique, getKey )
+import GHC.Types.Unique ( Uniquable(..), Unique, getKey, mkUniqueGrimily )
 import GHC.Utils.Outputable
 
 import qualified GHC.Data.Word64Map.Strict as MS
@@ -315,7 +315,7 @@ filterUDFM p (UDFM m i) = UDFM (M.filter (\(TaggedVal v _) -> p v) m) i
 filterUDFM_Directly :: (Unique -> elt -> Bool) -> UniqDFM key elt -> UniqDFM key elt
 filterUDFM_Directly p (UDFM m i) = UDFM (M.filterWithKey p' m) i
   where
-  p' k (TaggedVal v _) = p (getUnique k) v
+  p' k (TaggedVal v _) = p (mkUniqueGrimily k) v
 
 udfmRestrictKeys :: UniqDFM key elt -> UniqDFM key elt2 -> UniqDFM key elt
 udfmRestrictKeys (UDFM a i) (UDFM b _) = UDFM (M.restrictKeys a (M.keysSet b)) i
@@ -329,7 +329,7 @@ udfmRestrictKeysSet (UDFM val_set i) set =
 -- It's O(n log n) while the corresponding function on `UniqFM` is O(n).
 udfmToList :: UniqDFM key elt -> [(Unique, elt)]
 udfmToList (UDFM m _i) =
-  [ (getUnique k, taggedFst v)
+  [ (mkUniqueGrimily k, taggedFst v)
   | (k, v) <- sortBy (compare `on` (taggedSnd . snd)) $ M.toList m ]
 
 -- Determines whether two 'UniqDFM's contain the same keys.


=====================================
compiler/GHC/Types/Unique/FM.hs
=====================================
@@ -86,7 +86,7 @@ module GHC.Types.Unique.FM (
 
 import GHC.Prelude
 
-import GHC.Types.Unique ( Uniquable(..), Unique, getKey )
+import GHC.Types.Unique ( Uniquable(..), Unique, getKey, mkUniqueGrimily )
 import GHC.Utils.Outputable
 import GHC.Utils.Panic.Plain
 import qualified GHC.Data.Word64Map as M
@@ -379,7 +379,7 @@ nonDetFoldUFM f z (UFM m) = M.foldr f z m
 nonDetFoldWithKeyUFM :: (Unique -> elt -> a -> a) -> a -> UniqFM key elt -> a
 nonDetFoldWithKeyUFM f z (UFM m) = M.foldrWithKey f' z m
   where
-    f' k e a = f (getUnique k) e a
+    f' k e a = f (mkUniqueGrimily k) e a
 
 mapUFM :: (elt1 -> elt2) -> UniqFM key elt1 -> UniqFM key elt2
 mapUFM f (UFM m) = UFM (M.map f m)
@@ -388,10 +388,10 @@ mapMaybeUFM :: (elt1 -> Maybe elt2) -> UniqFM key elt1 -> UniqFM key elt2
 mapMaybeUFM f (UFM m) = UFM (M.mapMaybe f m)
 
 mapMaybeWithKeyUFM :: (Unique -> elt1 -> Maybe elt2) -> UniqFM key elt1 -> UniqFM key elt2
-mapMaybeWithKeyUFM f (UFM m) = UFM (M.mapMaybeWithKey (f . getUnique) m)
+mapMaybeWithKeyUFM f (UFM m) = UFM (M.mapMaybeWithKey (f . mkUniqueGrimily) m)
 
 mapUFM_Directly :: (Unique -> elt1 -> elt2) -> UniqFM key elt1 -> UniqFM key elt2
-mapUFM_Directly f (UFM m) = UFM (M.mapWithKey (f . getUnique) m)
+mapUFM_Directly f (UFM m) = UFM (M.mapWithKey (f . mkUniqueGrimily) m)
 
 strictMapUFM :: (a -> b) -> UniqFM k a -> UniqFM k b
 strictMapUFM f (UFM a) = UFM $ MS.map f a
@@ -400,7 +400,7 @@ filterUFM :: (elt -> Bool) -> UniqFM key elt -> UniqFM key elt
 filterUFM p (UFM m) = UFM (M.filter p m)
 
 filterUFM_Directly :: (Unique -> elt -> Bool) -> UniqFM key elt -> UniqFM key elt
-filterUFM_Directly p (UFM m) = UFM (M.filterWithKey (p . getUnique) m)
+filterUFM_Directly p (UFM m) = UFM (M.filterWithKey (p . mkUniqueGrimily) m)
 
 partitionUFM :: (elt -> Bool) -> UniqFM key elt -> (UniqFM key elt, UniqFM key elt)
 partitionUFM p (UFM m) =
@@ -451,7 +451,7 @@ nonDetEltsUFM (UFM m) = M.elems m
 -- If you use this please provide a justification why it doesn't introduce
 -- nondeterminism.
 nonDetKeysUFM :: UniqFM key elt -> [Unique]
-nonDetKeysUFM (UFM m) = map getUnique $ M.keys m
+nonDetKeysUFM (UFM m) = map mkUniqueGrimily $ M.keys m
 
 -- See Note [Deterministic UniqFM] to learn about nondeterminism.
 -- If you use this please provide a justification why it doesn't introduce
@@ -468,18 +468,18 @@ nonDetStrictFoldUFM k z (UFM m) = M.foldl' (flip k) z m
 nonDetStrictFoldUFM_DirectlyM :: (Monad m) => (Unique -> b -> elt -> m b) -> b -> UniqFM key elt -> m b
 nonDetStrictFoldUFM_DirectlyM f z0 (UFM xs) = M.foldrWithKey c return xs z0
   -- See Note [List fusion and continuations in 'c']
-  where c u x k z = f (getUnique u) z x >>= k
+  where c u x k z = f (mkUniqueGrimily u) z x >>= k
         {-# INLINE c #-}
 
 nonDetStrictFoldUFM_Directly:: (Unique -> elt -> a -> a) -> a -> UniqFM key elt -> a
-nonDetStrictFoldUFM_Directly k z (UFM m) = M.foldlWithKey' (\z' i x -> k (getUnique i) x z') z m
+nonDetStrictFoldUFM_Directly k z (UFM m) = M.foldlWithKey' (\z' i x -> k (mkUniqueGrimily i) x z') z m
 {-# INLINE nonDetStrictFoldUFM_Directly #-}
 
 -- See Note [Deterministic UniqFM] to learn about nondeterminism.
 -- If you use this please provide a justification why it doesn't introduce
 -- nondeterminism.
 nonDetUFMToList :: UniqFM key elt -> [(Unique, elt)]
-nonDetUFMToList (UFM m) = map (\(k, v) -> (getUnique k, v)) $ M.toList m
+nonDetUFMToList (UFM m) = map (\(k, v) -> (mkUniqueGrimily k, v)) $ M.toList m
 
 -- | A wrapper around 'UniqFM' with the sole purpose of informing call sites
 -- that the provided 'Foldable' and 'Traversable' instances are



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/48970668865a07a04604f27a5bae93c0ca92d896

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/48970668865a07a04604f27a5bae93c0ca92d896
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230628/50106931/attachment-0001.html>


More information about the ghc-commits mailing list