summaryrefslogtreecommitdiff
path: root/libraries
diff options
context:
space:
mode:
authorMoritz Angermann <moritz.angermann@gmail.com>2020-10-22 12:08:34 +0800
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-11-26 16:00:32 -0500
commitbe5d74caab64abf9d986fc7290f62731db7e73e7 (patch)
tree7b1f374333ff0fb0449e9c6834c2a8210cfba7c5 /libraries
parent2ed3e6c0f179c06828712832d1176519cdfa82a6 (diff)
downloadhaskell-be5d74caab64abf9d986fc7290f62731db7e73e7.tar.gz
[Sized Cmm] properly retain sizes.
This replaces all Word<N> = W<N># Word# and Int<N> = I<N># Int# with Word<N> = W<N># Word<N># and Int<N> = I<N># Int<N>#, thus providing us with properly sized primitives in the codegenerator instead of pretending they are all full machine words. This came up when implementing darwinpcs for arm64. The darwinpcs reqires us to pack function argugments in excess of registers on the stack. While most procedure call standards (pcs) assume arguments are just passed in 8 byte slots; and thus the caller does not know the exact signature to make the call, darwinpcs requires us to adhere to the prototype, and thus have the correct sizes. If we specify CInt in the FFI call, it should correspond to the C int, and not just be Word sized, when it's only half the size. This does change the expected output of T16402 but the new result is no less correct as it eliminates the narrowing (instead of the `and` as was previously done). Bumps the array, bytestring, text, and binary submodules. Co-Authored-By: Ben Gamari <ben@well-typed.com> Metric Increase: T13701 T14697
Diffstat (limited to 'libraries')
m---------libraries/array0
-rw-r--r--libraries/base/GHC/Float.hs4
-rw-r--r--libraries/base/GHC/IO/Encoding/CodePage.hs2
-rw-r--r--libraries/base/GHC/IO/Encoding/UTF16.hs5
-rw-r--r--libraries/base/GHC/IO/Encoding/UTF32.hs9
-rw-r--r--libraries/base/GHC/IO/Encoding/UTF8.hs35
-rw-r--r--libraries/base/GHC/Int.hs266
-rw-r--r--libraries/base/GHC/Storable.hs24
-rw-r--r--libraries/base/GHC/Word.hs268
-rw-r--r--libraries/base/base.cabal2
m---------libraries/binary0
m---------libraries/bytestring0
-rw-r--r--libraries/ghc-bignum/ghc-bignum.cabal2
-rw-r--r--libraries/ghc-compact/ghc-compact.cabal2
-rw-r--r--libraries/ghc-heap/ghc-heap.cabal.in2
-rw-r--r--libraries/ghc-prim/ghc-prim.cabal2
-rw-r--r--libraries/ghci/GHCi/BreakArray.hs18
-rw-r--r--libraries/ghci/ghci.cabal.in1
m---------libraries/text0
19 files changed, 326 insertions, 316 deletions
diff --git a/libraries/array b/libraries/array
-Subproject 10e6c7e0522367677e4c33cc1c56eb852ef1342
+Subproject c7a696e3e6d5a6b00d3e00ca694af916f15bcff
diff --git a/libraries/base/GHC/Float.hs b/libraries/base/GHC/Float.hs
index 67cc11f9a9..5b859b1db9 100644
--- a/libraries/base/GHC/Float.hs
+++ b/libraries/base/GHC/Float.hs
@@ -1394,7 +1394,7 @@ castWord32ToFloat :: Word32 -> Float
castWord32ToFloat (W32# w#) = F# (stgWord32ToFloat w#)
foreign import prim "stg_word32ToFloatzh"
- stgWord32ToFloat :: Word# -> Float#
+ stgWord32ToFloat :: Word32# -> Float#
-- | @'castFloatToWord32' f@ does a bit-for-bit copy from a floating-point value
@@ -1407,7 +1407,7 @@ castFloatToWord32 :: Float -> Word32
castFloatToWord32 (F# f#) = W32# (stgFloatToWord32 f#)
foreign import prim "stg_floatToWord32zh"
- stgFloatToWord32 :: Float# -> Word#
+ stgFloatToWord32 :: Float# -> Word32#
diff --git a/libraries/base/GHC/IO/Encoding/CodePage.hs b/libraries/base/GHC/IO/Encoding/CodePage.hs
index 2532e071e6..6c77e65c41 100644
--- a/libraries/base/GHC/IO/Encoding/CodePage.hs
+++ b/libraries/base/GHC/IO/Encoding/CodePage.hs
@@ -174,7 +174,7 @@ indexInt (ConvArray p) (I# i) = I# (indexInt16OffAddr# p i)
{-# INLINE indexWord8 #-}
indexWord8 :: ConvArray Word8 -> Int -> Word8
-indexWord8 (ConvArray p) (I# i) = W8# (indexWord8OffAddr# p i)
+indexWord8 (ConvArray p) (I# i) = W8# (narrowWord8# (indexWord8OffAddr# p i))
{-# INLINE indexChar #-}
indexChar :: ConvArray Char -> Int -> Char
diff --git a/libraries/base/GHC/IO/Encoding/UTF16.hs b/libraries/base/GHC/IO/Encoding/UTF16.hs
index 192f30beb9..c77c131eef 100644
--- a/libraries/base/GHC/IO/Encoding/UTF16.hs
+++ b/libraries/base/GHC/IO/Encoding/UTF16.hs
@@ -342,8 +342,8 @@ utf16le_encode
chr2 :: Word16 -> Word16 -> Char
chr2 (W16# a#) (W16# b#) = C# (chr# (upper# +# lower# +# 0x10000#))
where
- !x# = word2Int# a#
- !y# = word2Int# b#
+ !x# = word2Int# (extendWord16# a#)
+ !y# = word2Int# (extendWord16# b#)
!upper# = uncheckedIShiftL# (x# -# 0xD800#) 10#
!lower# = y# -# 0xDC00#
{-# INLINE chr2 #-}
@@ -356,4 +356,3 @@ validate2 :: Word16 -> Word16 -> Bool
validate2 x1 x2 = x1 >= 0xD800 && x1 <= 0xDBFF &&
x2 >= 0xDC00 && x2 <= 0xDFFF
{-# INLINE validate2 #-}
-
diff --git a/libraries/base/GHC/IO/Encoding/UTF32.hs b/libraries/base/GHC/IO/Encoding/UTF32.hs
index 26b5e448ca..c14b365a04 100644
--- a/libraries/base/GHC/IO/Encoding/UTF32.hs
+++ b/libraries/base/GHC/IO/Encoding/UTF32.hs
@@ -309,10 +309,10 @@ chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char
chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
C# (chr# (z1# +# z2# +# z3# +# z4#))
where
- !y1# = word2Int# x1#
- !y2# = word2Int# x2#
- !y3# = word2Int# x3#
- !y4# = word2Int# x4#
+ !y1# = word2Int# (extendWord8# x1#)
+ !y2# = word2Int# (extendWord8# x2#)
+ !y3# = word2Int# (extendWord8# x3#)
+ !y4# = word2Int# (extendWord8# x4#)
!z1# = uncheckedIShiftL# y1# 24#
!z2# = uncheckedIShiftL# y2# 16#
!z3# = uncheckedIShiftL# y3# 8#
@@ -333,4 +333,3 @@ validate :: Char -> Bool
validate c = (x1 >= 0x0 && x1 < 0xD800) || (x1 > 0xDFFF && x1 <= 0x10FFFF)
where x1 = ord c
{-# INLINE validate #-}
-
diff --git a/libraries/base/GHC/IO/Encoding/UTF8.hs b/libraries/base/GHC/IO/Encoding/UTF8.hs
index 18d034ad15..d887a92960 100644
--- a/libraries/base/GHC/IO/Encoding/UTF8.hs
+++ b/libraries/base/GHC/IO/Encoding/UTF8.hs
@@ -11,7 +11,7 @@
-- Module : GHC.IO.Encoding.UTF8
-- Copyright : (c) The University of Glasgow, 2009
-- License : see libraries/base/LICENSE
---
+--
-- Maintainer : libraries@haskell.org
-- Stability : internal
-- Portability : non-portable
@@ -144,17 +144,17 @@ bom1 = 0xbb
bom2 = 0xbf
utf8_decode :: DecodeBuffer
-utf8_decode
+utf8_decode
input@Buffer{ bufRaw=iraw, bufL=ir0, bufR=iw, bufSize=_ }
output@Buffer{ bufRaw=oraw, bufL=_, bufR=ow0, bufSize=os }
- = let
+ = let
loop !ir !ow
| ow >= os = done OutputUnderflow ir ow
| ir >= iw = done InputUnderflow ir ow
| otherwise = do
c0 <- readWord8Buf iraw ir
case c0 of
- _ | c0 <= 0x7f -> do
+ _ | c0 <= 0x7f -> do
ow' <- writeCharBuf oraw ow (unsafeChr (fromIntegral c0))
loop (ir+1) ow'
| c0 >= 0xc0 && c0 <= 0xc1 -> invalid -- Overlong forms
@@ -170,7 +170,7 @@ utf8_decode
2 -> do -- check for an error even when we don't have
-- the full sequence yet (#3341)
c1 <- readWord8Buf iraw (ir+1)
- if not (validate3 c0 c1 0x80)
+ if not (validate3 c0 c1 0x80)
then invalid else done InputUnderflow ir ow
_ -> do
c1 <- readWord8Buf iraw (ir+1)
@@ -215,7 +215,7 @@ utf8_encode :: EncodeBuffer
utf8_encode
input@Buffer{ bufRaw=iraw, bufL=ir0, bufR=iw, bufSize=_ }
output@Buffer{ bufRaw=oraw, bufL=_, bufR=ow0, bufSize=os }
- = let
+ = let
done why !ir !ow = return (why,
if ir == iw then input{ bufL=0, bufR=0 }
else input{ bufL=ir },
@@ -255,7 +255,7 @@ utf8_encode
-- -----------------------------------------------------------------------------
-- UTF-8 primitives, lifted from Data.Text.Fusion.Utf8
-
+
ord2 :: Char -> (Word8,Word8)
ord2 c = assert (n >= 0x80 && n <= 0x07ff) (x1,x2)
where
@@ -283,8 +283,8 @@ ord4 c = assert (n >= 0x10000) (x1,x2,x3,x4)
chr2 :: Word8 -> Word8 -> Char
chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
where
- !y1# = word2Int# x1#
- !y2# = word2Int# x2#
+ !y1# = word2Int# (extendWord8# x1#)
+ !y2# = word2Int# (extendWord8# x2#)
!z1# = uncheckedIShiftL# (y1# -# 0xC0#) 6#
!z2# = y2# -# 0x80#
{-# INLINE chr2 #-}
@@ -292,9 +292,9 @@ chr2 (W8# x1#) (W8# x2#) = C# (chr# (z1# +# z2#))
chr3 :: Word8 -> Word8 -> Word8 -> Char
chr3 (W8# x1#) (W8# x2#) (W8# x3#) = C# (chr# (z1# +# z2# +# z3#))
where
- !y1# = word2Int# x1#
- !y2# = word2Int# x2#
- !y3# = word2Int# x3#
+ !y1# = word2Int# (extendWord8# x1#)
+ !y2# = word2Int# (extendWord8# x2#)
+ !y3# = word2Int# (extendWord8# x3#)
!z1# = uncheckedIShiftL# (y1# -# 0xE0#) 12#
!z2# = uncheckedIShiftL# (y2# -# 0x80#) 6#
!z3# = y3# -# 0x80#
@@ -304,10 +304,10 @@ chr4 :: Word8 -> Word8 -> Word8 -> Word8 -> Char
chr4 (W8# x1#) (W8# x2#) (W8# x3#) (W8# x4#) =
C# (chr# (z1# +# z2# +# z3# +# z4#))
where
- !y1# = word2Int# x1#
- !y2# = word2Int# x2#
- !y3# = word2Int# x3#
- !y4# = word2Int# x4#
+ !y1# = word2Int# (extendWord8# x1#)
+ !y2# = word2Int# (extendWord8# x2#)
+ !y3# = word2Int# (extendWord8# x3#)
+ !y4# = word2Int# (extendWord8# x4#)
!z1# = uncheckedIShiftL# (y1# -# 0xF0#) 18#
!z2# = uncheckedIShiftL# (y2# -# 0x80#) 12#
!z3# = uncheckedIShiftL# (y3# -# 0x80#) 6#
@@ -346,7 +346,7 @@ validate4 :: Word8 -> Word8 -> Word8 -> Word8 -> Bool
validate4 x1 x2 x3 x4 = validate4_1 ||
validate4_2 ||
validate4_3
- where
+ where
validate4_1 = x1 == 0xF0 &&
between x2 0x90 0xBF &&
between x3 0x80 0xBF &&
@@ -359,4 +359,3 @@ validate4 x1 x2 x3 x4 = validate4_1 ||
between x2 0x80 0x8F &&
between x3 0x80 0xBF &&
between x4 0x80 0xBF
-
diff --git a/libraries/base/GHC/Int.hs b/libraries/base/GHC/Int.hs
index 5449a79c8f..08827e92c4 100644
--- a/libraries/base/GHC/Int.hs
+++ b/libraries/base/GHC/Int.hs
@@ -59,7 +59,7 @@ import GHC.Show
-- Int8 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsInt8" #-} Int8 = I8# Int#
+data {-# CTYPE "HsInt8" #-} Int8 = I8# Int8#
-- ^ 8-bit signed integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -69,8 +69,8 @@ instance Eq Int8 where
(/=) = neInt8
eqInt8, neInt8 :: Int8 -> Int8 -> Bool
-eqInt8 (I8# x) (I8# y) = isTrue# (x ==# y)
-neInt8 (I8# x) (I8# y) = isTrue# (x /=# y)
+eqInt8 (I8# x) (I8# y) = isTrue# ((extendInt8# x) ==# (extendInt8# y))
+neInt8 (I8# x) (I8# y) = isTrue# ((extendInt8# x) /=# (extendInt8# y))
{-# INLINE [1] eqInt8 #-}
{-# INLINE [1] neInt8 #-}
@@ -86,10 +86,10 @@ instance Ord Int8 where
{-# INLINE [1] ltInt8 #-}
{-# INLINE [1] leInt8 #-}
gtInt8, geInt8, ltInt8, leInt8 :: Int8 -> Int8 -> Bool
-(I8# x) `gtInt8` (I8# y) = isTrue# (x ># y)
-(I8# x) `geInt8` (I8# y) = isTrue# (x >=# y)
-(I8# x) `ltInt8` (I8# y) = isTrue# (x <# y)
-(I8# x) `leInt8` (I8# y) = isTrue# (x <=# y)
+(I8# x) `gtInt8` (I8# y) = isTrue# ((extendInt8# x) ># (extendInt8# y))
+(I8# x) `geInt8` (I8# y) = isTrue# ((extendInt8# x) >=# (extendInt8# y))
+(I8# x) `ltInt8` (I8# y) = isTrue# ((extendInt8# x) <# (extendInt8# y))
+(I8# x) `leInt8` (I8# y) = isTrue# ((extendInt8# x) <=# (extendInt8# y))
-- | @since 2.01
instance Show Int8 where
@@ -97,16 +97,16 @@ instance Show Int8 where
-- | @since 2.01
instance Num Int8 where
- (I8# x#) + (I8# y#) = I8# (narrow8Int# (x# +# y#))
- (I8# x#) - (I8# y#) = I8# (narrow8Int# (x# -# y#))
- (I8# x#) * (I8# y#) = I8# (narrow8Int# (x# *# y#))
- negate (I8# x#) = I8# (narrow8Int# (negateInt# x#))
+ (I8# x#) + (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) +# (extendInt8# y#)))
+ (I8# x#) - (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) -# (extendInt8# y#)))
+ (I8# x#) * (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) *# (extendInt8# y#)))
+ negate (I8# x#) = I8# (narrowInt8# (negateInt# (extendInt8# x#)))
abs x | x >= 0 = x
| otherwise = negate x
signum x | x > 0 = 1
signum 0 = 0
signum _ = -1
- fromInteger i = I8# (narrow8Int# (integerToInt# i))
+ fromInteger i = I8# (narrowInt8# (integerToInt# i))
-- | @since 2.01
instance Real Int8 where
@@ -122,9 +122,9 @@ instance Enum Int8 where
| otherwise = predError "Int8"
toEnum i@(I# i#)
| i >= fromIntegral (minBound::Int8) && i <= fromIntegral (maxBound::Int8)
- = I8# i#
+ = I8# (narrowInt8# i#)
| otherwise = toEnumError "Int8" i (minBound::Int8, maxBound::Int8)
- fromEnum (I8# x#) = I# x#
+ fromEnum (I8# x#) = I# (extendInt8# x#)
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
@@ -133,34 +133,34 @@ instance Integral Int8 where
quot x@(I8# x#) y@(I8# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I8# (narrow8Int# (x# `quotInt#` y#))
+ | otherwise = I8# (narrowInt8# ((extendInt8# x#) `quotInt#` (extendInt8# y#)))
rem (I8# x#) y@(I8# y#)
| y == 0 = divZeroError
- | otherwise = I8# (narrow8Int# (x# `remInt#` y#))
+ | otherwise = I8# (narrowInt8# ((extendInt8# x#) `remInt#` (extendInt8# y#)))
div x@(I8# x#) y@(I8# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I8# (narrow8Int# (x# `divInt#` y#))
+ | otherwise = I8# (narrowInt8# ((extendInt8# x#) `divInt#` (extendInt8# y#)))
mod (I8# x#) y@(I8# y#)
| y == 0 = divZeroError
- | otherwise = I8# (narrow8Int# (x# `modInt#` y#))
+ | otherwise = I8# (narrowInt8# ((extendInt8# x#) `modInt#` (extendInt8# y#)))
quotRem x@(I8# x#) y@(I8# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `quotRemInt#` y# of
+ | otherwise = case (extendInt8# x#) `quotRemInt#` (extendInt8# y#) of
(# q, r #) ->
- (I8# (narrow8Int# q),
- I8# (narrow8Int# r))
+ (I8# (narrowInt8# q),
+ I8# (narrowInt8# r))
divMod x@(I8# x#) y@(I8# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `divModInt#` y# of
+ | otherwise = case (extendInt8# x#) `divModInt#` (extendInt8# y#) of
(# d, m #) ->
- (I8# (narrow8Int# d),
- I8# (narrow8Int# m))
- toInteger (I8# x#) = IS x#
+ (I8# (narrowInt8# d),
+ I8# (narrowInt8# m))
+ toInteger (I8# x#) = IS (extendInt8# x#)
-- | @since 2.01
instance Bounded Int8 where
@@ -184,34 +184,34 @@ instance Bits Int8 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (I8# x#) .&. (I8# y#) = I8# (x# `andI#` y#)
- (I8# x#) .|. (I8# y#) = I8# (x# `orI#` y#)
- (I8# x#) `xor` (I8# y#) = I8# (x# `xorI#` y#)
- complement (I8# x#) = I8# (notI# x#)
+ (I8# x#) .&. (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `andI#` (extendInt8# y#)))
+ (I8# x#) .|. (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `orI#` (extendInt8# y#)))
+ (I8# x#) `xor` (I8# y#) = I8# (narrowInt8# ((extendInt8# x#) `xorI#` (extendInt8# y#)))
+ complement (I8# x#) = I8# (narrowInt8# (notI# (extendInt8# x#)))
(I8# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = I8# (narrow8Int# (x# `iShiftL#` i#))
- | otherwise = I8# (x# `iShiftRA#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftL#` i#))
+ | otherwise = I8# (narrowInt8# ((extendInt8# x#) `iShiftRA#` negateInt# i#))
(I8# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = I8# (narrow8Int# (x# `iShiftL#` i#))
+ | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftL#` i#))
| otherwise = overflowError
- (I8# x#) `unsafeShiftL` (I# i#) = I8# (narrow8Int# (x# `uncheckedIShiftL#` i#))
+ (I8# x#) `unsafeShiftL` (I# i#) = I8# (narrowInt8# ((extendInt8# x#) `uncheckedIShiftL#` i#))
(I8# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = I8# (x# `iShiftRA#` i#)
+ | isTrue# (i# >=# 0#) = I8# (narrowInt8# ((extendInt8# x#) `iShiftRA#` i#))
| otherwise = overflowError
- (I8# x#) `unsafeShiftR` (I# i#) = I8# (x# `uncheckedIShiftRA#` i#)
+ (I8# x#) `unsafeShiftR` (I# i#) = I8# (narrowInt8# ((extendInt8# x#) `uncheckedIShiftRA#` i#))
(I8# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#)
= I8# x#
| otherwise
- = I8# (narrow8Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
+ = I8# (narrowInt8# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
(x'# `uncheckedShiftRL#` (8# -# i'#)))))
where
- !x'# = narrow8Word# (int2Word# x#)
+ !x'# = narrow8Word# (int2Word# (extendInt8# x#))
!i'# = word2Int# (int2Word# i# `and#` 7##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = True
- popCount (I8# x#) = I# (word2Int# (popCnt8# (int2Word# x#)))
+ popCount (I8# x#) = I# (word2Int# (popCnt8# (int2Word# (extendInt8# x#))))
bit = bitDefault
testBit = testBitDefault
@@ -220,13 +220,13 @@ instance FiniteBits Int8 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 8
- countLeadingZeros (I8# x#) = I# (word2Int# (clz8# (int2Word# x#)))
- countTrailingZeros (I8# x#) = I# (word2Int# (ctz8# (int2Word# x#)))
+ countLeadingZeros (I8# x#) = I# (word2Int# (clz8# (int2Word# (extendInt8# x#))))
+ countTrailingZeros (I8# x#) = I# (word2Int# (ctz8# (int2Word# (extendInt8# x#))))
{-# RULES
"fromIntegral/Int8->Int8" fromIntegral = id :: Int8 -> Int8
-"fromIntegral/a->Int8" fromIntegral = \x -> case fromIntegral x of I# x# -> I8# (narrow8Int# x#)
-"fromIntegral/Int8->a" fromIntegral = \(I8# x#) -> fromIntegral (I# x#)
+"fromIntegral/a->Int8" fromIntegral = \x -> case fromIntegral x of I# x# -> I8# (narrowInt8# x#)
+"fromIntegral/Int8->a" fromIntegral = \(I8# x#) -> fromIntegral (I# (extendInt8# x#))
#-}
{-# RULES
@@ -266,7 +266,7 @@ instance FiniteBits Int8 where
-- Int16 is represented in the same way as Int. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsInt16" #-} Int16 = I16# Int#
+data {-# CTYPE "HsInt16" #-} Int16 = I16# Int16#
-- ^ 16-bit signed integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -276,8 +276,8 @@ instance Eq Int16 where
(/=) = neInt16
eqInt16, neInt16 :: Int16 -> Int16 -> Bool
-eqInt16 (I16# x) (I16# y) = isTrue# (x ==# y)
-neInt16 (I16# x) (I16# y) = isTrue# (x /=# y)
+eqInt16 (I16# x) (I16# y) = isTrue# ((extendInt16# x) ==# (extendInt16# y))
+neInt16 (I16# x) (I16# y) = isTrue# ((extendInt16# x) /=# (extendInt16# y))
{-# INLINE [1] eqInt16 #-}
{-# INLINE [1] neInt16 #-}
@@ -293,10 +293,10 @@ instance Ord Int16 where
{-# INLINE [1] ltInt16 #-}
{-# INLINE [1] leInt16 #-}
gtInt16, geInt16, ltInt16, leInt16 :: Int16 -> Int16 -> Bool
-(I16# x) `gtInt16` (I16# y) = isTrue# (x ># y)
-(I16# x) `geInt16` (I16# y) = isTrue# (x >=# y)
-(I16# x) `ltInt16` (I16# y) = isTrue# (x <# y)
-(I16# x) `leInt16` (I16# y) = isTrue# (x <=# y)
+(I16# x) `gtInt16` (I16# y) = isTrue# ((extendInt16# x) ># (extendInt16# y))
+(I16# x) `geInt16` (I16# y) = isTrue# ((extendInt16# x) >=# (extendInt16# y))
+(I16# x) `ltInt16` (I16# y) = isTrue# ((extendInt16# x) <# (extendInt16# y))
+(I16# x) `leInt16` (I16# y) = isTrue# ((extendInt16# x) <=# (extendInt16# y))
-- | @since 2.01
instance Show Int16 where
@@ -304,16 +304,16 @@ instance Show Int16 where
-- | @since 2.01
instance Num Int16 where
- (I16# x#) + (I16# y#) = I16# (narrow16Int# (x# +# y#))
- (I16# x#) - (I16# y#) = I16# (narrow16Int# (x# -# y#))
- (I16# x#) * (I16# y#) = I16# (narrow16Int# (x# *# y#))
- negate (I16# x#) = I16# (narrow16Int# (negateInt# x#))
+ (I16# x#) + (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) +# (extendInt16# y#)))
+ (I16# x#) - (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) -# (extendInt16# y#)))
+ (I16# x#) * (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) *# (extendInt16# y#)))
+ negate (I16# x#) = I16# (narrowInt16# (negateInt# (extendInt16# x#)))
abs x | x >= 0 = x
| otherwise = negate x
signum x | x > 0 = 1
signum 0 = 0
signum _ = -1
- fromInteger i = I16# (narrow16Int# (integerToInt# i))
+ fromInteger i = I16# (narrowInt16# (integerToInt# i))
-- | @since 2.01
instance Real Int16 where
@@ -329,9 +329,9 @@ instance Enum Int16 where
| otherwise = predError "Int16"
toEnum i@(I# i#)
| i >= fromIntegral (minBound::Int16) && i <= fromIntegral (maxBound::Int16)
- = I16# i#
+ = I16# (narrowInt16# i#)
| otherwise = toEnumError "Int16" i (minBound::Int16, maxBound::Int16)
- fromEnum (I16# x#) = I# x#
+ fromEnum (I16# x#) = I# (extendInt16# x#)
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
@@ -340,34 +340,34 @@ instance Integral Int16 where
quot x@(I16# x#) y@(I16# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I16# (narrow16Int# (x# `quotInt#` y#))
+ | otherwise = I16# (narrowInt16# ((extendInt16# x#) `quotInt#` (extendInt16# y#)))
rem (I16# x#) y@(I16# y#)
| y == 0 = divZeroError
- | otherwise = I16# (narrow16Int# (x# `remInt#` y#))
+ | otherwise = I16# (narrowInt16# ((extendInt16# x#) `remInt#` (extendInt16# y#)))
div x@(I16# x#) y@(I16# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I16# (narrow16Int# (x# `divInt#` y#))
+ | otherwise = I16# (narrowInt16# ((extendInt16# x#) `divInt#` (extendInt16# y#)))
mod (I16# x#) y@(I16# y#)
| y == 0 = divZeroError
- | otherwise = I16# (narrow16Int# (x# `modInt#` y#))
+ | otherwise = I16# (narrowInt16# ((extendInt16# x#) `modInt#` (extendInt16# y#)))
quotRem x@(I16# x#) y@(I16# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `quotRemInt#` y# of
+ | otherwise = case (extendInt16# x#) `quotRemInt#` (extendInt16# y#) of
(# q, r #) ->
- (I16# (narrow16Int# q),
- I16# (narrow16Int# r))
+ (I16# (narrowInt16# q),
+ I16# (narrowInt16# r))
divMod x@(I16# x#) y@(I16# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `divModInt#` y# of
+ | otherwise = case (extendInt16# x#) `divModInt#` (extendInt16# y#) of
(# d, m #) ->
- (I16# (narrow16Int# d),
- I16# (narrow16Int# m))
- toInteger (I16# x#) = IS x#
+ (I16# (narrowInt16# d),
+ I16# (narrowInt16# m))
+ toInteger (I16# x#) = IS (extendInt16# x#)
-- | @since 2.01
instance Bounded Int16 where
@@ -391,34 +391,34 @@ instance Bits Int16 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (I16# x#) .&. (I16# y#) = I16# (x# `andI#` y#)
- (I16# x#) .|. (I16# y#) = I16# (x# `orI#` y#)
- (I16# x#) `xor` (I16# y#) = I16# (x# `xorI#` y#)
- complement (I16# x#) = I16# (notI# x#)
+ (I16# x#) .&. (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `andI#` (extendInt16# y#)))
+ (I16# x#) .|. (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `orI#` (extendInt16# y#)))
+ (I16# x#) `xor` (I16# y#) = I16# (narrowInt16# ((extendInt16# x#) `xorI#` (extendInt16# y#)))
+ complement (I16# x#) = I16# (narrowInt16# (notI# (extendInt16# x#)))
(I16# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = I16# (narrow16Int# (x# `iShiftL#` i#))
- | otherwise = I16# (x# `iShiftRA#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftL#` i#))
+ | otherwise = I16# (narrowInt16# ((extendInt16# x#) `iShiftRA#` negateInt# i#))
(I16# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = I16# (narrow16Int# (x# `iShiftL#` i#))
+ | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftL#` i#))
| otherwise = overflowError
- (I16# x#) `unsafeShiftL` (I# i#) = I16# (narrow16Int# (x# `uncheckedIShiftL#` i#))
+ (I16# x#) `unsafeShiftL` (I# i#) = I16# (narrowInt16# ((extendInt16# x#) `uncheckedIShiftL#` i#))
(I16# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = I16# (x# `iShiftRA#` i#)
+ | isTrue# (i# >=# 0#) = I16# (narrowInt16# ((extendInt16# x#) `iShiftRA#` i#))
| otherwise = overflowError
- (I16# x#) `unsafeShiftR` (I# i#) = I16# (x# `uncheckedIShiftRA#` i#)
+ (I16# x#) `unsafeShiftR` (I# i#) = I16# (narrowInt16# ((extendInt16# x#) `uncheckedIShiftRA#` i#))
(I16# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#)
= I16# x#
| otherwise
- = I16# (narrow16Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
+ = I16# (narrowInt16# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
(x'# `uncheckedShiftRL#` (16# -# i'#)))))
where
- !x'# = narrow16Word# (int2Word# x#)
+ !x'# = narrow16Word# (int2Word# (extendInt16# x#))
!i'# = word2Int# (int2Word# i# `and#` 15##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = True
- popCount (I16# x#) = I# (word2Int# (popCnt16# (int2Word# x#)))
+ popCount (I16# x#) = I# (word2Int# (popCnt16# (int2Word# (extendInt16# x#))))
bit = bitDefault
testBit = testBitDefault
@@ -427,15 +427,15 @@ instance FiniteBits Int16 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 16
- countLeadingZeros (I16# x#) = I# (word2Int# (clz16# (int2Word# x#)))
- countTrailingZeros (I16# x#) = I# (word2Int# (ctz16# (int2Word# x#)))
+ countLeadingZeros (I16# x#) = I# (word2Int# (clz16# (int2Word# (extendInt16# x#))))
+ countTrailingZeros (I16# x#) = I# (word2Int# (ctz16# (int2Word# (extendInt16# x#))))
{-# RULES
-"fromIntegral/Word8->Int16" fromIntegral = \(W8# x#) -> I16# (word2Int# x#)
-"fromIntegral/Int8->Int16" fromIntegral = \(I8# x#) -> I16# x#
+"fromIntegral/Word8->Int16" fromIntegral = \(W8# x#) -> I16# (narrowInt16# (word2Int# (extendWord8# x#)))
+"fromIntegral/Int8->Int16" fromIntegral = \(I8# x#) -> I16# (narrowInt16# (extendInt8# x#))
"fromIntegral/Int16->Int16" fromIntegral = id :: Int16 -> Int16
-"fromIntegral/a->Int16" fromIntegral = \x -> case fromIntegral x of I# x# -> I16# (narrow16Int# x#)
-"fromIntegral/Int16->a" fromIntegral = \(I16# x#) -> fromIntegral (I# x#)
+"fromIntegral/a->Int16" fromIntegral = \x -> case fromIntegral x of I# x# -> I16# (narrowInt16# x#)
+"fromIntegral/Int16->a" fromIntegral = \(I16# x#) -> fromIntegral (I# (extendInt16# x#))
#-}
{-# RULES
@@ -478,7 +478,7 @@ instance FiniteBits Int16 where
-- from its logical range.
#endif
-data {-# CTYPE "HsInt32" #-} Int32 = I32# Int#
+data {-# CTYPE "HsInt32" #-} Int32 = I32# Int32#
-- ^ 32-bit signed integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -488,8 +488,8 @@ instance Eq Int32 where
(/=) = neInt32
eqInt32, neInt32 :: Int32 -> Int32 -> Bool
-eqInt32 (I32# x) (I32# y) = isTrue# (x ==# y)
-neInt32 (I32# x) (I32# y) = isTrue# (x /=# y)
+eqInt32 (I32# x) (I32# y) = isTrue# ((extendInt32# x) ==# (extendInt32# y))
+neInt32 (I32# x) (I32# y) = isTrue# ((extendInt32# x) /=# (extendInt32# y))
{-# INLINE [1] eqInt32 #-}
{-# INLINE [1] neInt32 #-}
@@ -505,10 +505,10 @@ instance Ord Int32 where
{-# INLINE [1] ltInt32 #-}
{-# INLINE [1] leInt32 #-}
gtInt32, geInt32, ltInt32, leInt32 :: Int32 -> Int32 -> Bool
-(I32# x) `gtInt32` (I32# y) = isTrue# (x ># y)
-(I32# x) `geInt32` (I32# y) = isTrue# (x >=# y)
-(I32# x) `ltInt32` (I32# y) = isTrue# (x <# y)
-(I32# x) `leInt32` (I32# y) = isTrue# (x <=# y)
+(I32# x) `gtInt32` (I32# y) = isTrue# ((extendInt32# x) ># (extendInt32# y))
+(I32# x) `geInt32` (I32# y) = isTrue# ((extendInt32# x) >=# (extendInt32# y))
+(I32# x) `ltInt32` (I32# y) = isTrue# ((extendInt32# x) <# (extendInt32# y))
+(I32# x) `leInt32` (I32# y) = isTrue# ((extendInt32# x) <=# (extendInt32# y))
-- | @since 2.01
instance Show Int32 where
@@ -516,16 +516,16 @@ instance Show Int32 where
-- | @since 2.01
instance Num Int32 where
- (I32# x#) + (I32# y#) = I32# (narrow32Int# (x# +# y#))
- (I32# x#) - (I32# y#) = I32# (narrow32Int# (x# -# y#))
- (I32# x#) * (I32# y#) = I32# (narrow32Int# (x# *# y#))
- negate (I32# x#) = I32# (narrow32Int# (negateInt# x#))
+ (I32# x#) + (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) +# (extendInt32# y#)))
+ (I32# x#) - (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) -# (extendInt32# y#)))
+ (I32# x#) * (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) *# (extendInt32# y#)))
+ negate (I32# x#) = I32# (narrowInt32# (negateInt# (extendInt32# x#)))
abs x | x >= 0 = x
| otherwise = negate x
signum x | x > 0 = 1
signum 0 = 0
signum _ = -1
- fromInteger i = I32# (narrow32Int# (integerToInt# i))
+ fromInteger i = I32# (narrowInt32# (integerToInt# i))
-- | @since 2.01
instance Enum Int32 where
@@ -536,14 +536,14 @@ instance Enum Int32 where
| x /= minBound = x - 1
| otherwise = predError "Int32"
#if WORD_SIZE_IN_BITS == 32
- toEnum (I# i#) = I32# i#
+ toEnum (I# i#) = I32# (narrowInt32# i#)
#else
toEnum i@(I# i#)
| i >= fromIntegral (minBound::Int32) && i <= fromIntegral (maxBound::Int32)
- = I32# i#
+ = I32# (narrowInt32# i#)
| otherwise = toEnumError "Int32" i (minBound::Int32, maxBound::Int32)
#endif
- fromEnum (I32# x#) = I# x#
+ fromEnum (I32# x#) = I# (extendInt32# x#)
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
@@ -552,42 +552,42 @@ instance Integral Int32 where
quot x@(I32# x#) y@(I32# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I32# (narrow32Int# (x# `quotInt#` y#))
+ | otherwise = I32# (narrowInt32# ((extendInt32# x#) `quotInt#` (extendInt32# y#)))
rem (I32# x#) y@(I32# y#)
| y == 0 = divZeroError
-- The quotRem CPU instruction fails for minBound `quotRem` -1,
-- but minBound `rem` -1 is well-defined (0). We therefore
-- special-case it.
| y == (-1) = 0
- | otherwise = I32# (narrow32Int# (x# `remInt#` y#))
+ | otherwise = I32# (narrowInt32# ((extendInt32# x#) `remInt#` (extendInt32# y#)))
div x@(I32# x#) y@(I32# y#)
| y == 0 = divZeroError
| y == (-1) && x == minBound = overflowError -- Note [Order of tests]
- | otherwise = I32# (narrow32Int# (x# `divInt#` y#))
+ | otherwise = I32# (narrowInt32# ((extendInt32# x#) `divInt#` (extendInt32# y#)))
mod (I32# x#) y@(I32# y#)
| y == 0 = divZeroError
-- The divMod CPU instruction fails for minBound `divMod` -1,
-- but minBound `mod` -1 is well-defined (0). We therefore
-- special-case it.
| y == (-1) = 0
- | otherwise = I32# (narrow32Int# (x# `modInt#` y#))
+ | otherwise = I32# (narrowInt32# ((extendInt32# x#) `modInt#` (extendInt32# y#)))
quotRem x@(I32# x#) y@(I32# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `quotRemInt#` y# of
+ | otherwise = case (extendInt32# x#) `quotRemInt#` (extendInt32# y#) of
(# q, r #) ->
- (I32# (narrow32Int# q),
- I32# (narrow32Int# r))
+ (I32# (narrowInt32# q),
+ I32# (narrowInt32# r))
divMod x@(I32# x#) y@(I32# y#)
| y == 0 = divZeroError
-- Note [Order of tests]
| y == (-1) && x == minBound = (overflowError, 0)
- | otherwise = case x# `divModInt#` y# of
+ | otherwise = case (extendInt32# x#) `divModInt#` (extendInt32# y#) of
(# d, m #) ->
- (I32# (narrow32Int# d),
- I32# (narrow32Int# m))
- toInteger (I32# x#) = IS x#
+ (I32# (narrowInt32# d),
+ I32# (narrowInt32# m))
+ toInteger (I32# x#) = IS (extendInt32# x#)
-- | @since 2.01
instance Read Int32 where
@@ -600,35 +600,35 @@ instance Bits Int32 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (I32# x#) .&. (I32# y#) = I32# (x# `andI#` y#)
- (I32# x#) .|. (I32# y#) = I32# (x# `orI#` y#)
- (I32# x#) `xor` (I32# y#) = I32# (x# `xorI#` y#)
- complement (I32# x#) = I32# (notI# x#)
+ (I32# x#) .&. (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `andI#` (extendInt32# y#)))
+ (I32# x#) .|. (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `orI#` (extendInt32# y#)))
+ (I32# x#) `xor` (I32# y#) = I32# (narrowInt32# ((extendInt32# x#) `xorI#` (extendInt32# y#)))
+ complement (I32# x#) = I32# (narrowInt32# (notI# (extendInt32# x#)))
(I32# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = I32# (narrow32Int# (x# `iShiftL#` i#))
- | otherwise = I32# (x# `iShiftRA#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftL#` i#))
+ | otherwise = I32# (narrowInt32# ((extendInt32# x#) `iShiftRA#` negateInt# i#))
(I32# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = I32# (narrow32Int# (x# `iShiftL#` i#))
+ | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftL#` i#))
| otherwise = overflowError
(I32# x#) `unsafeShiftL` (I# i#) =
- I32# (narrow32Int# (x# `uncheckedIShiftL#` i#))
+ I32# (narrowInt32# ((extendInt32# x#) `uncheckedIShiftL#` i#))
(I32# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = I32# (x# `iShiftRA#` i#)
+ | isTrue# (i# >=# 0#) = I32# (narrowInt32# ((extendInt32# x#) `iShiftRA#` i#))
| otherwise = overflowError
- (I32# x#) `unsafeShiftR` (I# i#) = I32# (x# `uncheckedIShiftRA#` i#)
+ (I32# x#) `unsafeShiftR` (I# i#) = I32# (narrowInt32# ((extendInt32# x#) `uncheckedIShiftRA#` i#))
(I32# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#)
= I32# x#
| otherwise
- = I32# (narrow32Int# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
+ = I32# (narrowInt32# (word2Int# ((x'# `uncheckedShiftL#` i'#) `or#`
(x'# `uncheckedShiftRL#` (32# -# i'#)))))
where
- !x'# = narrow32Word# (int2Word# x#)
+ !x'# = narrow32Word# (int2Word# (extendInt32# x#))
!i'# = word2Int# (int2Word# i# `and#` 31##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = True
- popCount (I32# x#) = I# (word2Int# (popCnt32# (int2Word# x#)))
+ popCount (I32# x#) = I# (word2Int# (popCnt32# (int2Word# (extendInt32# x#))))
bit = bitDefault
testBit = testBitDefault
@@ -637,17 +637,17 @@ instance FiniteBits Int32 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 32
- countLeadingZeros (I32# x#) = I# (word2Int# (clz32# (int2Word# x#)))
- countTrailingZeros (I32# x#) = I# (word2Int# (ctz32# (int2Word# x#)))
+ countLeadingZeros (I32# x#) = I# (word2Int# (clz32# (int2Word# (extendInt32# x#))))
+ countTrailingZeros (I32# x#) = I# (word2Int# (ctz32# (int2Word# (extendInt32# x#))))
{-# RULES
-"fromIntegral/Word8->Int32" fromIntegral = \(W8# x#) -> I32# (word2Int# x#)
-"fromIntegral/Word16->Int32" fromIntegral = \(W16# x#) -> I32# (word2Int# x#)
-"fromIntegral/Int8->Int32" fromIntegral = \(I8# x#) -> I32# x#
-"fromIntegral/Int16->Int32" fromIntegral = \(I16# x#) -> I32# x#
+"fromIntegral/Word8->Int32" fromIntegral = \(W8# x#) -> I32# (narrowInt32# (word2Int# (extendWord8# x#)))
+"fromIntegral/Word16->Int32" fromIntegral = \(W16# x#) -> I32# (narrowInt32# (word2Int# (extendWord16# x#)))
+"fromIntegral/Int8->Int32" fromIntegral = \(I8# x#) -> I32# (narrowInt32# (extendInt8# x#))
+"fromIntegral/Int16->Int32" fromIntegral = \(I16# x#) -> I32# (narrowInt32# (extendInt16# x#))
"fromIntegral/Int32->Int32" fromIntegral = id :: Int32 -> Int32
-"fromIntegral/a->Int32" fromIntegral = \x -> case fromIntegral x of I# x# -> I32# (narrow32Int# x#)
-"fromIntegral/Int32->a" fromIntegral = \(I32# x#) -> fromIntegral (I# x#)
+"fromIntegral/a->Int32" fromIntegral = \x -> case fromIntegral x of I# x# -> I32# (narrowInt32# x#)
+"fromIntegral/Int32->a" fromIntegral = \(I32# x#) -> fromIntegral (I# (extendInt32# x#))
#-}
{-# RULES
diff --git a/libraries/base/GHC/Storable.hs b/libraries/base/GHC/Storable.hs
index d9b9382211..359c136b2b 100644
--- a/libraries/base/GHC/Storable.hs
+++ b/libraries/base/GHC/Storable.hs
@@ -91,17 +91,17 @@ readDoubleOffPtr (Ptr a) (I# i)
readStablePtrOffPtr (Ptr a) (I# i)
= IO $ \s -> case readStablePtrOffAddr# a i s of (# s2, x #) -> (# s2, StablePtr x #)
readInt8OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readInt8OffAddr# a i s of (# s2, x #) -> (# s2, I8# x #)
+ = IO $ \s -> case readInt8OffAddr# a i s of (# s2, x #) -> (# s2, I8# (narrowInt8# x) #)
readWord8OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readWord8OffAddr# a i s of (# s2, x #) -> (# s2, W8# x #)
+ = IO $ \s -> case readWord8OffAddr# a i s of (# s2, x #) -> (# s2, W8# (narrowWord8# x) #)
readInt16OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readInt16OffAddr# a i s of (# s2, x #) -> (# s2, I16# x #)
+ = IO $ \s -> case readInt16OffAddr# a i s of (# s2, x #) -> (# s2, I16# (narrowInt16# x) #)
readWord16OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readWord16OffAddr# a i s of (# s2, x #) -> (# s2, W16# x #)
+ = IO $ \s -> case readWord16OffAddr# a i s of (# s2, x #) -> (# s2, W16# (narrowWord16# x) #)
readInt32OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readInt32OffAddr# a i s of (# s2, x #) -> (# s2, I32# x #)
+ = IO $ \s -> case readInt32OffAddr# a i s of (# s2, x #) -> (# s2, I32# (narrowInt32# x) #)
readWord32OffPtr (Ptr a) (I# i)
- = IO $ \s -> case readWord32OffAddr# a i s of (# s2, x #) -> (# s2, W32# x #)
+ = IO $ \s -> case readWord32OffAddr# a i s of (# s2, x #) -> (# s2, W32# (narrowWord32# x) #)
readInt64OffPtr (Ptr a) (I# i)
= IO $ \s -> case readInt64OffAddr# a i s of (# s2, x #) -> (# s2, I64# x #)
readWord64OffPtr (Ptr a) (I# i)
@@ -141,17 +141,17 @@ writeDoubleOffPtr (Ptr a) (I# i) (D# x)
writeStablePtrOffPtr (Ptr a) (I# i) (StablePtr x)
= IO $ \s -> case writeStablePtrOffAddr# a i x s of s2 -> (# s2 , () #)
writeInt8OffPtr (Ptr a) (I# i) (I8# x)
- = IO $ \s -> case writeInt8OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeInt8OffAddr# a i (extendInt8# x) s of s2 -> (# s2, () #)
writeWord8OffPtr (Ptr a) (I# i) (W8# x)
- = IO $ \s -> case writeWord8OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeWord8OffAddr# a i (extendWord8# x) s of s2 -> (# s2, () #)
writeInt16OffPtr (Ptr a) (I# i) (I16# x)
- = IO $ \s -> case writeInt16OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeInt16OffAddr# a i (extendInt16# x) s of s2 -> (# s2, () #)
writeWord16OffPtr (Ptr a) (I# i) (W16# x)
- = IO $ \s -> case writeWord16OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeWord16OffAddr# a i (extendWord16# x) s of s2 -> (# s2, () #)
writeInt32OffPtr (Ptr a) (I# i) (I32# x)
- = IO $ \s -> case writeInt32OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeInt32OffAddr# a i (extendInt32# x) s of s2 -> (# s2, () #)
writeWord32OffPtr (Ptr a) (I# i) (W32# x)
- = IO $ \s -> case writeWord32OffAddr# a i x s of s2 -> (# s2, () #)
+ = IO $ \s -> case writeWord32OffAddr# a i (extendWord32# x) s of s2 -> (# s2, () #)
writeInt64OffPtr (Ptr a) (I# i) (I64# x)
= IO $ \s -> case writeInt64OffAddr# a i x s of s2 -> (# s2, () #)
writeWord64OffPtr (Ptr a) (I# i) (W64# x)
diff --git a/libraries/base/GHC/Word.hs b/libraries/base/GHC/Word.hs
index 75ed7d1f73..4ff2cc4837 100644
--- a/libraries/base/GHC/Word.hs
+++ b/libraries/base/GHC/Word.hs
@@ -67,7 +67,10 @@ import GHC.Show
-- Word8 is represented in the same way as Word. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsWord8" #-} Word8 = W8# Word#
+data {-# CTYPE "HsWord8" #-} Word8
+ = W8# Word8#
+
+
-- ^ 8-bit unsigned integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -77,8 +80,8 @@ instance Eq Word8 where
(/=) = neWord8
eqWord8, neWord8 :: Word8 -> Word8 -> Bool
-eqWord8 (W8# x) (W8# y) = isTrue# (x `eqWord#` y)
-neWord8 (W8# x) (W8# y) = isTrue# (x `neWord#` y)
+eqWord8 (W8# x) (W8# y) = isTrue# ((extendWord8# x) `eqWord#` (extendWord8# y))
+neWord8 (W8# x) (W8# y) = isTrue# ((extendWord8# x) `neWord#` (extendWord8# y))
{-# INLINE [1] eqWord8 #-}
{-# INLINE [1] neWord8 #-}
@@ -94,10 +97,10 @@ instance Ord Word8 where
{-# INLINE [1] ltWord8 #-}
{-# INLINE [1] leWord8 #-}
gtWord8, geWord8, ltWord8, leWord8 :: Word8 -> Word8 -> Bool
-(W8# x) `gtWord8` (W8# y) = isTrue# (x `gtWord#` y)
-(W8# x) `geWord8` (W8# y) = isTrue# (x `geWord#` y)
-(W8# x) `ltWord8` (W8# y) = isTrue# (x `ltWord#` y)
-(W8# x) `leWord8` (W8# y) = isTrue# (x `leWord#` y)
+(W8# x) `gtWord8` (W8# y) = isTrue# ((extendWord8# x) `gtWord#` (extendWord8# y))
+(W8# x) `geWord8` (W8# y) = isTrue# ((extendWord8# x) `geWord#` (extendWord8# y))
+(W8# x) `ltWord8` (W8# y) = isTrue# ((extendWord8# x) `ltWord#` (extendWord8# y))
+(W8# x) `leWord8` (W8# y) = isTrue# ((extendWord8# x) `leWord#` (extendWord8# y))
-- | @since 2.01
instance Show Word8 where
@@ -105,14 +108,14 @@ instance Show Word8 where
-- | @since 2.01
instance Num Word8 where
- (W8# x#) + (W8# y#) = W8# (narrow8Word# (x# `plusWord#` y#))
- (W8# x#) - (W8# y#) = W8# (narrow8Word# (x# `minusWord#` y#))
- (W8# x#) * (W8# y#) = W8# (narrow8Word# (x# `timesWord#` y#))
- negate (W8# x#) = W8# (narrow8Word# (int2Word# (negateInt# (word2Int# x#))))
+ (W8# x#) + (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `plusWord#` (extendWord8# y#)))
+ (W8# x#) - (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `minusWord#` (extendWord8# y#)))
+ (W8# x#) * (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `timesWord#` (extendWord8# y#)))
+ negate (W8# x#) = W8# (narrowWord8# (int2Word# (negateInt# (word2Int# ((extendWord8# x#))))))
abs x = x
signum 0 = 0
signum _ = 1
- fromInteger i = W8# (narrow8Word# (integerToWord# i))
+ fromInteger i = W8# (narrowWord8# (integerToWord# i))
-- | @since 2.01
instance Real Word8 where
@@ -128,35 +131,36 @@ instance Enum Word8 where
| otherwise = predError "Word8"
toEnum i@(I# i#)
| i >= 0 && i <= fromIntegral (maxBound::Word8)
- = W8# (int2Word# i#)
+ = W8# (narrowWord8# (int2Word# i#))
| otherwise = toEnumError "Word8" i (minBound::Word8, maxBound::Word8)
- fromEnum (W8# x#) = I# (word2Int# x#)
+ fromEnum (W8# x#) = I# (word2Int# (extendWord8# x#))
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
-- | @since 2.01
instance Integral Word8 where
quot (W8# x#) y@(W8# y#)
- | y /= 0 = W8# (x# `quotWord#` y#)
+ | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#)))
| otherwise = divZeroError
rem (W8# x#) y@(W8# y#)
- | y /= 0 = W8# (x# `remWord#` y#)
+ | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#)))
| otherwise = divZeroError
div (W8# x#) y@(W8# y#)
- | y /= 0 = W8# (x# `quotWord#` y#)
+ | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#)))
| otherwise = divZeroError
mod (W8# x#) y@(W8# y#)
- | y /= 0 = W8# (x# `remWord#` y#)
+ | y /= 0 = W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#)))
| otherwise = divZeroError
quotRem (W8# x#) y@(W8# y#)
- | y /= 0 = case x# `quotRemWord#` y# of
+ | y /= 0 = case (extendWord8# x#) `quotRemWord#` (extendWord8# y#) of
(# q, r #) ->
- (W8# q, W8# r)
+ (W8# (narrowWord8# q), W8# (narrowWord8# r))
| otherwise = divZeroError
divMod (W8# x#) y@(W8# y#)
- | y /= 0 = (W8# (x# `quotWord#` y#), W8# (x# `remWord#` y#))
+ | y /= 0 = (W8# (narrowWord8# ((extendWord8# x#) `quotWord#` (extendWord8# y#)))
+ ,W8# (narrowWord8# ((extendWord8# x#) `remWord#` (extendWord8# y#))))
| otherwise = divZeroError
- toInteger (W8# x#) = IS (word2Int# x#)
+ toInteger (W8# x#) = IS (word2Int# (extendWord8# x#))
-- | @since 2.01
instance Bounded Word8 where
@@ -176,33 +180,32 @@ instance Bits Word8 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (W8# x#) .&. (W8# y#) = W8# (x# `and#` y#)
- (W8# x#) .|. (W8# y#) = W8# (x# `or#` y#)
- (W8# x#) `xor` (W8# y#) = W8# (x# `xor#` y#)
- complement (W8# x#) = W8# (x# `xor#` mb#)
- where !(W8# mb#) = maxBound
+ (W8# x#) .&. (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `and#` (extendWord8# y#)))
+ (W8# x#) .|. (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `or#` (extendWord8# y#)))
+ (W8# x#) `xor` (W8# y#) = W8# (narrowWord8# ((extendWord8# x#) `xor#` (extendWord8# y#)))
+ complement (W8# x#) = W8# (narrowWord8# (not# (extendWord8# x#)))
(W8# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = W8# (narrow8Word# (x# `shiftL#` i#))
- | otherwise = W8# (x# `shiftRL#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftL#` i#))
+ | otherwise = W8# (narrowWord8# ((extendWord8# x#) `shiftRL#` negateInt# i#))
(W8# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = W8# (narrow8Word# (x# `shiftL#` i#))
+ | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftL#` i#))
| otherwise = overflowError
(W8# x#) `unsafeShiftL` (I# i#) =
- W8# (narrow8Word# (x# `uncheckedShiftL#` i#))
+ W8# (narrowWord8# ((extendWord8# x#) `uncheckedShiftL#` i#))
(W8# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = W8# (x# `shiftRL#` i#)
+ | isTrue# (i# >=# 0#) = W8# (narrowWord8# ((extendWord8# x#) `shiftRL#` i#))
| otherwise = overflowError
- (W8# x#) `unsafeShiftR` (I# i#) = W8# (x# `uncheckedShiftRL#` i#)
+ (W8# x#) `unsafeShiftR` (I# i#) = W8# (narrowWord8# ((extendWord8# x#) `uncheckedShiftRL#` i#))
(W8# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#) = W8# x#
- | otherwise = W8# (narrow8Word# ((x# `uncheckedShiftL#` i'#) `or#`
- (x# `uncheckedShiftRL#` (8# -# i'#))))
+ | otherwise = W8# (narrowWord8# (((extendWord8# x#) `uncheckedShiftL#` i'#) `or#`
+ ((extendWord8# x#) `uncheckedShiftRL#` (8# -# i'#))))
where
!i'# = word2Int# (int2Word# i# `and#` 7##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = False
- popCount (W8# x#) = I# (word2Int# (popCnt8# x#))
+ popCount (W8# x#) = I# (word2Int# (popCnt8# (extendWord8# x#)))
bit = bitDefault
testBit = testBitDefault
@@ -211,14 +214,14 @@ instance FiniteBits Word8 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 8
- countLeadingZeros (W8# x#) = I# (word2Int# (clz8# x#))
- countTrailingZeros (W8# x#) = I# (word2Int# (ctz8# x#))
+ countLeadingZeros (W8# x#) = I# (word2Int# (clz8# (extendWord8# x#)))
+ countTrailingZeros (W8# x#) = I# (word2Int# (ctz8# (extendWord8# x#)))
{-# RULES
"fromIntegral/Word8->Word8" fromIntegral = id :: Word8 -> Word8
"fromIntegral/Word8->Integer" fromIntegral = toInteger :: Word8 -> Integer
-"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (narrow8Word# x#)
-"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# x#)
+"fromIntegral/a->Word8" fromIntegral = \x -> case fromIntegral x of W# x# -> W8# (narrowWord8# x#)
+"fromIntegral/Word8->a" fromIntegral = \(W8# x#) -> fromIntegral (W# (extendWord8# x#))
#-}
{-# RULES
@@ -258,7 +261,7 @@ instance FiniteBits Word8 where
-- Word16 is represented in the same way as Word. Operations may assume
-- and must ensure that it holds only values from its logical range.
-data {-# CTYPE "HsWord16" #-} Word16 = W16# Word#
+data {-# CTYPE "HsWord16" #-} Word16 = W16# Word16#
-- ^ 16-bit unsigned integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -268,8 +271,8 @@ instance Eq Word16 where
(/=) = neWord16
eqWord16, neWord16 :: Word16 -> Word16 -> Bool
-eqWord16 (W16# x) (W16# y) = isTrue# (x `eqWord#` y)
-neWord16 (W16# x) (W16# y) = isTrue# (x `neWord#` y)
+eqWord16 (W16# x) (W16# y) = isTrue# ((extendWord16# x) `eqWord#` (extendWord16# y))
+neWord16 (W16# x) (W16# y) = isTrue# ((extendWord16# x) `neWord#` (extendWord16# y))
{-# INLINE [1] eqWord16 #-}
{-# INLINE [1] neWord16 #-}
@@ -285,10 +288,10 @@ instance Ord Word16 where
{-# INLINE [1] ltWord16 #-}
{-# INLINE [1] leWord16 #-}
gtWord16, geWord16, ltWord16, leWord16 :: Word16 -> Word16 -> Bool
-(W16# x) `gtWord16` (W16# y) = isTrue# (x `gtWord#` y)
-(W16# x) `geWord16` (W16# y) = isTrue# (x `geWord#` y)
-(W16# x) `ltWord16` (W16# y) = isTrue# (x `ltWord#` y)
-(W16# x) `leWord16` (W16# y) = isTrue# (x `leWord#` y)
+(W16# x) `gtWord16` (W16# y) = isTrue# ((extendWord16# x) `gtWord#` (extendWord16# y))
+(W16# x) `geWord16` (W16# y) = isTrue# ((extendWord16# x) `geWord#` (extendWord16# y))
+(W16# x) `ltWord16` (W16# y) = isTrue# ((extendWord16# x) `ltWord#` (extendWord16# y))
+(W16# x) `leWord16` (W16# y) = isTrue# ((extendWord16# x) `leWord#` (extendWord16# y))
-- | @since 2.01
instance Show Word16 where
@@ -296,14 +299,14 @@ instance Show Word16 where
-- | @since 2.01
instance Num Word16 where
- (W16# x#) + (W16# y#) = W16# (narrow16Word# (x# `plusWord#` y#))
- (W16# x#) - (W16# y#) = W16# (narrow16Word# (x# `minusWord#` y#))
- (W16# x#) * (W16# y#) = W16# (narrow16Word# (x# `timesWord#` y#))
- negate (W16# x#) = W16# (narrow16Word# (int2Word# (negateInt# (word2Int# x#))))
+ (W16# x#) + (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `plusWord#` (extendWord16# y#)))
+ (W16# x#) - (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `minusWord#` (extendWord16# y#)))
+ (W16# x#) * (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `timesWord#` (extendWord16# y#)))
+ negate (W16# x#) = W16# (narrowWord16# (int2Word# (negateInt# (word2Int# (extendWord16# x#)))))
abs x = x
signum 0 = 0
signum _ = 1
- fromInteger i = W16# (narrow16Word# (integerToWord# i))
+ fromInteger i = W16# (narrowWord16# (integerToWord# i))
-- | @since 2.01
instance Real Word16 where
@@ -319,35 +322,36 @@ instance Enum Word16 where
| otherwise = predError "Word16"
toEnum i@(I# i#)
| i >= 0 && i <= fromIntegral (maxBound::Word16)
- = W16# (int2Word# i#)
+ = W16# (narrowWord16# (int2Word# i#))
| otherwise = toEnumError "Word16" i (minBound::Word16, maxBound::Word16)
- fromEnum (W16# x#) = I# (word2Int# x#)
+ fromEnum (W16# x#) = I# (word2Int# (extendWord16# x#))
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
-- | @since 2.01
instance Integral Word16 where
quot (W16# x#) y@(W16# y#)
- | y /= 0 = W16# (x# `quotWord#` y#)
+ | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#)))
| otherwise = divZeroError
rem (W16# x#) y@(W16# y#)
- | y /= 0 = W16# (x# `remWord#` y#)
+ | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#)))
| otherwise = divZeroError
div (W16# x#) y@(W16# y#)
- | y /= 0 = W16# (x# `quotWord#` y#)
+ | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#)))
| otherwise = divZeroError
mod (W16# x#) y@(W16# y#)
- | y /= 0 = W16# (x# `remWord#` y#)
+ | y /= 0 = W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#)))
| otherwise = divZeroError
quotRem (W16# x#) y@(W16# y#)
- | y /= 0 = case x# `quotRemWord#` y# of
+ | y /= 0 = case (extendWord16# x#) `quotRemWord#` (extendWord16# y#) of
(# q, r #) ->
- (W16# q, W16# r)
+ (W16# (narrowWord16# q), W16# (narrowWord16# r))
| otherwise = divZeroError
divMod (W16# x#) y@(W16# y#)
- | y /= 0 = (W16# (x# `quotWord#` y#), W16# (x# `remWord#` y#))
+ | y /= 0 = (W16# (narrowWord16# ((extendWord16# x#) `quotWord#` (extendWord16# y#)))
+ ,W16# (narrowWord16# ((extendWord16# x#) `remWord#` (extendWord16# y#))))
| otherwise = divZeroError
- toInteger (W16# x#) = IS (word2Int# x#)
+ toInteger (W16# x#) = IS (word2Int# (extendWord16# x#))
-- | @since 2.01
instance Bounded Word16 where
@@ -367,33 +371,32 @@ instance Bits Word16 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (W16# x#) .&. (W16# y#) = W16# (x# `and#` y#)
- (W16# x#) .|. (W16# y#) = W16# (x# `or#` y#)
- (W16# x#) `xor` (W16# y#) = W16# (x# `xor#` y#)
- complement (W16# x#) = W16# (x# `xor#` mb#)
- where !(W16# mb#) = maxBound
+ (W16# x#) .&. (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `and#` (extendWord16# y#)))
+ (W16# x#) .|. (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `or#` (extendWord16# y#)))
+ (W16# x#) `xor` (W16# y#) = W16# (narrowWord16# ((extendWord16# x#) `xor#` (extendWord16# y#)))
+ complement (W16# x#) = W16# (narrowWord16# (not# (extendWord16# x#)))
(W16# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = W16# (narrow16Word# (x# `shiftL#` i#))
- | otherwise = W16# (x# `shiftRL#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftL#` i#))
+ | otherwise = W16# (narrowWord16# ((extendWord16# x#) `shiftRL#` negateInt# i#))
(W16# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = W16# (narrow16Word# (x# `shiftL#` i#))
+ | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftL#` i#))
| otherwise = overflowError
(W16# x#) `unsafeShiftL` (I# i#) =
- W16# (narrow16Word# (x# `uncheckedShiftL#` i#))
+ W16# (narrowWord16# ((extendWord16# x#) `uncheckedShiftL#` i#))
(W16# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = W16# (x# `shiftRL#` i#)
+ | isTrue# (i# >=# 0#) = W16# (narrowWord16# ((extendWord16# x#) `shiftRL#` i#))
| otherwise = overflowError
- (W16# x#) `unsafeShiftR` (I# i#) = W16# (x# `uncheckedShiftRL#` i#)
+ (W16# x#) `unsafeShiftR` (I# i#) = W16# (narrowWord16# ((extendWord16# x#) `uncheckedShiftRL#` i#))
(W16# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#) = W16# x#
- | otherwise = W16# (narrow16Word# ((x# `uncheckedShiftL#` i'#) `or#`
- (x# `uncheckedShiftRL#` (16# -# i'#))))
+ | otherwise = W16# (narrowWord16# (((extendWord16# x#) `uncheckedShiftL#` i'#) `or#`
+ ((extendWord16# x#) `uncheckedShiftRL#` (16# -# i'#))))
where
!i'# = word2Int# (int2Word# i# `and#` 15##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = False
- popCount (W16# x#) = I# (word2Int# (popCnt16# x#))
+ popCount (W16# x#) = I# (word2Int# (popCnt16# (extendWord16# x#)))
bit = bitDefault
testBit = testBitDefault
@@ -402,21 +405,21 @@ instance FiniteBits Word16 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 16
- countLeadingZeros (W16# x#) = I# (word2Int# (clz16# x#))
- countTrailingZeros (W16# x#) = I# (word2Int# (ctz16# x#))
+ countLeadingZeros (W16# x#) = I# (word2Int# (clz16# (extendWord16# x#)))
+ countTrailingZeros (W16# x#) = I# (word2Int# (ctz16# (extendWord16# x#)))
-- | Reverse order of bytes in 'Word16'.
--
-- @since 4.7.0.0
byteSwap16 :: Word16 -> Word16
-byteSwap16 (W16# w#) = W16# (narrow16Word# (byteSwap16# w#))
+byteSwap16 (W16# w#) = W16# (narrowWord16# (byteSwap16# (extendWord16# w#)))
{-# RULES
-"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# x#
+"fromIntegral/Word8->Word16" fromIntegral = \(W8# x#) -> W16# (narrowWord16# (extendWord8# x#))
"fromIntegral/Word16->Word16" fromIntegral = id :: Word16 -> Word16
"fromIntegral/Word16->Integer" fromIntegral = toInteger :: Word16 -> Integer
-"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (narrow16Word# x#)
-"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# x#)
+"fromIntegral/a->Word16" fromIntegral = \x -> case fromIntegral x of W# x# -> W16# (narrowWord16# x#)
+"fromIntegral/Word16->a" fromIntegral = \(W16# x#) -> fromIntegral (W# (extendWord16# x#))
#-}
{-# RULES
@@ -492,7 +495,7 @@ byteSwap16 (W16# w#) = W16# (narrow16Word# (byteSwap16# w#))
#endif
-data {-# CTYPE "HsWord32" #-} Word32 = W32# Word#
+data {-# CTYPE "HsWord32" #-} Word32 = W32# Word32#
-- ^ 32-bit unsigned integer type
-- See GHC.Classes#matching_overloaded_methods_in_rules
@@ -502,8 +505,8 @@ instance Eq Word32 where
(/=) = neWord32
eqWord32, neWord32 :: Word32 -> Word32 -> Bool
-eqWord32 (W32# x) (W32# y) = isTrue# (x `eqWord#` y)
-neWord32 (W32# x) (W32# y) = isTrue# (x `neWord#` y)
+eqWord32 (W32# x) (W32# y) = isTrue# ((extendWord32# x) `eqWord#` (extendWord32# y))
+neWord32 (W32# x) (W32# y) = isTrue# ((extendWord32# x) `neWord#` (extendWord32# y))
{-# INLINE [1] eqWord32 #-}
{-# INLINE [1] neWord32 #-}
@@ -519,21 +522,21 @@ instance Ord Word32 where
{-# INLINE [1] ltWord32 #-}
{-# INLINE [1] leWord32 #-}
gtWord32, geWord32, ltWord32, leWord32 :: Word32 -> Word32 -> Bool
-(W32# x) `gtWord32` (W32# y) = isTrue# (x `gtWord#` y)
-(W32# x) `geWord32` (W32# y) = isTrue# (x `geWord#` y)
-(W32# x) `ltWord32` (W32# y) = isTrue# (x `ltWord#` y)
-(W32# x) `leWord32` (W32# y) = isTrue# (x `leWord#` y)
+(W32# x) `gtWord32` (W32# y) = isTrue# ((extendWord32# x) `gtWord#` (extendWord32# y))
+(W32# x) `geWord32` (W32# y) = isTrue# ((extendWord32# x) `geWord#` (extendWord32# y))
+(W32# x) `ltWord32` (W32# y) = isTrue# ((extendWord32# x) `ltWord#` (extendWord32# y))
+(W32# x) `leWord32` (W32# y) = isTrue# ((extendWord32# x) `leWord#` (extendWord32# y))
-- | @since 2.01
instance Num Word32 where
- (W32# x#) + (W32# y#) = W32# (narrow32Word# (x# `plusWord#` y#))
- (W32# x#) - (W32# y#) = W32# (narrow32Word# (x# `minusWord#` y#))
- (W32# x#) * (W32# y#) = W32# (narrow32Word# (x# `timesWord#` y#))
- negate (W32# x#) = W32# (narrow32Word# (int2Word# (negateInt# (word2Int# x#))))
+ (W32# x#) + (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `plusWord#` (extendWord32# y#)))
+ (W32# x#) - (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `minusWord#` (extendWord32# y#)))
+ (W32# x#) * (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `timesWord#` (extendWord32# y#)))
+ negate (W32# x#) = W32# (narrowWord32# (int2Word# (negateInt# (word2Int# (extendWord32# x#)))))
abs x = x
signum 0 = 0
signum _ = 1
- fromInteger i = W32# (narrow32Word# (integerToWord# i))
+ fromInteger i = W32# (narrowWord32# (integerToWord# i))
-- | @since 2.01
instance Enum Word32 where
@@ -548,19 +551,19 @@ instance Enum Word32 where
#if WORD_SIZE_IN_BITS > 32
&& i <= fromIntegral (maxBound::Word32)
#endif
- = W32# (int2Word# i#)
+ = W32# (narrowWord32# (int2Word# i#))
| otherwise = toEnumError "Word32" i (minBound::Word32, maxBound::Word32)
#if WORD_SIZE_IN_BITS == 32
fromEnum x@(W32# x#)
| x <= fromIntegral (maxBound::Int)
- = I# (word2Int# x#)
+ = I# (word2Int# (extendWord32# x#))
| otherwise = fromEnumError "Word32" x
enumFrom = integralEnumFrom
enumFromThen = integralEnumFromThen
enumFromTo = integralEnumFromTo
enumFromThenTo = integralEnumFromThenTo
#else
- fromEnum (W32# x#) = I# (word2Int# x#)
+ fromEnum (W32# x#) = I# (word2Int# (extendWord32# x#))
enumFrom = boundedEnumFrom
enumFromThen = boundedEnumFromThen
#endif
@@ -568,33 +571,34 @@ instance Enum Word32 where
-- | @since 2.01
instance Integral Word32 where
quot (W32# x#) y@(W32# y#)
- | y /= 0 = W32# (x# `quotWord#` y#)
+ | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#)))
| otherwise = divZeroError
rem (W32# x#) y@(W32# y#)
- | y /= 0 = W32# (x# `remWord#` y#)
+ | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#)))
| otherwise = divZeroError
div (W32# x#) y@(W32# y#)
- | y /= 0 = W32# (x# `quotWord#` y#)
+ | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#)))
| otherwise = divZeroError
mod (W32# x#) y@(W32# y#)
- | y /= 0 = W32# (x# `remWord#` y#)
+ | y /= 0 = W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#)))
| otherwise = divZeroError
quotRem (W32# x#) y@(W32# y#)
- | y /= 0 = case x# `quotRemWord#` y# of
+ | y /= 0 = case (extendWord32# x#) `quotRemWord#` (extendWord32# y#) of
(# q, r #) ->
- (W32# q, W32# r)
+ (W32# (narrowWord32# q), W32# (narrowWord32# r))
| otherwise = divZeroError
divMod (W32# x#) y@(W32# y#)
- | y /= 0 = (W32# (x# `quotWord#` y#), W32# (x# `remWord#` y#))
+ | y /= 0 = (W32# (narrowWord32# ((extendWord32# x#) `quotWord#` (extendWord32# y#)))
+ ,W32# (narrowWord32# ((extendWord32# x#) `remWord#` (extendWord32# y#))))
| otherwise = divZeroError
toInteger (W32# x#)
#if WORD_SIZE_IN_BITS == 32
| isTrue# (i# >=# 0#) = IS i#
- | otherwise = integerFromWord# x#
+ | otherwise = integerFromWord# (extendWord32# x#)
where
- !i# = word2Int# x#
+ !i# = word2Int# (extendWord32# x#)
#else
- = IS (word2Int# x#)
+ = IS (word2Int# (extendWord32# x#))
#endif
-- | @since 2.01
@@ -604,33 +608,32 @@ instance Bits Word32 where
{-# INLINE testBit #-}
{-# INLINE popCount #-}
- (W32# x#) .&. (W32# y#) = W32# (x# `and#` y#)
- (W32# x#) .|. (W32# y#) = W32# (x# `or#` y#)
- (W32# x#) `xor` (W32# y#) = W32# (x# `xor#` y#)
- complement (W32# x#) = W32# (x# `xor#` mb#)
- where !(W32# mb#) = maxBound
+ (W32# x#) .&. (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `and#` (extendWord32# y#)))
+ (W32# x#) .|. (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `or#` (extendWord32# y#)))
+ (W32# x#) `xor` (W32# y#) = W32# (narrowWord32# ((extendWord32# x#) `xor#` (extendWord32# y#)))
+ complement (W32# x#) = W32# (narrowWord32# (not# (extendWord32# x#)))
(W32# x#) `shift` (I# i#)
- | isTrue# (i# >=# 0#) = W32# (narrow32Word# (x# `shiftL#` i#))
- | otherwise = W32# (x# `shiftRL#` negateInt# i#)
+ | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftL#` i#))
+ | otherwise = W32# (narrowWord32# ((extendWord32# x#) `shiftRL#` negateInt# i#))
(W32# x#) `shiftL` (I# i#)
- | isTrue# (i# >=# 0#) = W32# (narrow32Word# (x# `shiftL#` i#))
+ | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftL#` i#))
| otherwise = overflowError
(W32# x#) `unsafeShiftL` (I# i#) =
- W32# (narrow32Word# (x# `uncheckedShiftL#` i#))
+ W32# (narrowWord32# ((extendWord32# x#) `uncheckedShiftL#` i#))
(W32# x#) `shiftR` (I# i#)
- | isTrue# (i# >=# 0#) = W32# (x# `shiftRL#` i#)
+ | isTrue# (i# >=# 0#) = W32# (narrowWord32# ((extendWord32# x#) `shiftRL#` i#))
| otherwise = overflowError
- (W32# x#) `unsafeShiftR` (I# i#) = W32# (x# `uncheckedShiftRL#` i#)
+ (W32# x#) `unsafeShiftR` (I# i#) = W32# (narrowWord32# ((extendWord32# x#) `uncheckedShiftRL#` i#))
(W32# x#) `rotate` (I# i#)
| isTrue# (i'# ==# 0#) = W32# x#
- | otherwise = W32# (narrow32Word# ((x# `uncheckedShiftL#` i'#) `or#`
- (x# `uncheckedShiftRL#` (32# -# i'#))))
+ | otherwise = W32# (narrowWord32# (((extendWord32# x#) `uncheckedShiftL#` i'#) `or#`
+ ((extendWord32# x#) `uncheckedShiftRL#` (32# -# i'#))))
where
!i'# = word2Int# (int2Word# i# `and#` 31##)
bitSizeMaybe i = Just (finiteBitSize i)
bitSize i = finiteBitSize i
isSigned _ = False
- popCount (W32# x#) = I# (word2Int# (popCnt32# x#))
+ popCount (W32# x#) = I# (word2Int# (popCnt32# (extendWord32# x#)))
bit = bitDefault
testBit = testBitDefault
@@ -639,16 +642,16 @@ instance FiniteBits Word32 where
{-# INLINE countLeadingZeros #-}
{-# INLINE countTrailingZeros #-}
finiteBitSize _ = 32
- countLeadingZeros (W32# x#) = I# (word2Int# (clz32# x#))
- countTrailingZeros (W32# x#) = I# (word2Int# (ctz32# x#))
+ countLeadingZeros (W32# x#) = I# (word2Int# (clz32# (extendWord32# x#)))
+ countTrailingZeros (W32# x#) = I# (word2Int# (ctz32# (extendWord32# x#)))
{-# RULES
-"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# x#
-"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# x#
+"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# (narrowWord32# (extendWord8# x#))
+"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# (narrowWord32# (extendWord16# x#))
"fromIntegral/Word32->Word32" fromIntegral = id :: Word32 -> Word32
"fromIntegral/Word32->Integer" fromIntegral = toInteger :: Word32 -> Integer
-"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (narrow32Word# x#)
-"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# x#)
+"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (narrowWord32# x#)
+"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# (extendWord32# x#))
#-}
-- | @since 2.01
@@ -679,7 +682,7 @@ instance Ix Word32 where
--
-- @since 4.7.0.0
byteSwap32 :: Word32 -> Word32
-byteSwap32 (W32# w#) = W32# (narrow32Word# (byteSwap32# w#))
+byteSwap32 (W32# w#) = W32# (narrowWord32# (byteSwap32# (extendWord32# w#)))
------------------------------------------------------------------------
-- type Word64
@@ -969,8 +972,7 @@ instance Bits Word64 where
(W64# x#) .&. (W64# y#) = W64# (x# `and#` y#)
(W64# x#) .|. (W64# y#) = W64# (x# `or#` y#)
(W64# x#) `xor` (W64# y#) = W64# (x# `xor#` y#)
- complement (W64# x#) = W64# (x# `xor#` mb#)
- where !(W64# mb#) = maxBound
+ complement (W64# x#) = W64# (not# x#)
(W64# x#) `shift` (I# i#)
| isTrue# (i# >=# 0#) = W64# (x# `shiftL#` i#)
| otherwise = W64# (x# `shiftRL#` negateInt# i#)
@@ -1050,19 +1052,19 @@ byteSwap64 (W64# w#) = W64# (byteSwap# w#)
--
-- @since 4.12.0.0
bitReverse8 :: Word8 -> Word8
-bitReverse8 (W8# w#) = W8# (narrow8Word# (bitReverse8# w#))
+bitReverse8 (W8# w#) = W8# (narrowWord8# (bitReverse8# (extendWord8# w#)))
-- | Reverse the order of the bits in a 'Word16'.
--
-- @since 4.12.0.0
bitReverse16 :: Word16 -> Word16
-bitReverse16 (W16# w#) = W16# (narrow16Word# (bitReverse16# w#))
+bitReverse16 (W16# w#) = W16# (narrowWord16# (bitReverse16# (extendWord16# w#)))
-- | Reverse the order of the bits in a 'Word32'.
--
-- @since 4.12.0.0
bitReverse32 :: Word32 -> Word32
-bitReverse32 (W32# w#) = W32# (narrow32Word# (bitReverse32# w#))
+bitReverse32 (W32# w#) = W32# (narrowWord32# (bitReverse32# (extendWord32# w#)))
-- | Reverse the order of the bits in a 'Word64'.
--
diff --git a/libraries/base/base.cabal b/libraries/base/base.cabal
index 5da92855f7..f620affcbf 100644
--- a/libraries/base/base.cabal
+++ b/libraries/base/base.cabal
@@ -88,7 +88,7 @@ Library
build-depends:
rts == 1.0,
- ghc-prim >= 0.5.1.0 && < 0.8,
+ ghc-prim >= 0.5.1.0 && < 0.9,
ghc-bignum >= 1.0 && < 2.0
exposed-modules:
diff --git a/libraries/binary b/libraries/binary
-Subproject dfaf780596328c9184758452b78288e8f405fcc
+Subproject b224410161f112dd1133a787ded9831799589ce
diff --git a/libraries/bytestring b/libraries/bytestring
-Subproject e043aacfc4202a59ccae8b8c8cf0e1ad83a3f20
+Subproject 8b5d8d0da24aefdc4d950174bf396b32335d7e0
diff --git a/libraries/ghc-bignum/ghc-bignum.cabal b/libraries/ghc-bignum/ghc-bignum.cabal
index bc478cf108..b1d600bd15 100644
--- a/libraries/ghc-bignum/ghc-bignum.cabal
+++ b/libraries/ghc-bignum/ghc-bignum.cabal
@@ -77,7 +77,7 @@ library
ForeignFunctionInterface
build-depends:
- ghc-prim >= 0.5.1.0 && < 0.8
+ ghc-prim >= 0.5.1.0 && < 0.9
hs-source-dirs: src/
include-dirs: include/
diff --git a/libraries/ghc-compact/ghc-compact.cabal b/libraries/ghc-compact/ghc-compact.cabal
index 4c55e09e4e..7ddb956355 100644
--- a/libraries/ghc-compact/ghc-compact.cabal
+++ b/libraries/ghc-compact/ghc-compact.cabal
@@ -36,7 +36,7 @@ library
UnboxedTuples
CPP
- build-depends: ghc-prim >= 0.5.3 && < 0.8,
+ build-depends: ghc-prim >= 0.5.3 && < 0.9,
base >= 4.9.0 && < 4.17,
bytestring >= 0.10.6.0
ghc-options: -Wall
diff --git a/libraries/ghc-heap/ghc-heap.cabal.in b/libraries/ghc-heap/ghc-heap.cabal.in
index a80d9f7ad3..e0f15abd3f 100644
--- a/libraries/ghc-heap/ghc-heap.cabal.in
+++ b/libraries/ghc-heap/ghc-heap.cabal.in
@@ -23,7 +23,7 @@ library
default-language: Haskell2010
build-depends: base >= 4.9.0 && < 5.0
- , ghc-prim > 0.2 && < 0.8
+ , ghc-prim > 0.2 && < 0.9
, rts == 1.0.*
ghc-options: -Wall
diff --git a/libraries/ghc-prim/ghc-prim.cabal b/libraries/ghc-prim/ghc-prim.cabal
index bca9225023..05fd60f09a 100644
--- a/libraries/ghc-prim/ghc-prim.cabal
+++ b/libraries/ghc-prim/ghc-prim.cabal
@@ -1,6 +1,6 @@
cabal-version: 2.2
name: ghc-prim
-version: 0.7.0
+version: 0.8.0
-- NOTE: Don't forget to update ./changelog.md
license: BSD-3-Clause
license-file: LICENSE
diff --git a/libraries/ghci/GHCi/BreakArray.hs b/libraries/ghci/GHCi/BreakArray.hs
index a0f9d03bdc..05d13bda67 100644
--- a/libraries/ghci/GHCi/BreakArray.hs
+++ b/libraries/ghci/GHCi/BreakArray.hs
@@ -32,10 +32,20 @@ import Control.Monad
import Data.Word
import GHC.Word
-import GHC.Exts
+import GHC.Exts hiding (extendWord8#, narrowWord8#)
import GHC.IO ( IO(..) )
import System.IO.Unsafe ( unsafeDupablePerformIO )
+#if MIN_VERSION_base(4,16,0)
+import GHC.Base (extendWord8#, narrowWord8#)
+#else
+narrowWord8#, extendWord8# :: Word# -> Word#
+narrowWord8# w = w
+extendWord8# w = w
+{-# INLINE narrowWord8# #-}
+{-# INLINE extendWord8# #-}
+#endif
+
data BreakArray = BA (MutableByteArray# RealWorld)
breakOff, breakOn :: Word8
@@ -96,7 +106,7 @@ newBreakArray entries@(I# sz) = do
case breakOff of
W8# off -> do
let loop n | isTrue# (n ==# sz) = return ()
- | otherwise = do writeBA# array n off; loop (n +# 1#)
+ | otherwise = do writeBA# array n (extendWord8# off); loop (n +# 1#)
loop 0#
return $ BA array
@@ -105,11 +115,11 @@ writeBA# array i word = IO $ \s ->
case writeWord8Array# array i word s of { s -> (# s, () #) }
writeBreakArray :: BreakArray -> Int -> Word8 -> IO ()
-writeBreakArray (BA array) (I# i) (W8# word) = writeBA# array i word
+writeBreakArray (BA array) (I# i) (W8# word) = writeBA# array i (extendWord8# word)
readBA# :: MutableByteArray# RealWorld -> Int# -> IO Word8
readBA# array i = IO $ \s ->
- case readWord8Array# array i s of { (# s, c #) -> (# s, W8# c #) }
+ case readWord8Array# array i s of { (# s, c #) -> (# s, W8# (narrowWord8# c) #) }
readBreakArray :: BreakArray -> Int -> IO Word8
readBreakArray (BA array) (I# i) = readBA# array i
diff --git a/libraries/ghci/ghci.cabal.in b/libraries/ghci/ghci.cabal.in
index e33b703b49..39ba3ccbe7 100644
--- a/libraries/ghci/ghci.cabal.in
+++ b/libraries/ghci/ghci.cabal.in
@@ -73,6 +73,7 @@ library
Build-Depends:
array == 0.5.*,
base >= 4.8 && < 4.17,
+ ghc-prim >= 0.5.0 && < 0.9,
binary == 0.8.*,
bytestring == 0.10.*,
containers >= 0.5 && < 0.7,
diff --git a/libraries/text b/libraries/text
-Subproject 80cb9ee2eb7141171171318bbd6760fe8001252
+Subproject f1a2e141a79ebc0a57ab2d641db00cef3ff60a4