Path: blob/develop/haskell-overlays/text-jsstring/hashable.patch
1 views
diff --git a/hashable.cabal b/hashable.cabal1index 4197060..1d3cd53 1006442--- a/hashable.cabal3+++ b/hashable.cabal4@@ -84,6 +84,9 @@ library5, ghc-prim6, text >=0.12 && <1.378+ if impl(ghcjs)9+ Build-depends: ghcjs-base10+11if impl(ghc >=9)12build-depends: ghc-bignum ==1.0.* || ==1.2.*1314diff --git a/src/Data/Hashable/Class.hs b/src/Data/Hashable/Class.hs15index c7dd8c5..036f450 10064416--- a/src/Data/Hashable/Class.hs17+++ b/src/Data/Hashable/Class.hs18@@ -5,6 +5,10 @@1920{-# LANGUAGE Trustworthy #-}2122+#ifdef __GHCJS__23+{-# LANGUAGE JavaScriptFFI, UnboxedTuples, GHCForeignImportPrim #-}24+#endif25+26#if __GLASGOW_HASKELL__ >= 80127{-# LANGUAGE PolyKinds #-} -- For TypeRep instances28#endif29@@ -72,7 +76,9 @@ import Data.Int (Int8, Int16, Int32, Int64)30import Data.List (foldl')31import Data.Ratio (Ratio, denominator, numerator)32import qualified Data.Text as T33+#ifndef __GHCJS__34import qualified Data.Text.Array as TA35+#endif36import qualified Data.Text.Internal as T37import qualified Data.Text.Lazy as TL38import Data.Version (Version(..))39@@ -92,6 +98,9 @@ import qualified Data.Map as Map40import qualified Data.Sequence as Seq41import qualified Data.Set as Set42import qualified Data.Tree as Tree43+#ifdef __GHCJS__44+import Data.JSString (JSString)45+#endif4647-- As we use qualified F.Foldable, we don't get warnings with newer base48import qualified Data.Foldable as F49@@ -152,7 +161,11 @@ import GHC.Exts (Int (..), sizeofByteArray#)50# define MIN_VERSION_integer_gmp_1_0_051# endif5253+#ifndef __GHCJS__54import GHC.Exts (Int(..))55+#else56+import GHC.Exts (Int(..), Int#)57+#endif58import GHC.Integer.GMP.Internals (Integer(..))59# if defined(MIN_VERSION_integer_gmp_1_0_0)60import GHC.Exts (sizeofByteArray#)61@@ -676,17 +689,31 @@ instance Hashable BSI.ShortByteString where62#endif6364instance Hashable T.Text where65+#ifndef __GHCJS__66hashWithSalt salt (T.Text arr off len) =67hashByteArrayWithSalt (TA.aBA arr) (off `shiftL` 1) (len `shiftL` 1)68(hashWithSalt salt len)69+#else70+ hashWithSalt salt (T.Text txt) =71+ hashByteArrayWithSalt ba (0 `shiftL` 1) (I# len `shiftL` 1)72+ (hashWithSalt salt (I# len))73+ where (# ba, len #) = js_textFromJSString txt74+#endif7576instance Hashable TL.Text where77hashWithSalt salt = finalise . TL.foldlChunks step (SP salt 0)78where79finalise (SP s l) = hashWithSalt s l80+#ifndef __GHCJS__81step (SP s l) (T.Text arr off len) = SP82(hashByteArrayWithSalt (TA.aBA arr) (off `shiftL` 1) (len `shiftL` 1) s)83(l + len)84+#else85+ step (SP s l) (T.Text txt) = SP86+ (hashByteArrayWithSalt ba (0 `shiftL` 1) (I# len `shiftL` 1) s)87+ (l + I# len)88+ where (# ba, len #) = js_textFromJSString txt89+#endif9091-- | Compute the hash of a ThreadId.92hashThreadId :: ThreadId -> Int93@@ -880,6 +907,12 @@ instance Hashable1 Option where liftHashWithSalt h salt (Option a) = liftHashWit94#endif95#endif9697+#ifdef __GHCJS__98+foreign import javascript unsafe99+ "h$textFromString"100+ js_textFromJSString :: JSString -> (# ByteArray#, Int# #)101+#endif102+103-- instances for @Data.Functor.{Product,Sum,Compose}@, present104-- in base-4.9 and onward.105#if MIN_VERSION_base(4,9,0)106107108