From 1204dfc3929afa621580dc6d8c79756bf70c987e Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Fri, 20 May 2022 18:50:04 +0200 Subject: [PATCH 01/16] Fix build on aarch32 with ghc 9.2.2 --- cborg/src/Codec/CBOR/Decoding.hs | 12 ++++++------ cborg/src/Codec/CBOR/Magic.hs | 21 +++++++------------- cborg/src/Codec/CBOR/Read.hs | 33 ++++++++++++++++---------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 2d18e51..cd8844c 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -418,7 +418,7 @@ decodeWord64 = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeWord (\w# -> k (toWord64 w#)))) #else - Decoder (\k -> return (ConsumeWord64 (\w64# -> k (toWord64 w64#)))) + Decoder (\k -> return (ConsumeWord64 (\w64# -> k (W64# w64#)))) #endif -- | Decode a negative 'Word'. @@ -437,7 +437,7 @@ decodeNegWord64 = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeNegWord (\w# -> k (toWord64 w#)))) #else - Decoder (\k -> return (ConsumeNegWord64 (\w64# -> k (toWord64 w64#)))) + Decoder (\k -> return (ConsumeNegWord64 (\w64# -> k (W64# w64#)))) #endif -- | Decode an 'Int'. @@ -477,7 +477,7 @@ decodeInt64 = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeInt (\n# -> k (toInt64 n#)))) #else - Decoder (\k -> return (ConsumeInt64 (\n64# -> k (toInt64 n64#)))) + Decoder (\k -> return (ConsumeInt64 (\n64# -> k (I64# n64#)))) #endif -- | Decode canonical representation of a 'Word'. @@ -517,7 +517,7 @@ decodeWord64Canonical = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeWordCanonical (\w# -> k (toWord64 w#)))) #else - Decoder (\k -> return (ConsumeWord64Canonical (\w64# -> k (toWord64 w64#)))) + Decoder (\k -> return (ConsumeWord64Canonical (\w64# -> k (W64# w64#)))) #endif -- | Decode canonical representation of a negative 'Word'. @@ -536,7 +536,7 @@ decodeNegWord64Canonical = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeNegWordCanonical (\w# -> k (toWord64 w#)))) #else - Decoder (\k -> return (ConsumeNegWord64Canonical (\w64# -> k (toWord64 w64#)))) + Decoder (\k -> return (ConsumeNegWord64Canonical (\w64# -> k (W64# w64#)))) #endif -- | Decode canonical representation of an 'Int'. @@ -576,7 +576,7 @@ decodeInt64Canonical = #if defined(ARCH_64bit) Decoder (\k -> return (ConsumeIntCanonical (\n# -> k (toInt64 n#)))) #else - Decoder (\k -> return (ConsumeInt64Canonical (\n64# -> k (toInt64 n64#)))) + Decoder (\k -> return (ConsumeInt64Canonical (\n64# -> k (I64# n64#)))) #endif -- | Decode an 'Integer'. diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index 0160881..ac896e3 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -120,13 +120,6 @@ import qualified Numeric.Half as Half import Data.Bits ((.|.), unsafeShiftL) #endif -#if defined(ARCH_32bit) -import GHC.IntWord64 (wordToWord64#, word64ToWord#, - intToInt64#, int64ToInt#, - leWord64#, ltWord64#, word64ToInt64#) - -#endif - -------------------------------------------------------------------------------- -- | Grab a 8-bit 'Word' given a 'Ptr' to some address. @@ -472,7 +465,7 @@ word16ToInt (W16# w#) = I# (word2Int# (word16ToWord# w#)) word32ToInt (W32# w#) = I# (word2Int# (word32ToWord# w#)) #else word32ToInt (W32# w#) = - case isTrue# (w# `ltWord#` 0x80000000##) of + case isTrue# (word32ToWord# w# `ltWord#` 0x80000000##) of True -> Just (I# (word2Int# (word32ToWord# w#))) False -> Nothing #endif @@ -508,17 +501,17 @@ word64ToInt (W64# w#) = {-# INLINE word64ToInt #-} #if defined(ARCH_32bit) -word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# w#)) -word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# w#)) -word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# w#)) +word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) +word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# (word32ToWord# w#))) word64ToInt64 (W64# w#) = case isTrue# (w# `ltWord64#` uncheckedShiftL64# (wordToWord64# 1##) 63#) of True -> Just (I64# (word64ToInt64# w#)) False -> Nothing -word8ToWord64 (W8# w#) = W64# (wordToWord64# w#) -word16ToWord64 (W16# w#) = W64# (wordToWord64# w#) -word32ToWord64 (W32# w#) = W64# (wordToWord64# w#) +word8ToWord64 (W8# w#) = W64# (wordToWord64# (word8ToWord# w#)) +word16ToWord64 (W16# w#) = W64# (wordToWord64# (word16ToWord# w#)) +word32ToWord64 (W32# w#) = W64# (wordToWord64# (word32ToWord# w#)) {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} diff --git a/cborg/src/Codec/CBOR/Read.hs b/cborg/src/Codec/CBOR/Read.hs index 0dbb0b6..c4676a1 100644 --- a/cborg/src/Codec/CBOR/Read.hs +++ b/cborg/src/Codec/CBOR/Read.hs @@ -63,9 +63,6 @@ import qualified Data.Text as T import qualified Data.Text.Encoding as T import Data.Word import GHC.Word -#if defined(ARCH_32bit) -import GHC.IntWord64 -#endif import GHC.Exts import GHC.Float (float2Double) import Data.Typeable @@ -510,9 +507,9 @@ go_fast !bs da@(ConsumeNegWord64Canonical k) = go_fast !bs da@(ConsumeInt64Canonical k) = case tryConsumeInt64 (BS.unsafeHead bs) bs of DecodeFailure -> go_fast_end bs da - DecodedToken sz i@(I64# i#) - | isInt64Canonical sz i -> k i# >>= go_fast (BS.unsafeDrop sz bs) - | otherwise -> go_fast_end bs da + DecodedToken sz (I64# i#) + | isInt64Canonical sz i# -> k i# >>= go_fast (BS.unsafeDrop sz bs) + | otherwise -> go_fast_end bs da go_fast !bs da@(ConsumeListLen64Canonical k) = case tryConsumeListLen64 (BS.unsafeHead bs) bs of @@ -994,9 +991,9 @@ go_fast_end !bs (ConsumeNegWord64Canonical k) = go_fast_end !bs (ConsumeInt64Canonical k) = case tryConsumeInt64 (BS.unsafeHead bs) bs of DecodeFailure -> return $! SlowFail bs "expected int64" - DecodedToken sz i@(I64# i#) - | isInt64Canonical sz i -> k i# >>= go_fast_end (BS.unsafeDrop sz bs) - | otherwise -> return $! SlowFail bs "non-canonical int64" + DecodedToken sz (I64# i#) + | isInt64Canonical sz i# -> k i# >>= go_fast_end (BS.unsafeDrop sz bs) + | otherwise -> return $! SlowFail bs "non-canonical int64" go_fast_end !bs (ConsumeListLen64Canonical k) = case tryConsumeListLen64 (BS.unsafeHead bs) bs of @@ -1552,17 +1549,17 @@ isIntCanonical sz i {-# INLINE isWord64Canonical #-} isWord64Canonical :: Int -> Word64 -> Bool isWord64Canonical sz w - | sz == 2 = w > 0x17) - | sz == 3 = w > 0xff) - | sz == 5 = w > 0xffff) - | sz == 9 = w > 0xffffffff) + | sz == 2 = (w > 0x17) + | sz == 3 = (w > 0xff) + | sz == 5 = (w > 0xffff) + | sz == 9 = (w > 0xffffffff) | otherwise = True {-# INLINE isInt64Canonical #-} isInt64Canonical :: Int -> Int64# -> Bool isInt64Canonical sz i# - | isTrue# (i# `ltInt64#` intToInt64# 0#) = isWord64Canonical sz (not64# w#) - | otherwise = isWord64Canonical sz w# + | isTrue# (i# `ltInt64#` intToInt64# 0#) = isWord64Canonical sz (W64# (not64# w#)) + | otherwise = isWord64Canonical sz (W64# w#) where w# = int64ToWord64# i# #endif @@ -1783,7 +1780,8 @@ tryConsumeInteger hdr !bs = case word8ToWord hdr of 0x1b -> let !w = eatTailWord64 bs sz = 9 #if defined(ARCH_32bit) - in DecodedToken sz (BigIntToken (isWord64Canonical sz (word64ToWord w)) $! toInteger w) + in DecodedToken sz (BigIntToken (maybe False (isWord64Canonical sz . wordToWord64) (word64ToWord w)) $! toInteger w) + where wordToWord64 (W# w#) = W64# (wordToWord64# w#) #else in DecodedToken sz (BigIntToken (isWordCanonical sz (word64ToWord w)) $! toInteger w) #endif @@ -1825,7 +1823,8 @@ tryConsumeInteger hdr !bs = case word8ToWord hdr of 0x3b -> let !w = eatTailWord64 bs sz = 9 #if defined(ARCH_32bit) - in DecodedToken sz (BigIntToken (isWord64Canonical sz (word64ToWord w)) $! (-1 - toInteger w)) + in DecodedToken sz (BigIntToken (maybe False (isWord64Canonical sz . wordToWord64) (word64ToWord w)) $! (-1 - toInteger w)) + where wordToWord64 (W# w#) = W64# (wordToWord64# w#) #else in DecodedToken sz (BigIntToken (isWordCanonical sz (word64ToWord w)) $! (-1 - toInteger w)) #endif From 0a0c152e8e8d07d4bbc54ee00f10eeb9bcd83861 Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 12:58:32 -0500 Subject: [PATCH 02/16] testing --- cborg/src/Codec/CBOR/Magic.hs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index c754133..b26abc9 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -120,6 +120,19 @@ import qualified Numeric.Half as Half import Data.Bits ((.|.), unsafeShiftL) #endif +#if defined(ARCH_32bit) +import GHC.IntWord64 as Compat (wordToWord64#, word64ToWord#, + intToInt64#, int64ToInt#, + leWord64#, ltWord64#, word64ToInt64#) +#else +import GHC.Exts as Compat (wordToWord64#, word64ToWord#, + intToInt64#, int64ToInt#, + leWord64#, ltWord64#, word64ToInt64#) + +#endif + + + -------------------------------------------------------------------------------- -- | Grab a 8-bit 'Word' given a 'Ptr' to some address. @@ -161,7 +174,7 @@ grabWord32 (Ptr ip#) = W32# (narrow32Word# (byteSwap32# (indexWord32OffAddr# ip# #endif #if defined(ARCH_64bit) #if MIN_VERSION_base(4,17,0) -grabWord64 (Ptr ip#) = W64# (wordToWord64# (byteSwap# (word64ToWord# (indexWord64OffAddr# ip# 0#)))) +grabWord64 (Ptr ip#) = W64# (Compat.wordToWord64# (byteSwap# (word64ToWord# (indexWord64OffAddr# ip# 0#)))) #else grabWord64 (Ptr ip#) = W64# (byteSwap# (indexWord64OffAddr# ip# 0#)) #endif @@ -252,7 +265,7 @@ grabWord64 (Ptr ip#) = #if WORD_SIZE_IN_BITS == 64 w64 w# = W64# (toWord w#) #else - w64 w# = W64# (wordToWord64# (toWord w#)) + w64 w# = W64# (Compat.wordToWord64# (toWord w#)) #endif #endif @@ -443,7 +456,7 @@ word64ToWord (W64# w#) = W# w# #endif #else word64ToWord (W64# w64#) = - case isTrue# (w64# `leWord64#` wordToWord64# 0xffffffff##) of + case isTrue# (w64# `leWord64#` Compat.wordToWord64# 0xffffffff##) of True -> Just (W# (word64ToWord# w64#)) False -> Nothing #endif @@ -455,7 +468,7 @@ word32ToWord (W32# w#) = W# w# word64ToWord (W64# w#) = W# w# #else word64ToWord (W64# w64#) = - case isTrue# (w64# `leWord64#` wordToWord64# 0xffffffff##) of + case isTrue# (w64# `leWord64#` Compat.wordToWord64# 0xffffffff##) of True -> Just (W# (word64ToWord# w64#)) False -> Nothing #endif @@ -508,7 +521,7 @@ word64ToInt (W64# w#) = False -> Nothing #else word64ToInt (W64# w#) = - case isTrue# (w# `ltWord64#` wordToWord64# 0x80000000##) of + case isTrue# (w# `ltWord64#` Compat.wordToWord64# 0x80000000##) of True -> Just (I# (int64ToInt# (word64ToInt64# w#))) False -> Nothing #endif @@ -521,15 +534,15 @@ word64ToInt (W64# w#) = #if defined(ARCH_32bit) word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) -word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# (word32ToWord# w#))) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (word32ToWord# w#))) word64ToInt64 (W64# w#) = - case isTrue# (w# `ltWord64#` uncheckedShiftL64# (wordToWord64# 1##) 63#) of + case isTrue# (w# `ltWord64#` uncheckedShiftL64# (Compat.wordToWord64# 1##) 63#) of True -> Just (I64# (word64ToInt64# w#)) False -> Nothing -word8ToWord64 (W8# w#) = W64# (wordToWord64# (word8ToWord# w#)) -word16ToWord64 (W16# w#) = W64# (wordToWord64# (word16ToWord# w#)) -word32ToWord64 (W32# w#) = W64# (wordToWord64# (word32ToWord# w#)) +word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (word8ToWord# w#)) +word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (word16ToWord# w#)) +word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (word32ToWord# w#)) {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} From 86f61ddb0a10794733c1665b25e301beeef1893a Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 13:15:04 -0500 Subject: [PATCH 03/16] Added more Compat --- cborg/src/Codec/CBOR/Magic.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index b26abc9..8f97c0a 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -532,17 +532,17 @@ word64ToInt (W64# w#) = {-# INLINE word64ToInt #-} #if defined(ARCH_32bit) -word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) -word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) -word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (word32ToWord# w#))) +word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (Compat.word8ToWord# w#))) +word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (Compat.word16ToWord# w#))) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (Compat.word32ToWord# w#))) word64ToInt64 (W64# w#) = case isTrue# (w# `ltWord64#` uncheckedShiftL64# (Compat.wordToWord64# 1##) 63#) of True -> Just (I64# (word64ToInt64# w#)) False -> Nothing -word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (word8ToWord# w#)) -word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (word16ToWord# w#)) -word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (word32ToWord# w#)) +word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (Compat.word8ToWord# w#)) +word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (Compat.word16ToWord# w#)) +word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (Compat.word32ToWord# w#)) {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} From c3f719d10d151359f2656972fb393755f29874ae Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 13:23:22 -0500 Subject: [PATCH 04/16] Revert "Added more Compat" This reverts commit 86f61ddb0a10794733c1665b25e301beeef1893a. --- cborg/src/Codec/CBOR/Magic.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index 8f97c0a..b26abc9 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -532,17 +532,17 @@ word64ToInt (W64# w#) = {-# INLINE word64ToInt #-} #if defined(ARCH_32bit) -word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (Compat.word8ToWord# w#))) -word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (Compat.word16ToWord# w#))) -word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (Compat.word32ToWord# w#))) +word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) +word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (word32ToWord# w#))) word64ToInt64 (W64# w#) = case isTrue# (w# `ltWord64#` uncheckedShiftL64# (Compat.wordToWord64# 1##) 63#) of True -> Just (I64# (word64ToInt64# w#)) False -> Nothing -word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (Compat.word8ToWord# w#)) -word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (Compat.word16ToWord# w#)) -word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (Compat.word32ToWord# w#)) +word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (word8ToWord# w#)) +word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (word16ToWord# w#)) +word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (word32ToWord# w#)) {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} From 733a1c0b1a7d65f11f2a0ec7e13dce9b854424aa Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 13:42:02 -0500 Subject: [PATCH 05/16] testing --- cborg/src/Codec/CBOR/Magic.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index b26abc9..c0b6c73 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -532,17 +532,32 @@ word64ToInt (W64# w#) = {-# INLINE word64ToInt #-} #if defined(ARCH_32bit) + +#if MIN_VERSION_ghc_prim(0,8,0) word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# (word8ToWord# w#))) word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# (word16ToWord# w#))) word32ToInt64 (W32# w#) = I64# (word64ToInt64# (Compat.wordToWord64# (word32ToWord# w#))) +#else +word8ToInt64 (W8# w#) = I64# (intToInt64# (word2Int# w#)) +word16ToInt64 (W16# w#) = I64# (intToInt64# (word2Int# w#)) +word32ToInt64 (W32# w#) = I64# (word64ToInt64# (wordToWord64# w#)) +#endif + + word64ToInt64 (W64# w#) = case isTrue# (w# `ltWord64#` uncheckedShiftL64# (Compat.wordToWord64# 1##) 63#) of True -> Just (I64# (word64ToInt64# w#)) False -> Nothing +#if MIN_VERSION_ghc_prim(0,8,0) word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# (word8ToWord# w#)) word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# (word16ToWord# w#)) word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# (word32ToWord# w#)) +#else +word8ToWord64 (W8# w#) = W64# (Compat.wordToWord64# w#) +word16ToWord64 (W16# w#) = W64# (Compat.wordToWord64# w#) +word32ToWord64 (W32# w#) = W64# (Compat.wordToWord64# w#) +#endif {-# INLINE word8ToInt64 #-} {-# INLINE word16ToInt64 #-} From 90b2355e9679cb2cd3a347a58e2f0e8da805840a Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:00:44 -0500 Subject: [PATCH 06/16] testing --- cborg/src/Codec/CBOR/Decoding.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 2932873..9233c08 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -126,6 +126,10 @@ import Codec.CBOR.ByteArray (ByteArray) import Prelude hiding (decodeFloat) +#if !MIN_VERSION_ghc_prim(0,8,0) +import qualified GHC.IntWord64 as Compat (wordToWord64#, intToInt64#) +#endif + -- | A continuation-based decoder, used for decoding values that were -- previously encoded using the "Codec.CBOR.Encoding" @@ -343,12 +347,17 @@ toWord64 n = W64# (wordToWord64# n) toInt8 n = I8# n toInt16 n = I16# n toInt32 n = I32# n -toInt64 n = I64# n toWord8 n = W8# n toWord16 n = W16# n toWord32 n = W32# n +#if defined(ARCH_32bit) +toInt64 n = I64# $ intToInt64# n +toWord64 n = W64# $ wordToInt64# n +#else +toInt64 n = I64# n toWord64 n = W64# n #endif +#endif -- $canonical -- From 2cdd63801daec916ca68fc643d5aca0f738c3107 Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:03:15 -0500 Subject: [PATCH 07/16] testing --- cborg/src/Codec/CBOR/Decoding.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 9233c08..170cbbb 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -351,8 +351,8 @@ toWord8 n = W8# n toWord16 n = W16# n toWord32 n = W32# n #if defined(ARCH_32bit) -toInt64 n = I64# $ intToInt64# n -toWord64 n = W64# $ wordToInt64# n +toInt64 n = I64# $ Compat.intToInt64# n +toWord64 n = W64# $ Compat.wordToInt64# n #else toInt64 n = I64# n toWord64 n = W64# n From 036df0c8b8da39bbe97131239dbe5be7f12ebcde Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:07:02 -0500 Subject: [PATCH 08/16] Fix typo --- cborg/src/Codec/CBOR/Decoding.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 170cbbb..5ec4cab 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -352,7 +352,7 @@ toWord16 n = W16# n toWord32 n = W32# n #if defined(ARCH_32bit) toInt64 n = I64# $ Compat.intToInt64# n -toWord64 n = W64# $ Compat.wordToInt64# n +toWord64 n = W64# $ Compat.wordToWord64# n #else toInt64 n = I64# n toWord64 n = W64# n From b214a1bab265b9c31c479f10b4a425690207d83d Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:18:19 -0500 Subject: [PATCH 09/16] With parens --- cborg/src/Codec/CBOR/Decoding.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index 5ec4cab..c7cbe83 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -351,8 +351,8 @@ toWord8 n = W8# n toWord16 n = W16# n toWord32 n = W32# n #if defined(ARCH_32bit) -toInt64 n = I64# $ Compat.intToInt64# n -toWord64 n = W64# $ Compat.wordToWord64# n +toInt64 n = I64# (Compat.intToInt64# n) +toWord64 n = W64# (Compat.wordToWord64# n) #else toInt64 n = I64# n toWord64 n = W64# n From 557e36b58440827f152e6ba56a6578ccf81a6622 Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:24:00 -0500 Subject: [PATCH 10/16] Better CPP Conditionals --- cborg/src/Codec/CBOR/Decoding.hs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index c7cbe83..c537006 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -319,11 +319,14 @@ getDecodeAction (Decoder k) = k (\x -> return (Done x)) toInt8 :: Int# -> Int8 toInt16 :: Int# -> Int16 toInt32 :: Int# -> Int32 -toInt64 :: Int# -> Int64 toWord8 :: Word# -> Word8 toWord16 :: Word# -> Word16 toWord32 :: Word# -> Word32 +#if defined(ARCH_64bit) +toInt64 :: Int# -> Int64 toWord64 :: Word# -> Word64 +#endif + #if MIN_VERSION_ghc_prim(0,8,0) toInt8 n = I8# (intToInt8# n) toInt16 n = I16# (intToInt16# n) @@ -332,6 +335,7 @@ toWord8 n = W8# (wordToWord8# n) toWord16 n = W16# (wordToWord16# n) toWord32 n = W32# (wordToWord32# n) #if WORD_SIZE_IN_BITS == 64 +#if defined(ARCH_64bit) #if MIN_VERSION_base(4,17,0) toInt64 n = I64# (intToInt64# n) toWord64 n = W64# (wordToWord64# n) @@ -339,6 +343,7 @@ toWord64 n = W64# (wordToWord64# n) toInt64 n = I64# n toWord64 n = W64# n #endif +#endif #else toInt64 n = I64# (intToInt64# n) toWord64 n = W64# (wordToWord64# n) @@ -350,10 +355,7 @@ toInt32 n = I32# n toWord8 n = W8# n toWord16 n = W16# n toWord32 n = W32# n -#if defined(ARCH_32bit) -toInt64 n = I64# (Compat.intToInt64# n) -toWord64 n = W64# (Compat.wordToWord64# n) -#else +#if defined(ARCH_64bit) toInt64 n = I64# n toWord64 n = W64# n #endif From e88c38414f151adb83a89ed2d4c6018c2eb22fae Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 14:31:34 -0500 Subject: [PATCH 11/16] Remove unused import --- cborg/src/Codec/CBOR/Decoding.hs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cborg/src/Codec/CBOR/Decoding.hs b/cborg/src/Codec/CBOR/Decoding.hs index c537006..8cff111 100644 --- a/cborg/src/Codec/CBOR/Decoding.hs +++ b/cborg/src/Codec/CBOR/Decoding.hs @@ -126,10 +126,6 @@ import Codec.CBOR.ByteArray (ByteArray) import Prelude hiding (decodeFloat) -#if !MIN_VERSION_ghc_prim(0,8,0) -import qualified GHC.IntWord64 as Compat (wordToWord64#, intToInt64#) -#endif - -- | A continuation-based decoder, used for decoding values that were -- previously encoded using the "Codec.CBOR.Encoding" From 8f9f3d8a67ca62970ab771332652df84d5e991ef Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 15:59:59 -0500 Subject: [PATCH 12/16] Added backwards compatible import --- cborg/src/Codec/CBOR/Read.hs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cborg/src/Codec/CBOR/Read.hs b/cborg/src/Codec/CBOR/Read.hs index ed674a1..d176afb 100644 --- a/cborg/src/Codec/CBOR/Read.hs +++ b/cborg/src/Codec/CBOR/Read.hs @@ -77,6 +77,11 @@ import Codec.CBOR.Decoding (DecodeAction) import qualified Codec.CBOR.Decoding as D import Codec.CBOR.Magic +#if !MIN_VERSION_ghc_prim(0,8,0) +import GHC.IntWord64 +#endif + + -------------------------------------------------------------------------------- -- | An exception type that may be returned (by pure functions) or From abe8b6d7fbd8556085e9c036c33941d46d88ad78 Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 16:14:07 -0500 Subject: [PATCH 13/16] Fixed CPP check to use base verison --- cborg/src/Codec/CBOR/Magic.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index c0b6c73..8a36e14 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -120,15 +120,15 @@ import qualified Numeric.Half as Half import Data.Bits ((.|.), unsafeShiftL) #endif -#if defined(ARCH_32bit) -import GHC.IntWord64 as Compat (wordToWord64#, word64ToWord#, - intToInt64#, int64ToInt#, - leWord64#, ltWord64#, word64ToInt64#) -#else +#if MIN_VERSION_base(4.17.0) import GHC.Exts as Compat (wordToWord64#, word64ToWord#, - intToInt64#, int64ToInt#, - leWord64#, ltWord64#, word64ToInt64#) - + intToInt64#, int64ToInt#, + leWord64#, ltWord64#, word64ToInt64#) + +#else +import GHC.IntWord64 as Compat (wordToWord64#, word64ToWord#, + intToInt64#, int64ToInt#, + leWord64#, ltWord64#, word64ToInt64#) #endif From 91f60949c8c7bdd719e800c45e642756c137df5f Mon Sep 17 00:00:00 2001 From: Logan Tibbetts Date: Tue, 18 Oct 2022 16:18:17 -0500 Subject: [PATCH 14/16] Changed to commas... --- cborg/src/Codec/CBOR/Magic.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index 8a36e14..c486df2 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -120,7 +120,7 @@ import qualified Numeric.Half as Half import Data.Bits ((.|.), unsafeShiftL) #endif -#if MIN_VERSION_base(4.17.0) +#if MIN_VERSION_base(4,17,0) import GHC.Exts as Compat (wordToWord64#, word64ToWord#, intToInt64#, int64ToInt#, leWord64#, ltWord64#, word64ToInt64#) From c93914589c0aa5def6fa4c44d9e14fea20828def Mon Sep 17 00:00:00 2001 From: Alberto Valverde Date: Wed, 19 Oct 2022 19:44:06 +0200 Subject: [PATCH 15/16] fix for 9.2.4 --- cborg/src/Codec/CBOR/Magic.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index c486df2..94db361 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -125,6 +125,8 @@ import GHC.Exts as Compat (wordToWord64#, word64ToWord#, intToInt64#, int64ToInt#, leWord64#, ltWord64#, word64ToInt64#) +#endif +#if MIN_VERSION_base(4,14,0) #else import GHC.IntWord64 as Compat (wordToWord64#, word64ToWord#, intToInt64#, int64ToInt#, From c80026d8ca47fc0cabe0dcf120a4c0599b983ba2 Mon Sep 17 00:00:00 2001 From: Michael Sewell Date: Wed, 26 Oct 2022 13:28:45 -0500 Subject: [PATCH 16/16] building in ghc 8.8.4 on 64 bit machine --- cborg/ChangeLog.md | 4 ++++ cborg/cborg.cabal | 2 +- cborg/src/Codec/CBOR/Magic.hs | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cborg/ChangeLog.md b/cborg/ChangeLog.md index 5b7963e..0aa6933 100644 --- a/cborg/ChangeLog.md +++ b/cborg/ChangeLog.md @@ -1,5 +1,9 @@ # Revision history for cborg +## 0.2.9.0 -- 2022-10-26 + +* building in ghc 8.8.4 on 64 bit machine + ## 0.2.8.0 -- 2022-09-24 * Support GHC 9.4 diff --git a/cborg/cborg.cabal b/cborg/cborg.cabal index a31eaa0..52ff790 100644 --- a/cborg/cborg.cabal +++ b/cborg/cborg.cabal @@ -1,5 +1,5 @@ name: cborg -version: 0.2.8.0 +version: 0.2.9.0 synopsis: Concise Binary Object Representation (CBOR) license: BSD3 license-file: LICENSE.txt diff --git a/cborg/src/Codec/CBOR/Magic.hs b/cborg/src/Codec/CBOR/Magic.hs index 94db361..bf69904 100644 --- a/cborg/src/Codec/CBOR/Magic.hs +++ b/cborg/src/Codec/CBOR/Magic.hs @@ -128,11 +128,12 @@ import GHC.Exts as Compat (wordToWord64#, word64ToWord#, #endif #if MIN_VERSION_base(4,14,0) #else +#if WORD_SIZE_IN_BITS < 64 import GHC.IntWord64 as Compat (wordToWord64#, word64ToWord#, intToInt64#, int64ToInt#, leWord64#, ltWord64#, word64ToInt64#) #endif - +#endif --------------------------------------------------------------------------------