X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FbasicTypes%2FUnique.lhs;h=874328863e7b745c79e52abb3e25709ec7fc200d;hb=c0233dc7d12654001595e9c3d5354ced415987bc;hp=dbfc12a865908d0173ebd2d6485187fbd8f17d36;hpb=423d477bfecd490de1449c59325c8776f91d7aac;p=ghc-hetmet.git diff --git a/ghc/compiler/basicTypes/Unique.lhs b/ghc/compiler/basicTypes/Unique.lhs index dbfc12a..8743288 100644 --- a/ghc/compiler/basicTypes/Unique.lhs +++ b/ghc/compiler/basicTypes/Unique.lhs @@ -18,7 +18,7 @@ Haskell). module Unique ( Unique, Uniquable(..), hasKey, - pprUnique, + pprUnique, mkUnique, -- Used in UniqSupply mkUniqueGrimily, -- Used in UniqSupply only! @@ -50,6 +50,7 @@ module Unique ( #include "HsVersions.h" import BasicTypes ( Boxity(..) ) +import PackageConfig ( PackageId, packageIdFS ) import FastString ( FastString, uniqueOfFS ) import Outputable import FastTypes @@ -158,6 +159,9 @@ x `hasKey` k = getUnique x == k instance Uniquable FastString where getUnique fs = mkUniqueGrimily (I# (uniqueOfFS fs)) +instance Uniquable PackageId where + getUnique pid = getUnique (packageIdFS pid) + instance Uniquable Int where getUnique i = mkUniqueGrimily i \end{code} @@ -202,7 +206,7 @@ We do sometimes make strings with @Uniques@ in them: pprUnique :: Unique -> SDoc pprUnique uniq = case unpkUnique uniq of - (tag, u) -> finish_ppr tag u (iToBase62 u) + (tag, u) -> finish_ppr tag u (text (iToBase62 u)) #ifdef UNUSED pprUnique10 :: Unique -> SDoc @@ -235,19 +239,18 @@ The ``62-its'' are \tr{[0-9a-zA-Z]}. We don't handle negative Ints. Code stolen from Lennart. \begin{code} -iToBase62 :: Int -> SDoc - -iToBase62 n@(I# n#) - = ASSERT(n >= 0) - if n# <# 62# then - case (indexCharOffAddr# chars62# n#) of { c -> - char (C# c) } - else - case (quotRem n 62) of { (q, I# r#) -> - case (indexCharOffAddr# chars62# r#) of { c -> - (<>) (iToBase62 q) (char (C# c)) }} +iToBase62 :: Int -> String +iToBase62 n@(I# n#) + = ASSERT(n >= 0) go n# "" where - chars62# = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"# + go n# cs | n# <# 62# + = case (indexCharOffAddr# chars62# n#) of { c# -> C# c# : cs } + | otherwise + = case (quotRem (I# n#) 62) of { (I# q#, I# r#) -> + case (indexCharOffAddr# chars62# r#) of { c# -> + go q# (C# c# : cs) }} + + chars62# = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"# \end{code} %************************************************************************