Remove `Uniquable Int` instance, use `mkUniqueGrimily` directly instead
While going over code in UniqFM
, I stumbled over code using getUnique :: Uniqable a => a -> Unique
on Int
s. And if you go to https://gitlab.haskell.org/ghc/ghc/-/blob/f78f001c91736e31cdfb23959647226f9bd9fe6b/compiler/GHC/Types/Unique.hs#L190, you really see
instance Uniquable Int where
getUnique i = mkUniqueGrimily i
I really don't think this is a good idea. getUnique
is used quite often, and almost never on Int
s. So it's very surprising to see this instance! UniqFM
uses it instead of mkUniqueGrimily
, for example:
nonDetKeysUFM :: UniqFM key elt -> [Unique]
nonDetKeysUFM (UFM m) = map getUnique $ M.keys m
Very, very sneaky. It relies on the getUnique
method to be an inverse to getKey :: Unique -> Int
. But that doesn't necessarily have to be the case!
I think we should get rid of the Uniquable
instance. Just use IntMap
directly instead, if needed! If that's not an option, we should at least consider replacing those getUnique @Int
calls by mkUniqueGrimily
.