diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-12-03 18:54:54 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-03-03 08:12:29 -0500 |
commit | d8dc0f96237fe6fe7081c04727c7c2573477e5cb (patch) | |
tree | dbc4e8d25cf5a085e979df98bacad5999bf78aee /testsuite/tests/primops | |
parent | eea96042f1e8682605ae68db10f2bcdd7dab923e (diff) | |
download | haskell-d8dc0f96237fe6fe7081c04727c7c2573477e5cb.tar.gz |
Fix array and cleanup conversion primops (#19026)
The first change makes the array ones use the proper fixed-size types,
which also means that just like before, they can be used without
explicit conversions with the boxed sized types. (Before, it was Int# /
Word# on both sides, now it is fixed sized on both sides).
For the second change, don't use "extend" or "narrow" in some of the
user-facing primops names for conversions.
- Names like `narrowInt32#` are misleading when `Int` is 32-bits.
- Names like `extendInt64#` are flat-out wrong when `Int is
32-bits.
- `narrow{Int,Word}<N>#` however map a type to itself, and so don't
suffer from this problem. They are left as-is.
These changes are batched together because Alex happend to use the array
ops. We can only use released versions of Alex at this time, sadly, and
I don't want to have to have a release thatwon't work for the final GHC
9.2. So by combining these we get all the changes for Alex done at once.
Bump hackage state in a few places, and also make that workflow slightly
easier for the future.
Bump minimum Alex version
Bump Cabal, array, bytestring, containers, text, and binary submodules
Diffstat (limited to 'testsuite/tests/primops')
-rw-r--r-- | testsuite/tests/primops/should_run/ArithInt16.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithInt32.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithInt8.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithWord16.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithWord32.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ArithWord8.hs | 20 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CStringLength.hs | 12 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpInt16.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpInt32.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpInt8.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpWord16.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpWord32.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/CmpWord8.hs | 2 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ShowPrim.hs | 6 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/ShowPrim.stdout | 6 | ||||
-rw-r--r-- | testsuite/tests/primops/should_run/T4442.hs | 151 |
16 files changed, 161 insertions, 146 deletions
diff --git a/testsuite/tests/primops/should_run/ArithInt16.hs b/testsuite/tests/primops/should_run/ArithInt16.hs index 0f09e0b4fb..373a61ccd8 100644 --- a/testsuite/tests/primops/should_run/ArithInt16.hs +++ b/testsuite/tests/primops/should_run/ArithInt16.hs @@ -146,32 +146,32 @@ addMany (I# a) (I# b) (I# c) (I# d) (I# e) (I# f) (I# g) (I# h) (I# i) (I# j) (I# k) (I# l) (I# m) (I# n) (I# o) (I# p) - = I# (extendInt16# int16) + = I# (int16ToInt# int16) where !int16 = addMany# - (narrowInt16# a) (narrowInt16# b) (narrowInt16# c) (narrowInt16# d) - (narrowInt16# e) (narrowInt16# f) (narrowInt16# g) (narrowInt16# h) - (narrowInt16# i) (narrowInt16# j) (narrowInt16# k) (narrowInt16# l) - (narrowInt16# m) (narrowInt16# n) (narrowInt16# o) (narrowInt16# p) + (intToInt16# a) (intToInt16# b) (intToInt16# c) (intToInt16# d) + (intToInt16# e) (intToInt16# f) (intToInt16# g) (intToInt16# h) + (intToInt16# i) (intToInt16# j) (intToInt16# k) (intToInt16# l) + (intToInt16# m) (intToInt16# n) (intToInt16# o) (intToInt16# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Int16# apply1 :: (Int16# -> Int16#) -> Int -> Int -apply1 opToTest (I# a) = I# (extendInt16# (opToTest (narrowInt16# a))) +apply1 opToTest (I# a) = I# (int16ToInt# (opToTest (intToInt16# a))) {-# NOINLINE apply1 #-} apply2 :: (Int16# -> Int16# -> Int16#) -> Int -> Int -> Int apply2 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt16# a, narrowInt16# b #) + let (# sa, sb #) = (# intToInt16# a, intToInt16# b #) r = opToTest sa sb - in I# (extendInt16# r) + in I# (int16ToInt# r) {-# NOINLINE apply2 #-} apply3 :: (Int16# -> Int16# -> (# Int16#, Int16# #)) -> Int -> Int -> (Int, Int) apply3 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt16# a, narrowInt16# b #) + let (# sa, sb #) = (# intToInt16# a, intToInt16# b #) (# ra, rb #) = opToTest sa sb - in (I# (extendInt16# ra), I# (extendInt16# rb)) + in (I# (int16ToInt# ra), I# (int16ToInt# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/ArithInt32.hs b/testsuite/tests/primops/should_run/ArithInt32.hs index 13b3bb026e..8d1c6a4ad0 100644 --- a/testsuite/tests/primops/should_run/ArithInt32.hs +++ b/testsuite/tests/primops/should_run/ArithInt32.hs @@ -146,32 +146,32 @@ addMany (I# a) (I# b) (I# c) (I# d) (I# e) (I# f) (I# g) (I# h) (I# i) (I# j) (I# k) (I# l) (I# m) (I# n) (I# o) (I# p) - = I# (extendInt32# int32) + = I# (int32ToInt# int32) where !int32 = addMany# - (narrowInt32# a) (narrowInt32# b) (narrowInt32# c) (narrowInt32# d) - (narrowInt32# e) (narrowInt32# f) (narrowInt32# g) (narrowInt32# h) - (narrowInt32# i) (narrowInt32# j) (narrowInt32# k) (narrowInt32# l) - (narrowInt32# m) (narrowInt32# n) (narrowInt32# o) (narrowInt32# p) + (intToInt32# a) (intToInt32# b) (intToInt32# c) (intToInt32# d) + (intToInt32# e) (intToInt32# f) (intToInt32# g) (intToInt32# h) + (intToInt32# i) (intToInt32# j) (intToInt32# k) (intToInt32# l) + (intToInt32# m) (intToInt32# n) (intToInt32# o) (intToInt32# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Int32# apply1 :: (Int32# -> Int32#) -> Int -> Int -apply1 opToTest (I# a) = I# (extendInt32# (opToTest (narrowInt32# a))) +apply1 opToTest (I# a) = I# (int32ToInt# (opToTest (intToInt32# a))) {-# NOINLINE apply1 #-} apply2 :: (Int32# -> Int32# -> Int32#) -> Int -> Int -> Int apply2 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt32# a, narrowInt32# b #) + let (# sa, sb #) = (# intToInt32# a, intToInt32# b #) r = opToTest sa sb - in I# (extendInt32# r) + in I# (int32ToInt# r) {-# NOINLINE apply2 #-} apply3 :: (Int32# -> Int32# -> (# Int32#, Int32# #)) -> Int -> Int -> (Int, Int) apply3 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt32# a, narrowInt32# b #) + let (# sa, sb #) = (# intToInt32# a, intToInt32# b #) (# ra, rb #) = opToTest sa sb - in (I# (extendInt32# ra), I# (extendInt32# rb)) + in (I# (int32ToInt# ra), I# (int32ToInt# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/ArithInt8.hs b/testsuite/tests/primops/should_run/ArithInt8.hs index 18a472d073..4629772a7d 100644 --- a/testsuite/tests/primops/should_run/ArithInt8.hs +++ b/testsuite/tests/primops/should_run/ArithInt8.hs @@ -150,32 +150,32 @@ addMany (I# a) (I# b) (I# c) (I# d) (I# e) (I# f) (I# g) (I# h) (I# i) (I# j) (I# k) (I# l) (I# m) (I# n) (I# o) (I# p) - = I# (extendInt8# int8) + = I# (int8ToInt# int8) where !int8 = addMany# - (narrowInt8# a) (narrowInt8# b) (narrowInt8# c) (narrowInt8# d) - (narrowInt8# e) (narrowInt8# f) (narrowInt8# g) (narrowInt8# h) - (narrowInt8# i) (narrowInt8# j) (narrowInt8# k) (narrowInt8# l) - (narrowInt8# m) (narrowInt8# n) (narrowInt8# o) (narrowInt8# p) + (intToInt8# a) (intToInt8# b) (intToInt8# c) (intToInt8# d) + (intToInt8# e) (intToInt8# f) (intToInt8# g) (intToInt8# h) + (intToInt8# i) (intToInt8# j) (intToInt8# k) (intToInt8# l) + (intToInt8# m) (intToInt8# n) (intToInt8# o) (intToInt8# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Int8# apply1 :: (Int8# -> Int8#) -> Int -> Int -apply1 opToTest (I# a) = I# (extendInt8# (opToTest (narrowInt8# a))) +apply1 opToTest (I# a) = I# (int8ToInt# (opToTest (intToInt8# a))) {-# NOINLINE apply1 #-} apply2 :: (Int8# -> Int8# -> Int8#) -> Int -> Int -> Int apply2 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt8# a, narrowInt8# b #) + let (# sa, sb #) = (# intToInt8# a, intToInt8# b #) r = opToTest sa sb - in I# (extendInt8# r) + in I# (int8ToInt# r) {-# NOINLINE apply2 #-} apply3 :: (Int8# -> Int8# -> (# Int8#, Int8# #)) -> Int -> Int -> (Int, Int) apply3 opToTest (I# a) (I# b) = - let (# sa, sb #) = (# narrowInt8# a, narrowInt8# b #) + let (# sa, sb #) = (# intToInt8# a, intToInt8# b #) (# ra, rb #) = opToTest sa sb - in (I# (extendInt8# ra), I# (extendInt8# rb)) + in (I# (int8ToInt# ra), I# (int8ToInt# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/ArithWord16.hs b/testsuite/tests/primops/should_run/ArithWord16.hs index 5870fd4751..cd64614873 100644 --- a/testsuite/tests/primops/should_run/ArithWord16.hs +++ b/testsuite/tests/primops/should_run/ArithWord16.hs @@ -141,34 +141,34 @@ addMany (W# a) (W# b) (W# c) (W# d) (W# e) (W# f) (W# g) (W# h) (W# i) (W# j) (W# k) (W# l) (W# m) (W# n) (W# o) (W# p) - = W# (extendWord16# word16) + = W# (word16ToWord# word16) where !word16 = addMany# - (narrowWord16# a) (narrowWord16# b) (narrowWord16# c) (narrowWord16# d) - (narrowWord16# e) (narrowWord16# f) (narrowWord16# g) (narrowWord16# h) - (narrowWord16# i) (narrowWord16# j) (narrowWord16# k) (narrowWord16# l) - (narrowWord16# m) (narrowWord16# n) (narrowWord16# o) (narrowWord16# p) + (wordToWord16# a) (wordToWord16# b) (wordToWord16# c) (wordToWord16# d) + (wordToWord16# e) (wordToWord16# f) (wordToWord16# g) (wordToWord16# h) + (wordToWord16# i) (wordToWord16# j) (wordToWord16# k) (wordToWord16# l) + (wordToWord16# m) (wordToWord16# n) (wordToWord16# o) (wordToWord16# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Word16# apply1 :: (Word16# -> Word16#) -> Word -> Word -apply1 opToTest (W# a) = W# (extendWord16# (opToTest (narrowWord16# a))) +apply1 opToTest (W# a) = W# (word16ToWord# (opToTest (wordToWord16# a))) {-# NOINLINE apply1 #-} apply2 :: (Word16# -> Word16# -> Word16#) -> Word -> Word -> Word apply2 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord16# a, narrowWord16# b #) + let (# sa, sb #) = (# wordToWord16# a, wordToWord16# b #) r = opToTest sa sb - in W# (extendWord16# r) + in W# (word16ToWord# r) {-# NOINLINE apply2 #-} apply3 :: (Word16# -> Word16# -> (# Word16#, Word16# #)) -> Word -> Word -> (Word, Word) apply3 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord16# a, narrowWord16# b #) + let (# sa, sb #) = (# wordToWord16# a, wordToWord16# b #) (# ra, rb #) = opToTest sa sb - in (W# (extendWord16# ra), W# (extendWord16# rb)) + in (W# (word16ToWord# ra), W# (word16ToWord# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/ArithWord32.hs b/testsuite/tests/primops/should_run/ArithWord32.hs index 5756732ce0..ad0352435e 100644 --- a/testsuite/tests/primops/should_run/ArithWord32.hs +++ b/testsuite/tests/primops/should_run/ArithWord32.hs @@ -141,34 +141,34 @@ addMany (W# a) (W# b) (W# c) (W# d) (W# e) (W# f) (W# g) (W# h) (W# i) (W# j) (W# k) (W# l) (W# m) (W# n) (W# o) (W# p) - = W# (extendWord32# word32) + = W# (word32ToWord# word32) where !word32 = addMany# - (narrowWord32# a) (narrowWord32# b) (narrowWord32# c) (narrowWord32# d) - (narrowWord32# e) (narrowWord32# f) (narrowWord32# g) (narrowWord32# h) - (narrowWord32# i) (narrowWord32# j) (narrowWord32# k) (narrowWord32# l) - (narrowWord32# m) (narrowWord32# n) (narrowWord32# o) (narrowWord32# p) + (wordToWord32# a) (wordToWord32# b) (wordToWord32# c) (wordToWord32# d) + (wordToWord32# e) (wordToWord32# f) (wordToWord32# g) (wordToWord32# h) + (wordToWord32# i) (wordToWord32# j) (wordToWord32# k) (wordToWord32# l) + (wordToWord32# m) (wordToWord32# n) (wordToWord32# o) (wordToWord32# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Word32# apply1 :: (Word32# -> Word32#) -> Word -> Word -apply1 opToTest (W# a) = W# (extendWord32# (opToTest (narrowWord32# a))) +apply1 opToTest (W# a) = W# (word32ToWord# (opToTest (wordToWord32# a))) {-# NOINLINE apply1 #-} apply2 :: (Word32# -> Word32# -> Word32#) -> Word -> Word -> Word apply2 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord32# a, narrowWord32# b #) + let (# sa, sb #) = (# wordToWord32# a, wordToWord32# b #) r = opToTest sa sb - in W# (extendWord32# r) + in W# (word32ToWord# r) {-# NOINLINE apply2 #-} apply3 :: (Word32# -> Word32# -> (# Word32#, Word32# #)) -> Word -> Word -> (Word, Word) apply3 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord32# a, narrowWord32# b #) + let (# sa, sb #) = (# wordToWord32# a, wordToWord32# b #) (# ra, rb #) = opToTest sa sb - in (W# (extendWord32# ra), W# (extendWord32# rb)) + in (W# (word32ToWord# ra), W# (word32ToWord# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/ArithWord8.hs b/testsuite/tests/primops/should_run/ArithWord8.hs index b25d2b0e6f..6fea314bb2 100644 --- a/testsuite/tests/primops/should_run/ArithWord8.hs +++ b/testsuite/tests/primops/should_run/ArithWord8.hs @@ -145,34 +145,34 @@ addMany (W# a) (W# b) (W# c) (W# d) (W# e) (W# f) (W# g) (W# h) (W# i) (W# j) (W# k) (W# l) (W# m) (W# n) (W# o) (W# p) - = W# (extendWord8# word8) + = W# (word8ToWord# word8) where !word8 = addMany# - (narrowWord8# a) (narrowWord8# b) (narrowWord8# c) (narrowWord8# d) - (narrowWord8# e) (narrowWord8# f) (narrowWord8# g) (narrowWord8# h) - (narrowWord8# i) (narrowWord8# j) (narrowWord8# k) (narrowWord8# l) - (narrowWord8# m) (narrowWord8# n) (narrowWord8# o) (narrowWord8# p) + (wordToWord8# a) (wordToWord8# b) (wordToWord8# c) (wordToWord8# d) + (wordToWord8# e) (wordToWord8# f) (wordToWord8# g) (wordToWord8# h) + (wordToWord8# i) (wordToWord8# j) (wordToWord8# k) (wordToWord8# l) + (wordToWord8# m) (wordToWord8# n) (wordToWord8# o) (wordToWord8# p) {-# NOINLINE addMany #-} -- Convenient and also tests higher order functions on Word8# apply1 :: (Word8# -> Word8#) -> Word -> Word -apply1 opToTest (W# a) = W# (extendWord8# (opToTest (narrowWord8# a))) +apply1 opToTest (W# a) = W# (word8ToWord# (opToTest (wordToWord8# a))) {-# NOINLINE apply1 #-} apply2 :: (Word8# -> Word8# -> Word8#) -> Word -> Word -> Word apply2 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord8# a, narrowWord8# b #) + let (# sa, sb #) = (# wordToWord8# a, wordToWord8# b #) r = opToTest sa sb - in W# (extendWord8# r) + in W# (word8ToWord# r) {-# NOINLINE apply2 #-} apply3 :: (Word8# -> Word8# -> (# Word8#, Word8# #)) -> Word -> Word -> (Word, Word) apply3 opToTest (W# a) (W# b) = - let (# sa, sb #) = (# narrowWord8# a, narrowWord8# b #) + let (# sa, sb #) = (# wordToWord8# a, wordToWord8# b #) (# ra, rb #) = opToTest sa sb - in (W# (extendWord8# ra), W# (extendWord8# rb)) + in (W# (word8ToWord# ra), W# (word8ToWord# rb)) {-# NOINLINE apply3 #-} instance diff --git a/testsuite/tests/primops/should_run/CStringLength.hs b/testsuite/tests/primops/should_run/CStringLength.hs index b580e61934..ee7aac4f9b 100644 --- a/testsuite/tests/primops/should_run/CStringLength.hs +++ b/testsuite/tests/primops/should_run/CStringLength.hs @@ -3,6 +3,7 @@ {-# LANGUAGE UnboxedTuples #-} import GHC.Exts +import GHC.Word (Word8(..)) main :: IO () main = do @@ -28,6 +29,11 @@ main = do naiveStrlen "araña\NULb"# 0 naiveStrlen :: Addr# -> Int -> Int -naiveStrlen addr !n = case indexWord8OffAddr# addr 0# of - 0## -> n - _ -> naiveStrlen (plusAddr# addr 1#) (n + 1) +naiveStrlen addr !n = + -- TODO change back to pattern matching once we have negative literals. + if isTrue# (res `eqWord8#` zero) + then n + else naiveStrlen (plusAddr# addr 1#) (n + 1) + where + res = indexWord8OffAddr# addr 0# + W8# zero = 0 diff --git a/testsuite/tests/primops/should_run/CmpInt16.hs b/testsuite/tests/primops/should_run/CmpInt16.hs index 3fa89b5b31..0fdec359d7 100644 --- a/testsuite/tests/primops/should_run/CmpInt16.hs +++ b/testsuite/tests/primops/should_run/CmpInt16.hs @@ -16,7 +16,7 @@ data TestInt16 = T16 Int16# deriving (Eq, Ord) mkT16 :: Int -> TestInt16 -mkT16 (I# a) = T16 (narrowInt16# a) +mkT16 (I# a) = T16 (intToInt16# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/CmpInt32.hs b/testsuite/tests/primops/should_run/CmpInt32.hs index 6f52ccecb1..a9b560664b 100644 --- a/testsuite/tests/primops/should_run/CmpInt32.hs +++ b/testsuite/tests/primops/should_run/CmpInt32.hs @@ -16,7 +16,7 @@ data TestInt32 = T32 Int32# deriving (Eq, Ord) mkT32 :: Int -> TestInt32 -mkT32 (I# a) = T32 (narrowInt32# a) +mkT32 (I# a) = T32 (intToInt32# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/CmpInt8.hs b/testsuite/tests/primops/should_run/CmpInt8.hs index 7f0bcda973..2bed2000da 100644 --- a/testsuite/tests/primops/should_run/CmpInt8.hs +++ b/testsuite/tests/primops/should_run/CmpInt8.hs @@ -16,7 +16,7 @@ data TestInt8 = T8 Int8# deriving (Eq, Ord) mkT8 :: Int -> TestInt8 -mkT8 (I# a) = T8 (narrowInt8# a) +mkT8 (I# a) = T8 (intToInt8# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/CmpWord16.hs b/testsuite/tests/primops/should_run/CmpWord16.hs index 1a69a10f4b..a5d527afd0 100644 --- a/testsuite/tests/primops/should_run/CmpWord16.hs +++ b/testsuite/tests/primops/should_run/CmpWord16.hs @@ -16,7 +16,7 @@ data TestWord16 = T16 Word16# deriving (Eq, Ord) mkT16 :: Word -> TestWord16 -mkT16 (W# a) = T16 (narrowWord16# a) +mkT16 (W# a) = T16 (wordToWord16# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/CmpWord32.hs b/testsuite/tests/primops/should_run/CmpWord32.hs index 5e422aecab..aeb7ec28e4 100644 --- a/testsuite/tests/primops/should_run/CmpWord32.hs +++ b/testsuite/tests/primops/should_run/CmpWord32.hs @@ -16,7 +16,7 @@ data TestWord32 = T32 Word32# deriving (Eq, Ord) mkT32 :: Word -> TestWord32 -mkT32 (W# a) = T32 (narrowWord32# a) +mkT32 (W# a) = T32 (wordToWord32# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/CmpWord8.hs b/testsuite/tests/primops/should_run/CmpWord8.hs index 07f683108e..813ae7c270 100644 --- a/testsuite/tests/primops/should_run/CmpWord8.hs +++ b/testsuite/tests/primops/should_run/CmpWord8.hs @@ -16,7 +16,7 @@ data TestWord8 = T8 Word8# deriving (Eq, Ord) mkT8 :: Word -> TestWord8 -mkT8 (W# a) = T8 (narrowWord8# a) +mkT8 (W# a) = T8 (wordToWord8# a) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/ShowPrim.hs b/testsuite/tests/primops/should_run/ShowPrim.hs index ddeb661ec4..6213ef496c 100644 --- a/testsuite/tests/primops/should_run/ShowPrim.hs +++ b/testsuite/tests/primops/should_run/ShowPrim.hs @@ -14,13 +14,13 @@ data Test3 = Test3 Int32# Word32# deriving (Show) test1 :: Test1 -test1 = Test1 (narrowInt8# 1#) (narrowWord8# 2##) +test1 = Test1 (intToInt8# 1#) (wordToWord8# 2##) test2 :: Test2 -test2 = Test2 (narrowInt16# 1#) (narrowWord16# 2##) +test2 = Test2 (intToInt16# 1#) (wordToWord16# 2##) test3 :: Test3 -test3 = Test3 (narrowInt32# 1#) (narrowWord32# 2##) +test3 = Test3 (intToInt32# 1#) (wordToWord32# 2##) main :: IO () main = do diff --git a/testsuite/tests/primops/should_run/ShowPrim.stdout b/testsuite/tests/primops/should_run/ShowPrim.stdout index a5dc75f39d..d4167bf32c 100644 --- a/testsuite/tests/primops/should_run/ShowPrim.stdout +++ b/testsuite/tests/primops/should_run/ShowPrim.stdout @@ -1,3 +1,3 @@ -Test1 (narrowInt8# 1#) (narrowWord8# 2##) -Test2 (narrowInt16# 1#) (narrowWord16# 2##) -Test3 (narrowInt32# 1#) (narrowWord32# 2##) +Test1 (intToInt8# 1#) (wordToWord8# 2##) +Test2 (intToInt16# 1#) (wordToWord16# 2##) +Test3 (intToInt32# 1#) (wordToWord32# 2##) diff --git a/testsuite/tests/primops/should_run/T4442.hs b/testsuite/tests/primops/should_run/T4442.hs index d9e65006bc..dfdf93cc4f 100644 --- a/testsuite/tests/primops/should_run/T4442.hs +++ b/testsuite/tests/primops/should_run/T4442.hs @@ -1,4 +1,6 @@ -{-# LANGUAGE MagicHash, UnboxedTuples, CPP #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE MagicHash #-} +{-# LANGUAGE UnboxedTuples #-} module Main where #include "MachDeps.h" @@ -8,32 +10,30 @@ import GHC.Stable( StablePtr(..), castStablePtrToPtr, castPtrToStablePtr, newStablePtr) import GHC.Exts import Data.Char(ord) -#if WORD_SIZE_IN_BITS < 64 -import GHC.Int (Int64(..)) -import GHC.Word (Word64(..)) -#endif +import GHC.Int +import GHC.Word -assertEqual :: (Show a, Eq a) => a -> a -> IO () -assertEqual a b - | a /= b = putStrLn (show a ++ " /= " ++ show b) +assertEqual :: (Show a, Eq a) => String -> a -> a -> IO () +assertEqual msg a b + | a /= b = putStrLn (msg ++ " " ++ show a ++ " /= " ++ show b) | otherwise = return () -readBytes :: MutableByteArray# s -> State# s -> Int# -> (# State# s, [Int] #) +readBytes :: MutableByteArray# s -> State# s -> Int# -> (# State# s, [Word8] #) readBytes marr s0 len = go s0 len [] where go s 0# bs = (# s, bs #) go s i bs = case readWord8Array# marr (i -# 1#) s of - (# s', b #) -> go s' (i -# 1#) (I# (word2Int# b):bs) + (# s', b #) -> go s' (i -# 1#) (W8# b : bs) -indexBytes :: ByteArray# -> Int# -> [Int] +indexBytes :: ByteArray# -> Int# -> [Word8] indexBytes arr len = - [I# (word2Int# (indexWord8Array# arr i)) | I# i <- [0..I# len - 1]] + [W8# (indexWord8Array# arr i) | I# i <- [0..I# len - 1]] -fillByteArray :: MutableByteArray# s -> Int# -> Int -> State# s -> State# s -fillByteArray arr len (I# a) = go len +fillByteArray :: MutableByteArray# s -> Int# -> Word8 -> State# s -> State# s +fillByteArray arr len (W8# a) = go len where go 0# s = s - go i s = go (i -# 1#) (writeInt8Array# arr (i -# 1#) a s) + go i s = go (i -# 1#) (writeWord8Array# arr (i -# 1#) a s) test :: (Eq a, Show a) => String @@ -43,7 +43,7 @@ test :: (Eq a, Show a) -> (MutableByteArray# RealWorld -> Int# -> a -> State# RealWorld -> State# RealWorld) -> a - -> [Int] + -> [Word8] -> Int -> IO () test name index read write val valBytes len = do @@ -53,14 +53,14 @@ test name index read write val valBytes len = do arrLen :: Int# arrLen = 24# - fillerByte :: Int + fillerByte :: Word8 fillerByte = 0x34 - expectedArrayBytes :: Int -> [Int] + expectedArrayBytes :: Int -> [Word8] expectedArrayBytes offset = replicate offset fillerByte ++ valBytes - ++ replicate (I# arrLen - len - offset) fillerByte + ++ replicate (fromIntegral $ I# arrLen - len - offset) fillerByte testAtOffset :: Int -> IO () testAtOffset offset@(I# offset#) = runRW# (\s0 -> let @@ -73,18 +73,18 @@ test name index read write val valBytes len = do actual1 = index arr offset# actualBytes1 = indexBytes arr arrLen in do - assertEqual actual0 val - assertEqual actual1 val - assertEqual actualBytes0 (expectedArrayBytes offset) - assertEqual actualBytes1 (expectedArrayBytes offset) + assertEqual "actual val 0" actual0 val + assertEqual "actual val 1" actual1 val + assertEqual "actualBytes0 indexed" actualBytes0 (expectedArrayBytes offset) + assertEqual "actualButes1 indexed" actualBytes1 (expectedArrayBytes offset) ) -intToBytes :: Int -> Int -> [Int] -intToBytes (I# val0) (I# len0) = let +intToBytes :: Word -> Int -> [Word8] +intToBytes (W# val0) (I# len0) = let result = go val0 len0 go v 0# = [] go v len = - I# (v `andI#` 0xff#) : go (v `uncheckedIShiftRL#` 8#) (len -# 1#) + W8# (wordToWord8# v) : go (v `uncheckedShiftRL#` 8#) (len -# 1#) in #if defined(WORDS_BIGENDIAN) reverse result @@ -92,28 +92,22 @@ intToBytes (I# val0) (I# len0) = let result #endif -testIntArray :: - String - -> (ByteArray# -> Int# -> Int#) +testIntArray :: (Eq a, Show a, Integral a, Num a) + => String + -> (ByteArray# -> Int# -> a) -> (MutableByteArray# RealWorld -> Int# -> State# RealWorld - -> (# State# RealWorld, Int# #)) - -> (MutableByteArray# RealWorld -> Int# -> Int# -> State# RealWorld - -> State# RealWorld) - -> Int + -> (# State# RealWorld, a #)) + -> (MutableByteArray# RealWorld -> Int# -> a -> State# RealWorld + -> State# RealWorld) + -> a -> Int -> IO () testIntArray name0 index read write val0 len = do doOne (name0 ++ " positive") val0 doOne (name0 ++ " negative") (negate val0) where - doOne name val = test - name - (\arr i -> I# (index arr i)) - (\arr i s -> case read arr i s of (# s', a #) -> (# s', I# a #)) - (\arr i (I# a) s -> write arr i a s) - val - (intToBytes val len) - len + doOne name val = test name index read write + val (intToBytes (fromIntegral val) len) len #if WORD_SIZE_IN_BITS == 64 testInt64Array = testIntArray @@ -143,24 +137,19 @@ testInt64Array name0 index read write val0 len = do len #endif -testWordArray :: - String - -> (ByteArray# -> Int# -> Word#) +testWordArray :: (Eq a, Show a, Integral a) + => String + -> (ByteArray# -> Int# -> a) -> (MutableByteArray# RealWorld -> Int# -> State# RealWorld - -> (# State# RealWorld, Word# #)) - -> (MutableByteArray# RealWorld -> Int# -> Word# -> State# RealWorld + -> (# State# RealWorld, a #)) + -> (MutableByteArray# RealWorld -> Int# -> a -> State# RealWorld -> State# RealWorld) - -> Word + -> a -> Int -> IO () -testWordArray name index read write val len = test - name - (\arr i -> W# (index arr i)) - (\arr i s -> case read arr i s of (# s', a #) -> (# s', W# a #)) - (\arr i (W# a) s -> write arr i a s) - val - (intToBytes (fromIntegral val) len) - len +testWordArray name index read write val len = + test name index read write + val (intToBytes (fromIntegral val) len) len #if WORD_SIZE_IN_BITS == 64 testWord64Array = testWordArray @@ -203,7 +192,7 @@ float = 123.456789 -- >>> import struct -- >>> import binascii -- >>> binascii.hexlify(struct.pack('>f', 123.456789)) -floatBytes :: Int +floatBytes :: Word floatBytes = 0x42f6e9e0 double :: Double @@ -213,41 +202,61 @@ double = 123.45678901234 -- >>> import struct -- >>> import binascii -- >>> binascii.hexlify(struct.pack('>d', 123.45678901234)) -doubleBytes :: Int +doubleBytes :: Word doubleBytes = 0x405edd3c07fb4b09 main :: IO () main = do testIntArray "Int8#" - indexInt8Array# readInt8Array# writeInt8Array# + (\arr i -> I8# (indexInt8Array# arr i)) + (\arr i s -> case readInt8Array# arr i s of (# s', a #) -> (# s', I8# a #)) + (\arr i (I8# a) s -> writeInt8Array# arr i a s) 123 1 testIntArray "Int16#" - indexWord8ArrayAsInt16# readWord8ArrayAsInt16# writeWord8ArrayAsInt16# + (\arr i -> I16# (indexWord8ArrayAsInt16# arr i)) + (\arr i s -> case readWord8ArrayAsInt16# arr i s of (# s', a #) -> (# s', I16# a #)) + (\arr i (I16# a) s -> writeWord8ArrayAsInt16# arr i a s) 12345 2 testIntArray "Int32#" - indexWord8ArrayAsInt32# readWord8ArrayAsInt32# writeWord8ArrayAsInt32# + (\arr i -> I32# (indexWord8ArrayAsInt32# arr i)) + (\arr i s -> case readWord8ArrayAsInt32# arr i s of (# s', a #) -> (# s', I32# a #)) + (\arr i (I32# a) s -> writeWord8ArrayAsInt32# arr i a s) 12345678 4 testInt64Array "Int64#" - indexWord8ArrayAsInt64# readWord8ArrayAsInt64# writeWord8ArrayAsInt64# + (\arr i -> I64# (indexWord8ArrayAsInt64# arr i)) + (\arr i s -> case readWord8ArrayAsInt64# arr i s of (# s', a #) -> (# s', I64# a #)) + (\arr i (I64# a) s -> writeWord8ArrayAsInt64# arr i a s) 1234567890123 8 testIntArray "Int#" - indexWord8ArrayAsInt# readWord8ArrayAsInt# writeWord8ArrayAsInt# + (\arr i -> I# (indexWord8ArrayAsInt# arr i)) + (\arr i s -> case readWord8ArrayAsInt# arr i s of (# s', a #) -> (# s', I# a #)) + (\arr i (I# a) s -> writeWord8ArrayAsInt# arr i a s) int wordSizeInBytes testWordArray "Word8#" - indexWord8Array# readWord8Array# writeWord8Array# + (\arr i -> W8# (indexWord8Array# arr i)) + (\arr i s -> case readWord8Array# arr i s of (# s', a #) -> (# s', W8# a #)) + (\arr i (W8# a) s -> writeWord8Array# arr i a s) 123 1 testWordArray "Word16#" - indexWord8ArrayAsWord16# readWord8ArrayAsWord16# writeWord8ArrayAsWord16# + (\arr i -> W16# (indexWord8ArrayAsWord16# arr i)) + (\arr i s -> case readWord8ArrayAsWord16# arr i s of (# s', a #) -> (# s', W16# a #)) + (\arr i (W16# a) s -> writeWord8ArrayAsWord16# arr i a s) 12345 2 testWordArray "Word32#" - indexWord8ArrayAsWord32# readWord8ArrayAsWord32# writeWord8ArrayAsWord32# + (\arr i -> W32# (indexWord8ArrayAsWord32# arr i)) + (\arr i s -> case readWord8ArrayAsWord32# arr i s of (# s', a #) -> (# s', W32# a #)) + (\arr i (W32# a) s -> writeWord8ArrayAsWord32# arr i a s) 12345678 4 testWord64Array "Word64#" - indexWord8ArrayAsWord64# readWord8ArrayAsWord64# writeWord8ArrayAsWord64# + (\arr i -> W64# (indexWord8ArrayAsWord64# arr i)) + (\arr i s -> case readWord8ArrayAsWord64# arr i s of (# s', a #) -> (# s', W64# a #)) + (\arr i (W64# a) s -> writeWord8ArrayAsWord64# arr i a s) 1234567890123 8 testWordArray "Word#" - indexWord8ArrayAsWord# readWord8ArrayAsWord# writeWord8ArrayAsWord# + (\arr i -> W# (indexWord8ArrayAsWord# arr i)) + (\arr i s -> case readWord8ArrayAsWord# arr i s of (# s', a #) -> (# s', W# a #)) + (\arr i (W# a) s -> writeWord8ArrayAsWord# arr i a s) word wordSizeInBytes test @@ -257,7 +266,7 @@ main = do case readWord8ArrayAsChar# arr i s of (# s', a #) -> (# s', C# a #)) (\arr i (C# a) s -> writeWord8ArrayAsChar# arr i a s) 'z' - [ord 'z'] + [fromIntegral $ ord 'z'] 1 test "WideChar#" @@ -266,7 +275,7 @@ main = do case readWord8ArrayAsWideChar# arr i s of (# s', a #) -> (# s', C# a #)) (\arr i (C# a) s -> writeWord8ArrayAsWideChar# arr i a s) '𠜎' -- See http://www.i18nguy.com/unicode/supplementary-test.html - (intToBytes (ord '𠜎') 4) + (intToBytes (fromIntegral $ ord '𠜎') 4) 4 test "Addr#" @@ -275,7 +284,7 @@ main = do case readWord8ArrayAsAddr# arr i s of (# s', a #) -> (# s', Ptr a #)) (\arr i (Ptr a) s -> writeWord8ArrayAsAddr# arr i a s) (nullPtr `plusPtr` int) - (intToBytes int wordSizeInBytes) + (intToBytes word wordSizeInBytes) wordSizeInBytes stablePtr <- newStablePtr () @@ -288,7 +297,7 @@ main = do (\arr i p s -> case castPtrToStablePtr p of (StablePtr a) -> writeWord8ArrayAsStablePtr# arr i a s) (castStablePtrToPtr stablePtr) - (intToBytes (castStablePtrToPtr stablePtr `minusPtr` nullPtr) + (intToBytes (fromIntegral $ castStablePtrToPtr stablePtr `minusPtr` nullPtr) wordSizeInBytes) wordSizeInBytes |