From be5d74caab64abf9d986fc7290f62731db7e73e7 Mon Sep 17 00:00:00 2001 From: Moritz Angermann Date: Thu, 22 Oct 2020 12:08:34 +0800 Subject: [Sized Cmm] properly retain sizes. This replaces all Word = W# Word# and Int = I# Int# with Word = W# Word# and Int = I# Int#, 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 Metric Increase: T13701 T14697 --- libraries/ghci/GHCi/BreakArray.hs | 18 ++++++++++++++---- libraries/ghci/ghci.cabal.in | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'libraries/ghci') 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, -- cgit v1.2.1